Automation Scripts

Reply

Failure in Adding rows to a List using Perl and the API documentation

Authority
Posts: 39
659     0

I have the foundation of a Perl script to try to populate an existing list in NetMRI, however I am a bit confused about part of the API documentation (- since this is not my strong point) and I can't get it to populate the row.

 

The script is successful in getting the contents of a list and I can use Data:Smiley Very Happyumper to see the format of the references.

The list has 3 columns, 'distdomainname', 'dist_ipaddress_d1' and 'dist_ipaddress_d2'

The list ID is 6.

 

 

 

So my script;

my $Rows = $client->broker->config_list->rows('id' => 6);

print Dumper($Rows);

 

gives;

$VAR1 = { 'current' => 0, 'limit' => 1000, 'total' => 17,

'rows' => [ 

    { 'distdomainname' => 'T1', 

       'dist_ipaddress_d2' => '10.63.1.12', 

       'dist_ipaddress_d1' => '10.63.1.11', 

       'id' => 9 

},

Etc.

This bit seems to work and results in 17 rows (currently) as seen in the output from Dumper. (I removed all but one to keep it simple).

 

If I now try to create a row, with some data, all it does is creates a blank row with no data.

This is the part I am struggling with as the document is unclear.

 

my $newRow = $client->broker->config_list->create_row('id' => 6, $distdomainname => 'newBit');

 

The script output says uninitialized value, so I think I am missing something.

Use of uninitialized value $_[2] in anonymous hash ({}) at usr/share/perl5/vendor_perl/NetMRI/API/Broker.pm line 52.

 

The following just creates the blank lines but doesn’t show any errors.

my $newRow = $client->broker->config_list->create_row('id' => 6)->{'rows'} = {'$distdomainname' => 'newBit',       '$dist_ipaddress_d1' => 'IP1','$dist_ipaddress_d2' => 'IP2'};

 

 

The document says you put in the $ before the ‘foo’ so in this case, I guess this would be the column name, ‘distdomainname’, so I have to put in $distdomainname. 

 

Document extract.

$broker->create_row( \%inputs )

Create a row in a config list
INPUTS

id: Optional Integer

The internal NetMRI identifier for the list. Either id or name is required.
name: Optional String

The name of the config list. Either id or name is required.
list_columns: Optional String

Each list column to be updated should be included as a separate input, starting the name with $ (no actual input named list_columns is needed). For example, you can update the column 'foo' of a list to 'bar' by passing $foo as the input name, along with the value 'bar'.

OUTPUTS

list_row: Hash

The config list row that was created.

 

 

Hope this makes sense.

 

Thanks

Russ

 

Highlighted

Re: Failure in Adding rows to a List using Perl and the API documentation

Guru
Posts: 61
659     0
my $newRow = $client->broker->config_list->create_row('id' => 6)->{'rows'} = {'$distdomainname' => 'newBit',       '$dist_ipaddress_d1' => 'IP1','$dist_ipaddress_d2' => 'IP2'};

 

On the above line, you are single quoting a variable.   This treats it as a literal string instead of a variable.  

Another issue- generally, you don't have the variable on the key side of the hash element, but rather the value. 

This isn't to say it isn't possible, but I am doubtful you are trying to use a dynamic key here.

 

Hope this helps.

 

 

Showing results for 
Search instead for 
Do you mean 

Recommended for You