Reply
Accepted Solution

Is there a way to create extensible attributes.

mmarseglia
Techie
Posts: 2
5940     0

 

  Does WAPI v1.4 support the creation of Exensible Attributes or can that only be done via the GUI?  I've seen examples of adding EA's to objects, but how to create the EA itself?

 

  Example, I have an EA called "Country" and I want to import the list of ISO country short names.  Can this be done?

 

Re: Is there a way to create extensible attributes.

[ Edited ]
Adviser
Posts: 267
5940     0

Hey MMars,

 

Thank you for posting and tweeting us!  I've forwarded your question on as there may be an update since this thread:

 

https://community.infoblox.com/t5/API-Integration/Add-a-New-Extensible-Attribute-via-WAPI/m-p/1536#M...

 

[I've just received confirmation you CAN do this as of WAPI 2.2...]

 

Best,

 

Eric

If you appreciate my efforts, please give me a kudo ↓ or Accept as solution to help others find it faster.

Re: Is there a way to create extensible attributes.

Adviser
Posts: 43
5940     0

Creation of Extensible Attribute definitions was added in WAPI 2.2 (NIOS 7.2).

Re: Is there a way to create extensible attributes.

[ Edited ]
Authority
Posts: 42
5940     0

 I need a better working example of this, as I just cannot get it to work with v2.5 of the WAPI.

 

I'm using one of the library that I found on here that has a couple of classes already configured.

 

so if I do the following, life is good:

note: network 10.29.20.0/24 was  previously created via GUI, and has ext attributes defined, including one named Building

ea = {'Building': '20', 
'Floor(s)': '0', 
'Site': 'Site A', 
'Location': '0n729', 
'Interface': 'GigabitEthernet2/0/12', 
'Date Assigned': '2017-08-10', 
'DHCP': 'N', 
'Renewal Date': '2019-08-10', 
'Legacy VLAN': 0, 
'Disposition': 'ACTIVE', 
'Usage': 'Prod', 
'Service': '0N729CLOSET_/ UPLINK TO W0N222-MDFA-NEW G1/3/5', 
'Source': 'value': 'python', 
'Switch': 'access123', 
'Tech': 'fred', 
'Zone': 'Basic-Internal (bint)'}

 

ea = iblx.get_network_extattrs(net)
ea['Building'] = '1000' #change Building value resp = iblx.update_network_extattrs(net,ea)

After the program runs, Building is changed from a value of '20' to a value of '1000'

ea = {'Building': '1000', 
'Floor(s)': '0', 
'Site': 'Site A', 
'Location': '0n729', 
'Interface': 'GigabitEthernet2/0/12', 
'Date Assigned': '2017-08-10', 
'DHCP': 'N', 
'Renewal Date': '2019-08-10', 
'Legacy VLAN': 0, 
'Disposition': 'ACTIVE', 
'Usage': 'Prod', 
'Service': '0N729CLOSET_/ UPLINK TO W0N222-MDFA-NEW G1/3/5', 
'Source': 'value': 'python', 
'Switch': 'access123', 
'Tech': 'fred', 
'Zone': 'Basic-Internal (bint)'}

If I attempt to add an EA, say something called State, with a value of "FL", the update fails with a 400 error.

 

Now, if I look at the WAPI docs, it mentions using 'extattrs+' in the payload, instead of 'extattrs', and I've tried that.  I still get a 400 error,

 

I can only assume that I'm mangling the request and I need some different formatting in there somewhere.

 

Does anybody have an example of a properly formatted request to do this?  When adding an EA to an existing object, is that a PUT or a POST?

 

Ideally I'd like to create a network with its EAs present upon creation of the network object.  Is that even possible?

 

If I do this via GUI, I get a list of EAs (with no values), as I've specifically restricted a number of EAs to network objects only. However, if I create a network via the WAPI, and then attempt viee the EAs via GUI or WAPI, there are no EAs associated with the network objects in question.

 

The class I'm using is below.  It has a number of print statements added to try to figure out what's going on:

    def update_network_extattrs_new(self, network, attributes):
        ''' Implements IBA REST API call to add or update network extensible attributes
        :param network: network in CIDR format
        :param attributes: hash table of extensible attributes with attribute name as a hash key

        '''
        rest_url = 'https://' + self.iba_host + '/wapi/v' + self.iba_wapi_version + '/network?network=' + network + '&network_view=' + self.iba_network_view + '&_return_fields=network,extattrs'
        extattrs = {}
        try:
            r = requests.get(url=rest_url, auth=(self.iba_user, self.iba_password), verify=self.iba_verify_ssl)
            r_json = r.json()
            if r.status_code == 200:
                if len(r_json) > 0:
                    network_ref = r_json[0]['_ref']
                    print('\nref?:',network_ref)
                    if network_ref:
                        extattrs = r_json[0]['extattrs']
#@# python2 iteritems --> python3 items
                        print('ref_extarrs:',extattrs)
                        print('\nattributes:',attributes)
                        for attr_name, attr_value in attributes.items():
                            extattrs[attr_name] = attr_value
                        print('\nextattrs:',extattrs)
                        payload = '{"extattrs+": ' + json.JSONEncoder().encode(extattrs) + '}'
                        print('\nPayload: <',payload,'>')
                        rest_url = 'https://' + self.iba_host + '/wapi/v' + self.iba_wapi_version + '/' + network_ref
                        print('\nURL: <',rest_url,'>')
                        r = requests.put(url=rest_url, auth=(self.iba_user, self.iba_password), verify=self.iba_verify_ssl, data=payload)
                        if r.status_code == 200:
                            return
                        else:
                            if 'text' in r_json:
                                raise InfobloxGeneralException(r_json['text'])
                            else:
                                r.raise_for_status()
                    else:
                        raise InfobloxGeneralException("No network reference received in IBA reply for network: " + network)
                else:
                    raise InfobloxNotFoundException("No requested network found: " + network)
            else:
                if 'text' in r_json:
                    raise InfobloxGeneralException(r_json['text'])
                else:
                    r.raise_for_status()
        except ValueError:
            raise Exception(r)
        except Exception:
            raise

 

Re: Is there a way to create extensible attributes.

Adviser
Posts: 357
5940     0

Not sure what library you are using, but the one we use internally is this one:

 

https://github.com/infobloxopen/infoblox-client

 

John

 

Highlighted

Re: Is there a way to create extensible attributes.

Authority
Posts: 42
5940     0

Allow me to restate my question:

 

Is it possible to create an object with explicit extensible attributes upon creation of the object?  The only way I've gotten this to work is to:

 

1) Create the object (POST),

