Forum Discussion

Steve_Brown_882's avatar
Steve_Brown_882
Historic F5 Account
Mar 10, 2011

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])

 

);

 

}

 

 

 

6 Replies

  • A couple of things stick out right away.

     

     

    First, here's the definition for the create_user_3 method

     

     

    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;
    }

     

     

    In looking at your code, the following pieces don't match with the input to the method.

     

     

    1. UserInfo3.password is a struct. You are passing in just the password as a string.

     

    2. UserInfo3.permissions is missing. You are calling it "permission" and you aren't passing in an array. You'll need to surround the "$UserPermissions" variable with brackets "[$UserPermissions]".

     

     

    I haven't had time to test this out, but I do think that's it. Let me know if you need further assistance.

     

     

    -Joe

     

  • Steve_Brown_882's avatar
    Steve_Brown_882
    Historic F5 Account
    Thanks 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

     

     

    !/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 = {

     

    is_encrypted => "false",

     

    password => ""

     

    };

     

     

    $UserID = {

     

    name => $UserName,

     

    full_name => $FullName

     

    };

     

     

    $UserPermissions = {

     

    role => $Role,

     

    partition => $Partition

     

    };

     

     

    $UserInfo = {

     

    user => [$UserID],

     

    password => [$Password],

     

    permisisions => [$UserPermissions],

     

    login_shell => "/bin/bash",

     

    };

     

     

    $soapResponse = $UserManagement->create_user_3(

     

    SOAP::Data->name(users => [$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.

    Give this a shot:

    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])
      );
    };

    Notice, I've removed the "login_shell" parameter as USER_ROLE_GUEST doesn't have the access to specify a custom shell.

    -Joe

  • Steve_Brown_882's avatar
    Steve_Brown_882
    Historic F5 Account
    For 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])
      );
    };

    That's the down side of perl with it's dynamic language. You need to make sure you get all the parameter names correct. Using a more tightly bound language like .Net or Java will not have this problem.

    -Joe

  • Steve_Brown_882's avatar
    Steve_Brown_882
    Historic F5 Account
    Now 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.