david-caro / python-foreman

Small low level python wrapper around Foreman API
GNU General Public License v2.0
57 stars 37 forks source link

problem modifying interfaces #88

Open bboles opened 6 years ago

bboles commented 6 years ago

Hello,

I am trying to modify an interface on an existing host but am not having any luck. This is a physical server that has 4 interfaces, plus an IPMI interface. I want to modify only one of the interfaces. I have tried using the hosts.update routine like this:

In [324]: f.hosts.update('341423',
     ...:     {'interface_attributes': [{
     ...:         '1': {'identifier': 'enp3s0f1',
     ...:              'ip': '172.28.5.28',
     ...:              'subnet_id': '13',
     ...:              'primary': 'true',
     ...:              'managed': 'true'
     ...:             }
     ...:            }]
     ...:     }
     ...: )

The only thing that happens is that I get back a hash of the host attributes but the interface doesn't get updated. There is no error. I have also tried the same thing with hosts.interfaces_host_id_updateinterfaces and have not been able to get that function to work correctly at all. Can you give me any pointers on the best way to go about modifying an interface?

david-caro commented 6 years ago

Sorry for the delay, I'm not using this project for work anymore so I have to fall back to maintaining it on my spare time.

So, first I would check if there are any logs on the server side that might give any hints. Then I'd check if the underlying put request that is sent is correct (probably with tcpdump or similar... I'm a systems guy xd).

If the put request looks ok, then it might be an issue on the server side (as the cli is sending what it should), if not, then the issue is on the cli side, if you pass me that info then I will be able to dig into that sooner.

On the other side, for me is not completely clear from the foreman api docs (I checked the latest version), how should the interfaces be upgraded. There seem to be two endpoints, hosts update (PUT /api/hosts/:id), and interfaces update (PUT /api/hosts/:host_id/interfaces/:id).

You are using the first. To me it looks like though the interface_attributes element you are sending might not be correct, are you sure it should not be like this?

In [324]: f.hosts.update('341423',
     ...:     {'interface_attributes': [
     ...:          {'identifier': 'enp3s0f1',
     ...:           'ip': '172.28.5.28',
     ...:           'subnet_id': '13',
     ...:           'primary': 'true',
     ...:           'managed': 'true'
     ...:           }
     ...:     ]}
     ...: )

For the other form, should be quite similar:

In [22]: cli.hosts.interfaces_host_id_updateinterfaces?
Signature: cli.hosts.interfaces_host_id_updateinterfaces(interface, host_id, id)
Docstring:
Update a host's interface

:param interface: interface information; Must be a Hash (REQUIRED)
:param interface[mac]: MAC address of interface; Must be String (OPTIONAL)
:param interface[ip]: IP address of interface; Must be String (OPTIONAL)
:param interface[type]: Interface type, i.e: Nic::BMC; Must be String (OPTIONAL)
:param interface[name]: Interface name; Must be String (OPTIONAL)
:param interface[subnet_id]: Foreman subnet ID of interface; Must be Fixnum (OPTIONAL)
:param interface[domain_id]: Foreman domain ID of interface; Must be Fixnum (OPTIONAL)
:param interface[username]: <no description>; Must be String (OPTIONAL)
:param interface[password]: <no description>; Must be String (OPTIONAL)
:param interface[provider]: Interface provider, i.e. IPMI; Must be String (OPTIONAL)
:param host_id: ID or name of host; Must be String (REQUIRED)
:param id: ID of interface; Must be an identifier, string from 1 to 128 characters containing only alphanumeric characters, space, underscore(_), hypen(-) with no leading or trailing space. (REQUIRED)

I have not tried, but something like this should be equivalent to the other request you showed:

cli.hosts.interfaces_host_id_updateinterfaces(
    host_id='341423',
    id='enp3s0f1',
    interface={
        'ip': '172.28.5.28',
        'subnet_id': '13',
        'primary': 'true',
        'managed': 'true'
    }
)