From 5860b3796a8eff19c9ee03744611174c6241b8cf Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Mon, 22 Jul 2019 13:42:37 -0400 Subject: [PATCH] Fallback to direct ipv4addresses manipulation A redfish implementation may forbid writing to it, however others allow only writing to it. Change-Id: If4e1f6a737cb6b1460d73cbe9faf30c18951f890 --- pyghmi/redfish/command.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/pyghmi/redfish/command.py b/pyghmi/redfish/command.py index 3508942d..df29ce1a 100644 --- a/pyghmi/redfish/command.py +++ b/pyghmi/redfish/command.py @@ -940,6 +940,7 @@ class Command(object): ipv4_gateway=None): patch = {} ipinfo = {} + dodhcp = None netmask = None if ipv4_address: if '/' in ipv4_address: @@ -953,12 +954,22 @@ class Command(object): patch['IPv4StaticAddresses'] = [ipinfo] ipinfo['Gateway'] = ipv4_gateway if ipv4_configuration.lower() == 'dhcp': + dodhcp = True patch['DHCPv4'] = {'DHCPEnabled': True} elif (ipv4_configuration == 'static' or 'IPv4StaticAddresses' in patch): + dodhcp = False patch['DHCPv4'] = {'DHCPEnabled': False} if patch: - self._do_web_request(self._bmcnicurl, patch, 'PATCH') + try: + self._do_web_request(self._bmcnicurl, patch, 'PATCH') + except exc.RedfishError as e: + patch = {'IPv4Addresses': [ipinfo]} + if dodhcp: + ipinfo['AddressOrigin'] = 'DHCP' + elif dodhcp is not None: + ipinfo['AddressOrigin'] = 'Static' + self._do_web_request(self._bmcnicurl, patch, 'PATCH') def get_net_configuration(self): netcfg = self._do_web_request(self._bmcnicurl, cache=False)