Reply
Highlighted

store returned reference to a string

tracymcclain
Techie
Posts: 2
863     0

Is it possible to store a returned reference to a string that can then be used in another command?

 

Basically what I'm looking to do is to get the reference for an a record and then use that reference to change the ip address using a script.

 

Re: store returned reference to a string

Adviser
Posts: 95
864     0

Sure, like in this example. Any update you want to perform, first requires you to get the object db reference. You will need to add it to the URL:

 

First GET user Object _ref
    
        curl -k -u admin:infoblox -H "Content-Type: application/json" -X GET https://192.168.0.110/wapi/v2.2/adminuser?name=myuser
    
    Use _ref to update the password:
    
        curl -k -u admin:infoblox -H "Content-Type: application/json" -X PUT https://192.168.0.110/wapi/v2.2/adminuser/b25lLmFkbWluJG15dXNlcg:myuser -d '{"password": "infoblox2" }'

 

 

Now in a script, you can do the following (pseudo code):

 

my $json = from_json($client->responseContent());
   #print Dumper \$json;
   
   
   foreach my $item( @$json ) { 
 
      print "$item->{name}\n";
   
      # Modify Object
   
      my $ref = $item->{_ref};
      delete $item->{_ref};

      $item->{name} = "new-name";
   
      if ( restcall("PUT", "wapi/v2.5/$ref", $json_send->encode($item)) )
      {	
   	  print "Obj modified\n";
     }

Re: store returned reference to a string

[ Edited ]
Adviser
Posts: 66
864     0

Adding on to SSieber's approach, you can also use the Multiple Object Body Feature available with the /request object, which allows the control of WAPI through a single-entry point.

Multiple object body requests are composed of a list of single requests. While programming this enables to make multiple requests with one API call, thus simplifying an operation, and reducing the number of API calls to be made. In addition to the standard HTTP methods (GET, PUT, POST, and DELETE), single request inside a multiple object body request can be set to these values:

Method

Description

STATE:ASSIGN

Copy fields in the data object to the state object.

STATE: DISPLAY

Added the state object to the returned result list.


Note: The Multiple Object Body Feature is only available NIOS 7.1 onwards (WAPI v2.1 onwards)

 

To modify the IP address of an A record, you can use the following call (Replace the content highlighted in bold)

curl -k -u admin:infoblox -H 'content-type:application/json' -X POST "https://grid-master/wapi/v2.7/request" -d '[{"method": "STATE:ASSIGN","data":{"host_name":"www.test.com"}},{"method":"GET","object": "record:a","data": {"name":"##STATE:host_name:##"},"assign_state": {"host_ref": "_ref"},"enable_substitution": true,"discard": true},{ "method": "PUT", "object": "##STATE:host_ref:##","data": {"ipv4addr":"1.1.1.100"},"enable_substitution": true,"discard": true},{"method": "GET","object": "record:a","data": {"name":"www.test.com"}}]'

 

Showing results for 
Search instead for 
Do you mean 

Recommended for You