2
0
mirror of https://opendev.org/x/pyghmi synced 2025-10-27 09:25:37 +00:00

Implement redfish set_net_configuration

This allows using redfish to set network parameters.

Change-Id: Icab70a377194ccc2a5e2058692e6b4a37a9057b3
This commit is contained in:
Jarrod Johnson
2019-04-10 17:12:00 -04:00
parent 9c4e520d93
commit a71076c0be

View File

@@ -116,6 +116,11 @@ def _mask_to_cidr(mask):
maskn >>= 1
return cidr
def _cidr_to_mask(cidr):
return socket.inet_ntop(
socket.AF_INET, struct.pack(
'!I', (2**32-1) ^ (2**(32-cidr)-1)))
class SensorReading(object):
def __init__(self, healthinfo):
@@ -468,8 +473,32 @@ class Command(object):
redfishsettings = {'Attributes': changeset}
self._do_web_request(self._setbiosurl, redfishsettings, 'PATCH')
def set_net_configuration(self, ipv4_address=None, ipv4_configuration=None,
ipv4_gateway=None):
patch = {}
ipinfo = {}
netmask = None
if ipv4_address:
if '/' in ipv4_address:
ipv4_address, cidr = ipv4_address.split('/')
netmask = _cidr_to_mask(int(cidr))
patch['IPv4StaticAddresses'] = [ipinfo]
ipinfo['Address'] = ipv4_address
if netmask:
ipinfo['SubnetMask'] = netmask
if ipv4_gateway:
patch['IPv4StaticAddresses'] = [ipinfo]
ipinfo['Gateway'] = ipv4_gateway
if ipv4_configuration.lower() == 'dhcp':
patch['DHCPv4'] = {'DHCPEnabled': True}
elif (ipv4_configuration == 'static' or
'IPv4StaticAddresses' in patch):
patch['DHCPv4'] = {'DHCPEnabled': False}
if patch:
self._do_web_request(self._bmcnicurl, patch, 'PATCH')
def get_net_configuration(self):
netcfg = self._do_web_request(self._bmcnicurl)
netcfg = self._do_web_request(self._bmcnicurl, cache=False)
ipv4 = netcfg.get('IPv4Addresses', {})
if not ipv4:
raise exc.PyghmiException('Unable to locate network information')