From d864d9efdc00ba81124f1d2d76cd86349b3c1b78 Mon Sep 17 00:00:00 2001 From: ertaozh Date: Wed, 14 Feb 2018 03:44:09 -0500 Subject: [PATCH] add set bmc hostname --- .../agent/hwctl/executor/openbmc_bmcconfig.py | 33 +++++++++++++++---- .../lib/python/agent/hwctl/openbmc_client.py | 9 ++++- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/xCAT-openbmc-py/lib/python/agent/hwctl/executor/openbmc_bmcconfig.py b/xCAT-openbmc-py/lib/python/agent/hwctl/executor/openbmc_bmcconfig.py index 1e19efe84..1817e50c9 100644 --- a/xCAT-openbmc-py/lib/python/agent/hwctl/executor/openbmc_bmcconfig.py +++ b/xCAT-openbmc-py/lib/python/agent/hwctl/executor/openbmc_bmcconfig.py @@ -96,7 +96,20 @@ rmdir \"/tmp/$userid\" \n") def set_ipdhcp(self, **kw): - return self.callback.info("set_ipdhcp") + node = kw['node'] + obmc = openbmc.OpenBMCRest(name=node, nodeinfo=kw['nodeinfo'], messager=self.callback, + debugmode=self.debugmode, verbose=self.verbose) + try: + obmc.login() + obmc.set_ipdhcp(key) + except (SelfServerException, SelfClientException) as e: + self.callback.info("%s: %s" % (node, e.message)) + + self.callback.info("%s: BMC Setting IP to DHCP..." % (node)) + try: + obmc.reboot_bmc() + except (SelfServerException, SelfClientException) as e: + self.callback.info("%s: %s" % (node, e.message)) def get_attributes(self, attributes, **kw): netinfo_dict={} @@ -127,18 +140,22 @@ rmdir \"/tmp/$userid\" \n") return self.callback.error("set_attributes unsupported attribute:%s" % k) if len(netinfo_dict) > 1 and (not netinfo_dict.has_key('ip') or not netinfo_dict.has_key('netmask') or not netinfo_dict.has_key('gateway')): self.callback.info("set_attributes miss either ip, netmask or gateway to set network information") + elif len(netinfo_dict) <= 1: + return else: self._set_netinfo(netinfo_dict['ip'], netinfo_dict['netmask'], netinfo_dict['gateway'], netinfo_dict['vlan']) def _set_hostname(self, hostname, **kw): + node = kw['node'] if hostname == '*': - if kw['nodeinfo']['bmc'] != kw['nodeinfo']['bmcip']: - hostname = kw['nodeinfo']['bmc'] - else: - hostname = '%s-bmc' % kw['node'] - return self.callback.info("set_hostname: %s" % hostname) - + if kw['nodeinfo']['bmc'] == kw['nodeinfo']['bmcip']: + self.callback.info("%s: set BMC ip as BMC Hostname" % node) + hostname = kw['nodeinfo']['bmc'] + self._set_apis_values("hostname", hostname, **kw) + self._get_netinfo(hostname=True, ntpserver=False, **kw) + return + def _set_apis_values(self, key, value, **kw): node = kw['node'] obmc = openbmc.OpenBMCRest(name=node, nodeinfo=kw['nodeinfo'], messager=self.callback, @@ -266,3 +283,5 @@ rmdir \"/tmp/$userid\" \n") for i in ntpserver_list: self.callback.info("%s: %s" % (node, i)) return + def get_netinfo(self, ip=False, ipsrc=False, netmask=False, gateway=False, vlan=False, hostname=False, ntpserver=True, **kw): + diff --git a/xCAT-openbmc-py/lib/python/agent/hwctl/openbmc_client.py b/xCAT-openbmc-py/lib/python/agent/hwctl/openbmc_client.py index 64d07dd9b..d8468f14a 100644 --- a/xCAT-openbmc-py/lib/python/agent/hwctl/openbmc_client.py +++ b/xCAT-openbmc-py/lib/python/agent/hwctl/openbmc_client.py @@ -143,7 +143,6 @@ FIRM_URLS = { RSPCONFIG_NETINFO_URL = { 'get_netinfo': "/network/enumerate", - 'hostname': "/network/config/attr/HostName", 'nic_ip': "/network/#NIC#/action/IP", 'vlan': "/network/action/VLAN", 'ipdhcp': "/network/action/Reset", @@ -151,6 +150,11 @@ RSPCONFIG_NETINFO_URL = { } RSPCONFIG_APIS = { + 'hostname': { + 'baseurl': "/network/config/", + 'set_url': "attr/HostName", + 'display_name': "BMC Hostname", + }, 'autoreboot' : { 'baseurl': "/control/host0/auto_reboot/", 'set_url': "attr/AutoReboot", @@ -523,6 +527,9 @@ class OpenBMCRest(object): def get_netinfo(self): return self.request('GET', RSPCONFIG_NETINFO_URL['get_netinfo'], cmd="get_netinfo") + def set_ipdhcp(self): + return self.request('PUT', RSPCONFIG_NETINFO_URL['ipdhcp'], cmd="set_bmcip_dhcp") + class OpenBMCImage(object): def __init__(self, rawid, data=None): self.id = rawid.split('/')[-1]