1

I'm trying to set the mac address of the eth0 interface of a system on my cobbler server using the xmlrpcapi.

I can set simple fields like "comment", but I can't seem to set mac address, probably because I don't know the path to refer to. So this works:

    handle = server.get_system_handle(system, token)
    server.modify_system(handle, 'comment', 'my comment', token)
    server.save_system(handle, token)

But if I want to set interfaces['eth0'][mac_address'] what property name do I use?

kimon
  • 2,481
  • 2
  • 23
  • 33

2 Answers2

0

Found an example in the documentation that happens to show the creation of a new system:

    server.modify_system(handle, 'modify_interface', {
            'macaddress-eth0': args.mac
        }, token)

I'm still not sure of a generic way though to determine what the path is to various properties, just got lucky with this example

kimon
  • 2,481
  • 2
  • 23
  • 33
0

I actually had to work around this same issue when developing the prov utility we use internally at Wolfram. I'm not sure why Cobbler's data representation isn't bidirectional. I effectively do the following:

system_name = '(something)' # The name of the system.
system_data = {} # The desired final state of the system data here.

# Pull out the interfaces dictionary.
if 'interfaces' in system_data:
  interfaces = system_data.pop('interfaces')
else:
  interfaces = {}

# Apply the non-interfaces data.
cobbler_server.xapi_object_edit('systems', system_name, 'edit', system_data, self.token)

# Apply interface-specific data.
handle = cobbler_server.get_system_handle(system_name, self.token)
ninterfaces = {}
for iname, ival in interfaces.items():
  for k, v in ival.items():
    if k in ['dns_name', 'ip_address', 'mac_address']:
      if v:
        ninterfaces[k.replace('_', '') + '-' + iname] = v
      else:
        ninterfaces[k + '-' + iname] = v
cobbler_server.modify_system(
  handle,
  'modify_interface',
  ninterfaces,
  self.token
)

cobbler_server.save_system(handle, self.token)
Harrison Totty
  • 192
  • 1
  • 1
  • 15