- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
Failure in Adding rows to a List using Perl and the API documentation
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
08-03-2018 06:57 AM
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:umper 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
Re: Failure in Adding rows to a List using Perl and the API documentation
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
09-10-2018 12:14 PM
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.