diff --git a/pyghmi/ipmi/command.py b/pyghmi/ipmi/command.py index 2a734dd9..24278b02 100644 --- a/pyghmi/ipmi/command.py +++ b/pyghmi/ipmi/command.py @@ -869,6 +869,48 @@ class Command(object): self.oem_init() self._oem.clear_system_configuration() + def set_net6_configuration(self, static_addresses=None, static_gateway=None, channel=None): + if static_addrs is None and static_gateway is None: + return + if channel is None: + channel = self.get_network_channel() + if static_addresses is not None: + i = 0 + for va in static_addresses: + if '/' in va: + va, plen = va.split('/', 1) + else: + plen = '64' + plen = int(plen) + vab = bytearray(socket.inet_pton(socket.AF_INET6, va)) + cmddata = bytearray([channel, 56, 0, 0x80]) + vab + bytearray([plen, 0]) + self.xraw_command(netfn=0xc, command=1, data=cmddata) + if static_gateway is not None: + gwb = bytearray(socket.inet_pton(socket.AF_INET6, static_gateway)) + cmddata = bytearray([channel, 65]) + gwb + self.xraw_command(netfn=0xc, command=1, data=cmddata) + + def get_net6_configuration(self, channel=None): + if channel is None: + channel = self.get_network_channel() + retdata = {} + ip6a = self.xraw_command(netfn=0xc, command=2, data=(channel, 56, 0, 0)) + ip6d = bytearray(ip6a['data']) + if ip6d[0] != 0x11: + raise Exception('Unsupported reply') + if ip6d[2] & 0x80 == 0x80: + ip6b = ip6d[3:19] + ip6addr = socket.inet_ntop(socket.AF_INET6, ip6b) + plen = ip6d[19] + retdata['static_addrs'] = ['{}/{}'.format(ip6addr, plen)] + ip6g = self.xraw_command(netfn=0xc, command=2, data=(channel, 65, 0, 0)) + ip6gd = bytearray(ip6g['data']) + if ip6gd[0] != 0x11: + raise Exception('Unsupported reply') + gwa = socket.inet_ntop(socket.AF_INET6, ip6gd[1:17]) + retdata['static_gateway'] = gwa + return retdata + def set_net_configuration(self, ipv4_address=None, ipv4_configuration=None, ipv4_gateway=None, channel=None): """Set network configuration data. @@ -883,6 +925,9 @@ class Command(object): :param ipv4_gateway: IP address of gateway to use. :param channel: LAN channel to configure, defaults to autodetect """ + if (ipv4_address is None and ipv4_configuration is None + and ipv4_gateway is None): + return if channel is None: channel = self.get_network_channel() if ipv4_configuration is not None: diff --git a/pyghmi/redfish/command.py b/pyghmi/redfish/command.py index ba05ef92..7ec2d5af 100644 --- a/pyghmi/redfish/command.py +++ b/pyghmi/redfish/command.py @@ -899,12 +899,37 @@ class Command(object): parms = {'Action': 'Bios.ResetBios'} self._do_web_request(rb, parms) + def set_net6_configuration(self, static_addresses=None, static_gateway=None, name=None): + patch = {} + if static_addresses is not None: + sa = [] + patch['IPv6StaticAddresses'] = sa + for addr in static_addresses: + if '/' in addr: + addr, plen = addr.split('/', 1) + else: + plen = '64' + sa.append({ + 'PrefixLength': int(plen), + 'Address': addr + }) + if static_gateway: + patch['IPv6StaticDefaultGateways'] = [{ + 'Address': static_gateway, + }] + if patch: + nicurl = self._get_bmc_nic_url(name) + self._do_web_request(nicurl, patch, 'PATCH') + def set_net_configuration(self, ipv4_address=None, ipv4_configuration=None, ipv4_gateway=None, name=None): patch = {} ipinfo = {} dodhcp = None netmask = None + if (ipv4_address is None and ipv4_configuration is None + and ipv4_gateway is None): + return if ipv4_address: if '/' in ipv4_address: ipv4_address, cidr = ipv4_address.split('/') @@ -918,7 +943,7 @@ class Command(object): patch['IPv4StaticAddresses'] = [ipinfo] ipinfo['Gateway'] = ipv4_gateway ipv4_configuration = 'static' - if ipv4_configuration.lower() == 'dhcp': + if ipv4_configuration and ipv4_configuration.lower() == 'dhcp': dodhcp = True patch['DHCPv4'] = {'DHCPEnabled': True} elif (ipv4_configuration == 'static' @@ -937,6 +962,21 @@ class Command(object): ipinfo['AddressOrigin'] = 'Static' self._do_web_request(nicurl, patch, 'PATCH') + def get_net6_configuration(self, name=None): + nicurl = self._get_bmc_nic_url(name) + netcfg = self._do_web_request(nicurl, cache=False) + retdata = {} + saddrs = netcfg.get('IPv6StaticAddresses', ()) + retdata['static_addrs'] = [] + for sa in saddrs: + ca = '{}/{}'.format(sa['Address'], sa['PrefixLength']) + retdata['static_addrs'].append(ca) + gws = netcfg.get('IPv6StaticDefaultGateways', None) + if gws: + for gw in gws: + retdata['static_gateway'] = gw['Address'] + return retdata + def get_net_configuration(self, name=None): nicurl = self._get_bmc_nic_url(name) netcfg = self._do_web_request(nicurl, cache=False)