Active IQ Unified Manager Discussions

user role creation in WFA--Perl

raovolvoadmin
2,679 Views

Hello,

I want ot create the User role using the Perl in the WFA.I have written below code..but getting the error..

Can't locate object method "child_add" via package "WFAUtil" at ./Useradmin4448434308083319828.pl line 22, <STDIN> line 1.

My code is...

#!/usr/bin/perl

use strict;

use warnings;

use  NaServer;

use Getopt::Long;

use WFAUtil;

our $array;our $server;our $vfiler;our $RoleName;our $comment;our $CapaName;our $api;

GetOptions("array=s" => \$array,

                 "RoleName" => \$RoleName,

                       "comment"   =>  \$comment,

                       "CapaName"  =>  \$CapaName

             ) or die "Illigal Options";

if(!  defined $array){ die "Array Name/ip Address is mendatory";}

my $wfautil=WFAUtil->new();

$wfautil->sendLog('INFO','Connecting to array:',$array);

$server=$wfautil->connect($array,$vfiler);

my $api = WFAUtil->new('useradmin-role-add');

my $xi = WFAUtil->new('useradmin-role');

$api->child_add($xi);

my $xi2 = WFAUtil->new('allowed-capabilities');

my $xi1->child_add($xi2);

my $xi3 = WFAUtil->new('useradmin-capability-info');

$xi2->child_add($xi3);

$xi3->child_add_string('name','login-snmp');

$xi1->child_add_string('comment','Testing');

$xi1->child_add_string('name','snmpAuth');

my $xi4=$wfautil->checkFailure("Failed to run the command",$server->invoke($api));

$wfautil->sendLog('INFO','Create the role for the user failed'.$array);

1 REPLY 1

mshearer
2,588 Views

This should work, however it only adds one capability and I have not figured out how loop it correctly to add more than one capability...

#!/usr/bin/perl

use strict;

use NaServer;

use Getopt::Long;

use WFAUtil;

my $array;

my $vfiler;

my $rolename;

my $comment;

my $capabilities;

GetOptions("array=s" => \$array,

          "vfiler:s" => \$vfiler,

                 "rolename:s" => \$rolename,

                       "comment:s"   =>  \$comment,

                       "capabilities:s"  =>  \$capabilities

             ) or die 'Illegal command parameters';

#my @capabilitieslist = split(',', $capabilities);

my $wfaUtil = WFAUtil->new();

$wfaUtil->sendLog('INFO','Connecting to array: '.$array);

my $server = $wfaUtil->connect($array, $vfiler);

my $add = new NaElement('useradmin-role-add');

my $role = new NaElement('useradmin-role');

$add->child_add($role);

my $roleinfo = new NaElement('useradmin-role-info');

$role->child_add($roleinfo);

$roleinfo->child_add_string('comment',$comment,);

$roleinfo->child_add_string('name',$rolename);

my $allowed = new NaElement('allowed-capabilities');

$roleinfo->child_add($allowed);

my $capainfo1 = new NaElement('useradmin-capability-info');

$allowed->child_add($capainfo1);

$capainfo1->child_add_string('name',$capabilities);

$wfaUtil->sendLog('INFO','Creating Role Name : '.$rolename);

my $out = $server->invoke_elem($add);

if ( $out->results_status() eq "failed" )

{

                              $wfaUtil->sendLog('WARN',"Unable to add role '".$rolename."'. Reason: ".$out->results_reason());

                              exit(1);

}

Public