Reply
Highlighted
Accepted Solution

Update EA List

rjin9673
Techie
Posts: 4
6610     0
Hello,

As part of our automation framework, we want our network objects to have an EA which is a list of company codes pulled from our CMDB. I unfortunately cannot find how to 'GET' this EA list through the WAPI, or to 'PUT' at the list with values from my CMDB on a regular schedule. Has anyone tried this yet?

Re: Update EA List

Moderator BRampling
Moderator
Posts: 69
6611     0

Note that the EA type must be ENUM (list) for this to work. To get the list of possible values:

 

curl -k1 -u admin:infoblox -H "Content-Type: appliction/json" -X GET https://10.60.27.4/wapi/v2.5/extensibleattributedef?_return_fields=list_values -d '{"name":"CompanyCode"}'
[
    {
        "_ref": "extensibleattributedef/b25lLmV4dGVuc2libGVfYXR0cmlidXRlc19kZWYkLkNvbXBhbnlDb2Rl:CompanyCode", 
        "list_values": [
            {
                "value": "CompanyA"
            }, 
            {
                "value": "CompanyB"
            }, 
            {
                "value": "CompanyC"
            }
        ]
    }
]

This will update the list and add a list value of "CompanyD":

curl -k1 -u admin:infoblox -H "Content-Type: application/json" -X PUT https://10.60.27.4/wapi/v2.5/extensibleattributedef/b25lLmV4dGVuc2libGVfYXR0cmlidXRlc19kZWYkLkNvbXBhbnlDb2Rl:CompanyCode -d '{"list_values":[{"value":"CompanyA"},{"value":"CompanyB"},{"value":"CompanyC"},{"value":"CompanyD"}]}'

Get the list again and you'll see the updated list:

curl -k1 -u admin:infoblox -H "Content-tion/json" -X GET https://10.60.27.4/wapi/v2.5/extensibleattributedef?_return_fields=list_values -d '{"name":"CompanyCode"}'
[
    {
        "_ref": "extensibleattributedef/b25lLmV4dGVuc2libGVfYXR0cmlidXRlc19kZWYkLkNvbXBhbnlDb2Rl:CompanyCode", 
        "list_values": [
            {
                "value": "CompanyA"
            }, 
            {
                "value": "CompanyB"
            }, 
            {
                "value": "CompanyC"
            }, 
            {
                "value": "CompanyD"
            }
        ]
    }
]

Re: Update EA List

rjin9673
Techie
Posts: 4
6611     0

Thank you! I actually found this out by reading up at https://ipam.illinois.edu/wapidoc/index.html# and playing around, but came to the same conclusion. I am not only able to retrieve, but able to PUT the list, which is really just overwriting. I was able to confirm that no matter what order I changed the value when doing a new PUT, it did not effect any other items that used a value from the EA which is great for automation.

 

I was using Python 2.7 against WAPI 2.2.2. Thanks again for the response. My example code is below:

 

 

for line in sf_company_list:
     temp_company_list.append({'value': line['u_sf_account_number']})

new_company_list = sorted(temp_company_list, key=lambda k: k['value'])

print 'Please enter your Infoblox credentials'
user, pwd = get_credentials()

print 'Updating the company list in Infoblox'
infoblox_calls.put_company_list(ib_url, user, pwd, new_company_list)

The GET:

def get_company_id_list(ib_url, user, pwd):
    table = 'extensibleattributedef'
    ref = 'b25lLmV4dGVuc2libGVfYZWYkLkNvbXBhbnkgSUQ:Company%20ID'
    params = '?_return_fields=list_values'

    company_id_list = perform_request(ib_url, table, user, pwd, 'GET', params, ref, fields='')

    return json.loads(company_id_list)

The PUT:

def put_company_list(ib_url, user, pwd, new_company_list):
    table = 'extensibleattributedef'
    attribute = 'b25lLmV4dGVuc2libGVfkZWYkLkNvbXBhbnkgSUQ:Company%20ID'
    new_company_dict = {"list_values": new_company_list}

    put_response = perform_request(ib_url, table, user, pwd, 'PUT', params='', ref=attribute,
                                   fields=json.dumps(new_company_dict))
    return put_response

The actual request:

def perform_request(ib_url, table, user, pwd, operation, params, ref, fields,
                    content_type=JSON):
    """
    Send an HTTPS request to the Web API server.
    """
    # Create connection and request header.
    # This class does not perform any verification of the server`s certificate.
    conn = HTTPSConnection(ib_url)
    auth_header = 'Basic %s' % (':'.join([user, pwd])
                                .encode('Base64').strip('\r\n'))
    request_header = {'Authorization': auth_header,
                      'Content-Type': content_type}
    if ref:
        url = PATH + table + '/' + ref
    else:
        url = PATH + table
    if params:
        url += params

    conn.request(operation, url, fields, request_header)
    response = conn.getresponse()
    if 300 > response.status >= 200:
        return handle_success(response)
    else:
        return handle_exception(response)

 

Re: Update EA List

Authority
Posts: 19
6611     0

We wanted to include a new EA , Lets say VLAN-ID, type ENUM(LIST). Starts from 1,2 ...till  255.

is there a API where I could assign VLAN ID to a particular range of IP address?

 

For example :

149.203.3.0/24 as  VLAN-ID : 3

149.203.121/24 as  VLAN-ID :121

Assigning Individually is a tedious process.

 

Thank you

 

Re: Update EA List

Adviser
Posts: 100
6611     0

Hi,

 

Assuming that the EA VLAN ID is already defined in your grid, you can update the EA as below.

curl -k -u admin:Infoblox -H 'content-type: application/json' -X PUT "https://127.0.0.1/wapi/v2.7/network/ZG5zLmhvc3QkLl9kZWZhdWx0LmNvbS5pbmZvLndhcGk:149.203.3.0/24/default?_return_fields%2B=extattrs&_return_as_object=1" -d '{"extattrs":{"VLAN-ID": {"value": "3"}}}'

Thanks and Regards,

Krishna Vasudevan

Showing results for 
Search instead for 
Do you mean 

Recommended for You

Businesses are investing heavily into securing company resources from cyber-attacks form cybercrimin