2) Grab the object using the unique reference (GET)

3) Update the object using "extattrs+":{...} (PUT)

 

I'd like to do it in one step, not three.

Re: Is there a way to create extensible attributes.

Adviser
Posts: 95
5941     0

Yes, here's a curl example using the next-availale-ip function to automatically choose an address within a specific network, and also assign an Extensible Attribute value.

 

curl -k1 -u admin:infoblox -H 'Content-Type: application/json' -X POST \
    'https://10.9.16.6/wapi/v2.1/record:host' \
     -d '{"name": "test103.richard.network",
          "ipv4addrs": [{"ipv4addr": {"_object_function": "next_available_ip",
                         "_object": "network", "_object_parameters": {"network": "10.102.0.0/16"},
                         "_result_field": "ips"}}],
          "extattrs":{"Site":{"value":"East Coast Data Center"}}}'

 

Re: Is there a way to create extensible attributes.

Authority
Posts: 42
5941     0

OK, I'll give this a shot, with the following possible gotchas:

 

1) Not using curl, so I have to build the string in python, as pass it all to WAPI;  which, I know how to do, but it just gets hard to keep it all straight.

2) Not using host records or ipv4 address objects or next_available_ip function, am more interested in populating EAs when I create networks, but perhaps, it will work.

Re: Is there a way to create extensible attributes.

echandler1971
Techie
Posts: 12
5941     0

I create containers and networks with the extattrs combined all the time.

 

from infoblox_client import connector, objects

cidr = '86.75.30.9/32'

netdict = {'someextattr1': 'bla', 'somethingelse': 'bla2'}

ea = objects.EA(netdict)
objects.Network.create(conn, cidr=cidr, extattrs=ea)

Re: Is there a way to create extensible attributes.

[ Edited ]
Adviser
Posts: 83
5941     0

If an extensible attribute already exists (for example-State), you can add it to the network while creating as show below. (Remember to replace the values in bold to values specific to your environment)

import requests
requests.packages.urllib3.disable_warnings()  # Disable SSL warnings in requests #
url = "https://grid-master/wapi/v2.7/network?_return_as_object=1&_return_fields%2B=network,extattrs"
payload = "{\"network\":\"1.1.1.0/24\",\"extattrs\": {\"State\":{\"value\":\"FL\"}}}"
headers = {'content-type': "application/json"}
response = requests.request("POST", url, auth=('admin', 'infoblox'), data=payload, headers=headers, verify=False)
print(response.text)

 You will see an output similar to:

{
    "result": {
        "_ref": "network/ZG5zLm5ldHdvcmskMS4xLjEuMC8yNC8w:1.1.1.0/24/default",
        "extattrs": {
            "State": {
                "value": "FL"
            }
        },
        "network": "1.1.1.0/24",
        "network_view": "default"
    }
}

 

Re: Is there a way to create extensible attributes.

Adviser
Posts: 49
5941     0

Relying on https://github.com/infobloxopen/infoblox-client 

 

Here is how I maintain EA list values:

 

import logging
import csv
logging.basicConfig(level=logging.DEBUG)

from infoblox_client import connector
from infoblox_client import objects

opts = {'host': '192.168.206.53', 'username': 'admin', 'password': 'infoblox', 'wapi_version': '2.5'}
conn = connector.Connector(opts)

# Get Data from CSV

with open('my.csv') as csvfile:
reader = csv.DictReader(csvfile, delimiter=';')
Country = []
for row in reader:
if row['COUNTRY'] not in Country:
Country.append(row['COUNTRY'])


# Sort
Country.sort()

#print Country

# Get Data from Extensible Attributes
EACountry = objects.EADefinition.search(conn, name='Country', return_fields=['name', 'list_values'])

# Since modified list values are removed from object, I have decided not to rename to value - deprecated but to remove it as
# Update

EACountry.list_values = []
[EACountry.list_values.append({'value':val}) for val in Country]
EACountry.update()
Check out our new Tech docs website at http://docs.infobox.com for latest documentation on Infoblox products.
Showing results for 
Search instead for 
Do you mean 

Recommended for You