Forum Discussion
Steve_Brown_882
Mar 10, 2011Historic F5 Account
create_user_3 in a perl script
Hey Guys,
I don't do a lot of perl scripting so I am hoping for a little help getting a script to work. Basically I have pieced som code together from the forums but it doesn't quite work.
Here is the code I have so far, any thoughts?
!/usr/bin/perl
use SOAP::Lite;
sub SOAP::Transport::HTTP::Client::get_basic_credentials
{
return "admin" => "admin";
}
$UserManagement = SOAP::Lite
-> uri('urn:iControl:Management/UserManagement')
-> readable(1)
-> proxy("https://192.168.10.100/iControl/iControlPortal.cgi");
&handle_create();
sub handle_create()
{
my ($UserName, $FullName, $Role, $Partition ) = @_;
if ( $UserName eq "" ) { $UserName = "testuser1"; }
if ( $FullName eq "" ) { $FullName = "New User"; }
if ( $Role eq "" ) { $Role = USER_ROLE_GUEST ; }
if ( $Partition eq "" ) { $Partition = "Common" ; }
$Password = "";
$UserID = {
name => $UserName,
full_name => $FullName
};
$UserPermissions = {
role => $Role,
partition => $Partition
};
$UserInfo = {
user => $UserID,
password => $Password,
permisision => $UserPermissions,
login_shell => "/bin/bash",
};
$soapResponse = $UserManagement->create_user_3(
SOAP::Data->name(users => [$UserInfo])
);
}
- A couple of things stick out right away.
Management.UserManagement.create_user_3 ( Management.UserManagement.UserInfo3 users ) struct Management.UserManagement.UserInfo3 { UserID user; PasswordInfo password; UserPermission [] permissions; String login_shell; } struct Management.UserManagement.UserID { String name; String full_name; } struct Management.UserManagement.PasswordInfo { boolean is_encrypted; String password; } struct Management.UserManagement.UserPermission { UserRole role; String partition; }
- Steve_Brown_882Historic F5 AccountThanks for the input Joe. I made a few changes, but still not working. It actually runs without error but doesn't create the user so I am guessing I still have something wrong with $UserInfo
- You've got a few too many brackets in your UserInfo structure. By putting brackets around all parameters you are turning them all into arrays. Also, for a boolean, you'll have to use either 0 or 1.
sub handle_create() { my ($UserName, $FullName, $Role, $Partition ) = @_; if ( $UserName eq "" ) { $UserName = "testuser1"; } if ( $FullName eq "" ) { $FullName = "New User"; } if ( $Role eq "" ) { $Role = USER_ROLE_GUEST ; } if ( $Partition eq "" ) { $Partition = "Common" ; } $Password = { is_encrypted => 0, password => "" }; $UserID = { name => $UserName, full_name => $FullName }; $UserPermissions = { role => $Role, partition => $Partition }; $UserInfo = { user => $UserID, password => $Password, permisisions => [$UserPermissions], login_shell => "", }; $soapResponse = $UserManagement->create_user_3( SOAP::Data->name(users => [$UserInfo]) ); };
- Steve_Brown_882Historic F5 AccountFor some reason even this code runs without error, but fails to create the user.
- Darn typos... I misspelled the "permissions" member int he UserInfo structure. I tested this one and it did create the user for me.
sub handle_create() { my ($UserName, $FullName, $Role, $Partition ) = @_; if ( $UserName eq "" ) { $UserName = "testuser1"; } if ( $FullName eq "" ) { $FullName = "New User"; } if ( $Role eq "" ) { $Role = USER_ROLE_GUEST ; } if ( $Partition eq "" ) { $Partition = "Common" ; } $Password = { is_encrypted => 0, password => "" }; $UserID = { name => $UserName, full_name => $FullName }; $UserPermissions = { role => $Role, partition => $Partition }; $UserInfo = { user => $UserID, password => $Password, permissions => [$UserPermissions], login_shell => "", }; $soapResponse = $UserManagement->create_user_3( SOAP::Data->name(users => [$UserInfo]) ); };
- Steve_Brown_882Historic F5 AccountNow it works! Thanks for helping out with this. I am a little better with python, but in either case I really appreciate all the help you guys provide with this sort of stuff. Anyhow this gets me pretty close to done with my overall script, I will be sure to share the rest of it when I finish.
Recent Discussions
Related Content
Â
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects