Reply
Highlighted

Adding MAC address to existing host record

[ Edited ]
Techie
Posts: 3
8432     1

I am attempting to use the WAPI to set or change the mac_address on an existing host record. I have the _ref for the host and the ipv4address, but I am getting an error when using PUT against either.

 

These are examples of my attempts: 

 

{'data': {'mac': '<MAC>'},
'method': 'PUT',
'params': None,
'response': {'Error': 'AdmConProtoError: Field is not writable: mac',
'code': 'Client.Ibap.Proto',
'text': 'Field is not writable: mac'},
'url': 'https://<HOST>/wapi/v1.4/record:host/<..._ref>'}
{'data': {'mac': '<MAC>'},
'method': 'PUT',
'params': None,
'response': {'Error': u'AdmConProtoError: Operation update not allowed for ipv4address',
'code': 'Client.Ibap.Proto',
'text': 'Operation update not allowed for ipv4address'},
'url': 'https://<HOST>/wapi/v1.4/ipv4address/<..._ref>'}

 

{'data': {'mac_address': '<MAC>'},
 'method': 'PUT',
 'params': None,
 'response': {'Error': "AdmConProtoError: Unknown argument/field: 'mac_address'",
              'code': 'Client.Ibap.Proto',
              'text': "Unknown argument/field: 'mac_address'"},
 'url': 'https://<HOST>/wapi/v1.4/record:host/<..._ref>'}

 

What's the correct way to modify a host record to add a mac_address?

Highlighted

Re: Adding MAC address to existing host record

Adviser
Posts: 135
8432     1

@krets wrote:

I am attempting to use the WAPI to set or change the mac_address on an existing host record. I have the _ref for the host and the ipv4address, but I am getting an error when using PUT against either.

I was able to get this to work. The key point is that you do a PUT request against the host record, and you supply a new value for the ipv4addrs field. For example, suppose we start with a host record with name 'test.example.com' and IP address 10.0.0.1, but no MAC address defined. We first GET the host record to retrieve its object reference:

 

curl --tlsv1 --insecure --user 'admin:infoblox' 'https://gm.example.com/wapi/v2.2/record:host?name=test.example.com'

 

which returns the following record:host object:

 

[
    {
        "_ref": "record:host/ZG5zLmhvc3QkLl9kZWZhdWx0LmNvbS5leGFtcGxlLnRlc3Q:test.example.com/internal", 
        "ipv4addrs": [
            {
                "_ref": "record:host_ipv4addr/ZG5zLmhvc3RfYWRkcmVzcyQuX2RlZmF1bHQuY29tLmV4YW1wbGUudGVzdC4xMC4wLjAuMS4:10.0.0.1/test.example.com/internal", 
                "configure_for_dhcp": false, 
                "host": "test.example.com", 
                "ipv4addr": "10.0.0.1"
            }
        ], 
        "name": "test.example.com", 
        "view": "internal"
    }
]

 

We then do a PUT request against the host record (using its object reference returned from the GET request) that completely replaces the value of the ipv4addrs field:

 

curl --tlsv1 --insecure --user 'admin:infoblox' --header 'Content-Type: application/json' --data '{"ipv4addrs": [{"ipv4addr": "10.0.0.1", "mac": "01:23:45:67:89:ab"}]}' --request PUT 'https://gm.example.com/wapi/v2.2/record:host/ZG5zLmhvc3QkLl9kZWZhdWx0LmNvbS5leGFtcGxlLnRlc3Q:test.example.com/internal'

 

Repeating the curl GET request above shows that the resulting host record now has the specified MAC address defined for iP address 10.0.0.1:

 

[
    {
        "_ref": "record:host/ZG5zLmhvc3QkLl9kZWZhdWx0LmNvbS5leGFtcGxlLnRlc3Q:test.example.com/internal", 
        "ipv4addrs": [
            {
                "_ref": "record:host_ipv4addr/ZG5zLmhvc3RfYWRkcmVzcyQuX2RlZmF1bHQuY29tLmV4YW1wbGUudGVzdC4xMC4wLjAuMS4:10.0.0.1/test.example.com/internal", 
                "configure_for_dhcp": true, 
                "host": "test.example.com", 
                "ipv4addr": "10.0.0.1", 
                "mac": "01:23:45:67:89:ab"
            }
        ], 
        "name": "test.example.com", 
        "view": "internal"
    }
]

 

Note carefully: You should NOT specify the host field when updating the value of the ipv4addrs field. That's because the host field is a non-writable field that (as far as I know) is simply inherited from the enclosing host record object.

 

