API & Integration

Reply
Highlighted
Accepted Solution

Adding Extensible Attribute value to existing Network via PERL API

davesampson
Techie
Posts: 5
3350     0

what I am trying to do is add extensible values for a previously created Network/Network Containers in my IPAM.  I have create code that modifies/adds a value to the Comment field but I can't find a way to modify/add to an extensible attribute.

 

here is the code that works my question is how do I modify the code to work with an extensible attribute called building.

 

my @result_array = $session->get(
object => "Infoblox:Smiley Very HappyHCP::Network" ,
network => "10.65.6.32/27",
);

my $bind_a = $result_array[0];

$bind_a->comment("test2");

my $response = $session->modify ( $bind_a );

Re: Adding Extensible Attribute value to existing Network via PERL API

GHorne Community Manager
Community Manager
Posts: 254
3351     0

EAs are in a nested datastructure and, to make matters more confusing, if there are no EAs set on an object we return 'undef' instead of an empty set.

 

So if you are modifying an object you have to first get the current EAs :

 

my $exts = $obj->extensible_attributes() || {}; # handle undef

Then you can set the value on an EA

$exts->{'Site'} = $myNewSite ;

Then you need to write the EAs back to the object

$obj->extensible_attributes( $exts );

 

 

Re: Adding Extensible Attribute value to existing Network via PERL API

davesampson
Techie
Posts: 5
3351     0

Worked great....thanks.  Was this located anywhere in the API documentation?

Re: Adding Extensible Attribute value to existing Network via PERL API

[ Edited ]
GHorne Community Manager
Community Manager
Posts: 254
3351     0

yes, in every object page, under the section 'extensible_attributes'

 

extensible_attributes( )
           Use this method to set or retrieve the extensible attributes
           associated with a DNS Host object.

           Include the specified parameter to set the attribute value. Omit
           the parameter to retrieve the attribute value.

           Parameter
               For valid values for extensible attributes, see
               Infoblox::Grid::ExtensibleAttributeDef/Extensible Attribute
               Values.

           Returns
               If you specified a parameter, the method returns true when the
               modification succeeds, and returns false when the operation
               fails.

               If you did not specify a parameter, the method returns the
               attribute value.

           Example
                #Get extensible attributes
                my $ref_extensible_attributes = $host->extensible_attributes();
                #Modify extensible attributes
                $host->extensible_attributes({ 'Site' => 'Santa Clara', 'Administrator' => [ 'Peter', 'Tom' ] });

Re: Adding Extensible Attribute value to existing Network via PERL API

SunnyGuy53
Techie
Posts: 2
3351     0

So how about deleting an EA key, in our case named 'HOSTGROUP'?

 

$exts = $obj->extattrs() ;

 

delete $exts->{'HOSTGROUPS'};

 

$obj->extattrs($exts);

 

Is that about right? I can't seem to get it to work....

 

Thank you.

Mark

Re: Adding Extensible Attribute value to existing Network via PERL API

hariganesh
Techie
Posts: 1
3351     0

I am not sure where I do mistake. I am trying to update EA-Class with value "TEST" but not happening with follwoing script. Please help

 

 

my @retrieved_objs = $session->search(
object => "Infoblox:Smiley Very HappyNS::Record::A",
zone => "testw02.pt",
view => "soft",
);

foreach my $item (@retrieved_objs) {
       my $i = $item->extensible_attributes();
       my $eac = 'TEST';
       $i->{'Class'} = $eac ;
       $item->extensible_attributes( $i );

}

Showing results for 
Search instead for 
Do you mean 

Recommended for You