【问题标题】:Setting the mac address on a system on a cobbler server using the xmlrpc api使用 xmlrpc api 在 cobbler 服务器上的系统上设置 mac 地址
【发布时间】:2015-09-09 18:48:10
【问题描述】:

我正在尝试使用 xmlrpcapi 在我的 cobbler 服务器上设置系统的 eth0 接口的 mac 地址。

我可以设置“comment”之类的简单字段,但我似乎无法设置mac地址,可能是因为我不知道要引用的路径。所以这行得通:

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

但是如果我想设置 interfaces['eth0'][mac_address'] 我应该使用什么属性名称?

【问题讨论】:

    标签: python xmlrpcclient


    【解决方案1】:

    documentation 中找到了一个恰好显示新系统创建的示例:

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

    我仍然不确定一个通用的方法来确定各种属性的路径是什么,只是幸运地看到了这个例子

    【讨论】:

      【解决方案2】:

      在开发我们在 Wolfram 内部使用的 prov 实用程序时,我实际上不得不解决同样的问题。我不确定为什么 Cobbler 的数据表示不是双向的。我有效地做了以下事情:

      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)
      

      【讨论】:

        猜你喜欢
        • 2023-03-28
        • 1970-01-01
        • 2020-12-07
        • 2011-06-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多