Also note that if the host record is associated with multiple IP addresses then you will need to make sure that the updated value of the ipv4addrs field supplied in the PUT request also reflects the previous data for the IP addresses other than the one for which you're adding or updating the MAC address. Doing this properly is left as an exercise for the reader :-)

 

Frank

Highlighted

Re: Adding MAC address to existing host record

Adviser
Posts: 135
8433     1

@FHecker wrote:

I was able to get this to work. The key point is that you do a PUT request against the host record, and you supply a new value for the ipv4addrs field.

Actually, after thinking about this again and doing some more testing I realized that it's even easier than that. You can just do a PUT request against the record:host_ipv4addr object (i.e., using its object reference); again, don't specify a value for the host field in the record:host_ipv4addr object, because that field is not writable.

 

For example, from the original GET request above we have a reference "record:host_ipv4addr/ZG5z...uMS4:10.0.0.1/test.example.com/internal" to the record:host_ipv4addr object corresponding to IP address 10.0.0.1 in the host test.example.com. We simply do a PUT request against that object reference to provide a new MAC address (in this case 01:01:01:01:01:01:

 

curl --tlsv1 --insecure --user 'admin:infoblox' --header 'Content-Type: application/json' --data '{"mac": "01:01:01:01:01:01"}' --request PUT 'https://gm.fhecker.com/wapi/v2.2/record:host_ipv4addr/ZG5zLmhvc3RfYWRkcmVzcyQuX2RlZmF1bHQuY29tLmV4YW1wbGUudGVzdC4xMC4wLjAuMS4:10.0.0.1/test.example.com/internal'

 

Repeating the GET request against the host record shows that the MAC address has been correctly updated:

 

[
    {
        "_ref": "record:host/ZG5zLmhvc3QkLl9kZWZhdWx0LmNvbS5leGFtcGxlLnRlc3Q:test.example.com/internal", 
        "ipv4addrs": [
            {
                "_ref": "record:host_ipv4addr/ZG5zLmhvc3RfYWRkcmVzcyQuX2RlZmF1bHQuY29tLmV4YW1wbGUudGVzdC4xMC4wLjAuMS4:10.0.0.1/test.example.com/internal", 
                "configure_for_dhcp": true, 
                "host": "test.example.com", 
                "ipv4addr": "10.0.0.1", 
                "mac": "01:01:01:01:01:01"
            }
        ], 
        "name": "test.example.com", 
        "view": "internal"
    }
]

 

The advantage of this method is that it doesn't affect the data for other IP addresses associated with the host record in question.

 

Also note that you really don't need to include the IP address when updating the record:host_ipv4addr object. Given that you're providing the object reference, that by itself identifies the IP address corresponding to the MAC address to be added or updated.

 

Finally, I did all my testing against NIOS 7.2 (WAPI version 2.2). I can't guarantee that this will work in earlier NIOS versions.

 

Frank

Highlighted

Re: Adding MAC address to existing host record

Techie
Posts: 3
8433     1
'url': 'https://<HOST>/wapi/v1.4/record:host_ipv4addr/<..._ref>'
'method': 'PUT', 'data': {'configure_for_dhcp': True, 'mac': 'fa:16:3e:99:83:7f'}, 'status_code': 200, 'response': 'record:host_ipv4addr/<..._ref>'

Frank,

Thank you for the quick response. With your help I am successfully making changes. I don't quite understand why there is both an ipv4addr and a host_ipv4addr for the same IP address, but I'm happy to be over this little hurdle.

Cheers,

Jesse

 

PS, Thanks for all your previous posts and replies. I have referenced your posts often while getting setup with infoblox.

Highlighted

Re: Adding MAC address to existing host record

Techie
Posts: 3
8433     1

Unfortunately, I am a bit stumped again. How should I handle it when ther is both a fixedaddress AND an host_ipv4addr? I'm not much of an Infoblox admin, so I'm looking through the docs now.

 

Any chance you know what I should do in this case? More details below.

 

This is the operation you suggested and has worked for _most_ updates:

 

url: https://<HOST>/wapi/v1.4/record:host_ipv4addr/<..._ref>
method: PUT
params: None
data&colon; 
    {'configure_for_dhcp': True, 'mac': '18:42:1d:cb:17:9e'}
status_code: 400
response: 
    {u'Error': u'AdmConDataError: None (IBDataConflictError: IB.Data.Conflict:IP address 10.73.110.11 is already used by a reservation.)',
     u'code': u'Client.Ibap.Data.Conflict',
     u'text': u'IP address 10.73.110.11 is already used by a reservation.'}

 

I started with an IP lookup:

 

url: https://<HOST>/wapi/v1.4/ipv4address/<..._ref>
method: GET
params:
{'ip_address': '10.73.110.11'}
data&colon; None
status_code: 200
response:
[{u'_ref': u'ipv4address/<..._ref...>:10.73.110.11',
u'ip_address': u'10.73.110.11',
u'is_conflict': False,
u'mac_address': u'',
u'names': [u'<hostname>'],
u'network': u'10.73.108.0/22',
u'network_view': u'default',
u'objects': [u'fixedaddress/<..._ref>',
u'record:host/<..._ref>'],
u'status': u'USED',
u'types': [u'RESERVATION', u'HOST'],
u'usage': [u'DHCP', u'DNS']}]

 

This is the host record:

url: https://<HOST>/wapi/v1.4/record:host/<..._ref>
method: GET
params: None
data&colon; None
status_code: 200
response: 
{u'_ref': u'record:host/<..._ref>',
 u'ipv4addrs': [{u'_ref': u'record:host_ipv4addr/<..._ref>',
                 u'configure_for_dhcp': False,
                 u'host': u'<hostname>',
                 u'ipv4addr': u'10.73.110.11'}],
 u'name': u'<hostname>',
 u'view': u'default'}

This is the host_ipv4addr:

url: https://<HOST>/wapi/v1.4/record:host_ipv4addr/<..._ref>
method: GET
params: None
data&colon; None
status_code: 200
response: 
{u'_ref': u'record:host_ipv4addr/<..._ref>',
 u'configure_for_dhcp': False,
 u'host': u'<hostname>',
 u'ipv4addr': u'10.73.110.11'}

 

This is the fixedaddress record:

url: https://<HOST>/wapi/v1.4/fixedaddress/<..._ref>
method: GET
params: None
data&colon; None
status_code: 200
response: 
{u'_ref': u'fixedaddress/<..._ref>',
 u'ipv4addr': u'10.73.110.11',
 u'network_view': u'default'}

 

 

Highlighted

Re: Adding MAC address to existing host record

[ Edited ]
Community Manager
Community Manager
Posts: 248
8433     1

The 'record:host_ipv4addr' is just a shortcut directly to one of the IP addresses in a host struct. You probably shouldn't be using that object unless you know exactly what you are doing and what you are looking for.

 

You should also know that for the host_ipv4addr "...Fields other than ipv4addr, host and configure_for_dhcp are returned only when configure_for_dhcp is true.

 

ok, so what does all that mean ?

 

If an IP address on a host also has a MAC address, NIOS goes ahead and creates a 'fixedaddress' object as well, you can get to it as a 'fixed address' but it is just an abstraction of the data on the host 'ipv4addrs' array.

 

if your host had MORE than 1 ip address and you wanted to change one of them you would have to push and pull items from the host 'ipv4addrs' array which can sometimes be annoying, so the again the 'record:host_ipv4addr' is just an apstraction directly into one of the elements in that array.

 

If you are new to the WAPI and want to stay sane, it is easier to just make all your changes to the 'record:host' object where you can see all the data in one place.

 

However, and here's where things can break.

 

It is possible to create a FIXEDADDRESS and a HOST that have the same IP but are not connected to each other. Only some fixed addresses are pointers to the host, it depends on how they were created. This often happens with reservations, and that is the error you are seeing. You are trying to add a MAC address to a host ipaddress, but NIOS is kicking an error because it says there is a reservaton (which is just a fixedaddress with a mac of '00000000'), and that reservation/fixedaddr has the same address as the host , thus the conflct.

 

So, what do you do ?

 

Well there is no good simple solution.

 

before you modify the host, you need to check if there is a fixedaddress using that IP address.

 

You saw that data in the 'objects' array when you searched for the /ipv4address, but didn't recognise it. there are 2 objects there: host and fixedaddress

 

you could try and modify the host and risk a conflict with a dangling fixedaddress, or

you could try and modify the fixed address and then find out that it isn't attached to the host

 

the right thing to do may be to trash the fixed address, add all the IP/MAC data to the host object and let NIOS clean up all the references for you.

 

oh, and in case you were't confused yet, depending on the version of the WAPI, whan you search for a /fixedaddress you don't get back fixedaddrs that are attached to hosts, we fixed this bug, around v1.7 I think.

 

YMMV.

 

 

 

 

 

 

 

 

Highlighted

Re: Adding MAC address to existing host record

Techie
Posts: 3
8433     1

As a followup question how can we undertand an is fixed address or leases ipaddress ? Is there any specific api ?

Showing results for 
Search instead for 
Did you mean: 

Recommended for You