# Copyright 2013 IBM Corporation # Copyright 2015-2017 Lenovo # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """This represents the low layer message framing portion of IPMI""" from itertools import chain import os import socket import struct import threading import asyncio import aiohmi.constants as const import aiohmi.exceptions as exc import aiohmi.ipmi.events as sel import aiohmi.ipmi.fru as fru import aiohmi.ipmi.oem.generic as genericoem from aiohmi.ipmi.oem.lookup import get_oem_handler import aiohmi.ipmi.private.util as util from aiohmi.ipmi import sdr try: from aiohmi.ipmi.private import session except ImportError: session = None try: from aiohmi.ipmi.private import localsession except ImportError: localsession = None try: range = xrange except NameError: pass try: buffer except NameError: buffer = memoryview boot_devices = { 'net': 4, 'network': 4, 'pxe': 4, 'hd': 8, 'safe': 0xc, 'cd': 0x14, 'cdrom': 0x14, 'optical': 0x14, 'dvd': 0x14, 'floppy': 0x3c, 'usb': 0x3c, 'default': 0x0, 'setup': 0x18, 'bios': 0x18, 'f1': 0x18, 1: 'network', 2: 'hd', 3: 'safe', 5: 'optical', 6: 'setup', 15: 'floppy', 0: 'default' } power_states = { "off": 0, "on": 1, "reset": 3, "diag": 4, "softoff": 5, "shutdown": 5, # NOTE(jbjohnso): -1 is not a valid direct boot state, # but here for convenience of 'in' statement "boot": -1, } def select_simplesession(): global session import aiohmi.ipmi.private.simplesession as session def _mask_to_cidr(mask): maskn = struct.unpack_from('>I', mask)[0] cidr = 32 while maskn & 0b1 == 0 and cidr > 0: cidr -= 1 maskn >>= 1 return cidr def _cidr_to_mask(prefix): return struct.pack('>I', 2 ** prefix - 1 << (32 - prefix)) class Housekeeper(threading.Thread): """A Maintenance thread for housekeeping Long lived use of aiohmi may warrant some recurring asynchronous behavior. This stock thread provides a simple minimal context for these housekeeping tasks to run in. To use, do 'aiohmi.ipmi.command.Maintenance().start()' and from that point forward, aiohmi should execute any needed ongoing tasks automatically as needed. This is an alternative to calling wait_for_rsp or eventloop in a thread of the callers design. """ def run(self): Command.eventloop() class Command(object): """Send IPMI commands to BMCs. This object represents a persistent session to an IPMI device (bmc) and allows the caller to reuse a single session to issue multiple commands. This class can be used in a synchronous (wait for answer and return) or asynchronous fashion (return immediately and provide responses by callbacks). Synchronous mode is the default behavior. For asynchronous mode, simply pass in a callback function. It is recommended to pass in an instance method to callback and ignore the callback_args parameter. However, callback_args can optionally be populated if desired. :param bmc: hostname or ip address of the BMC (default is local) :param userid: username to use to connect (default to no user) :param password: password to connect to the BMC (defaults to no password) :param onlogon: function to run when logon completes in an asynchronous fashion. This will result in a greenthread behavior. :param kg: Optional parameter to use if BMC has a particular Kg configured :param verifycallback: For OEM extensions that use HTTPS, this function will be used to evaluate the certificate. :param keepalive: If False, then an idle connection will logout rather than keepalive unless held open by console or ongoing activity. """ @classmethod async def create(cls, bmc=None, userid=None, password=None, port=623, kg=None, privlevel=None, verifycallback=None, keepalive=True, **kwargs): self = cls() # TODO(jbjohnso): accept tuples and lists of each parameter for mass # operations without pushing the async complexities up the stack self.bmc = bmc self._sdrcachedir = None self._sdr = None self._oem = None self._oemknown = False self._netchannel = None self._ipv6support = None self.certverify = verifycallback self.kwargs = kwargs if bmc is None: self.ipmi_session = localsession.Session() else: self.ipmi_session = await session.Session(bmc=self.bmc, userid=userid, password=password, port=port, kg=kg, privlevel=privlevel, keepalive=keepalive) # induce one iteration of the loop, now that we would be # prepared for it in theory await session.Session.wait_for_rsp(0) return self def set_sdr_cachedir(self, path): """Register use of a directory for SDR cache. Takes the given directory and uses it to persist SDR cache run to run. This can greatly improve performance across runs. :param path: :return: """ self._sdrcachedir = path def register_key_handler(self, callback, type='tls'): """Assign a verification handler for a public key When the library attempts to communicate with the management target using a non-IPMI protocol, it will try to verify a key. This allows a caller to register a key handler for accepting or rejecting a public key/certificate. The callback will be passed the peer public key or certificate. :param callback: The function to call with public key/certificate :param type: Whether the callback is meant to handle 'tls' or 'ssh', defaults to 'tls' """ if type == 'tls': self.certverify = callback @classmethod async def eventloop(cls): while True: await session.Session.wait_for_rsp() @classmethod async def wait_for_rsp(cls, timeout): """Delay for no longer than timeout for next response. This acts like a sleep that exits on activity. :param timeout: Maximum number of seconds before returning """ return await session.Session.wait_for_rsp(timeout=timeout) async def _get_device_id(self): response = await self.raw_command(netfn=0x06, command=0x01) return { 'device_id': response['data'][0], 'device_revision': response['data'][1] & 0b1111, 'manufacturer_id': struct.unpack( '> 4 & 0b1111, response['data'][3] & 0b1111) } async def oem_init(self): """Initialize the command object for OEM capabilities A number of capabilities are either totally OEM defined or else augmented somehow by knowledge of the OEM. This method does an interrogation to identify the OEM. """ if self._oemknown: return if self.bmc is None: self._oem = await genericoem.OEMHandler.create(None, None) self._oemknown = True return self._oem, self._oemknown = await get_oem_handler(await self._get_device_id(), self) async def get_bootdev(self): """Get current boot device override information. Provides the current requested boot device. Be aware that not all IPMI devices support this. Even in BMCs that claim to, occasionally the BIOS or UEFI fail to honor it. This is usually only applicable to the next reboot. :raises: IpmiException on an error. :returns: dict --The response will be provided in the return as a dict """ response = await self.raw_command(netfn=0, command=9, data=(5, 0, 0)) # interpret response per 'get system boot options' # this should only be invoked for get system boot option complying to # ipmi spec and targeting the 'boot flags' parameter assert (response['command'] == 9 and response['netfn'] == 1 and response['data'][0] == 1 and (response['data'][1] & 0b1111111) == 5) if (response['data'][1] & 0b10000000 or not response['data'][2] & 0b10000000): return {'bootdev': 'default', 'persistent': True} else: # will consult data2 of the boot flags parameter for the data persistent = False uefimode = False if response['data'][2] & 0b1000000: persistent = True if response['data'][2] & 0b100000: uefimode = True bootnum = (response['data'][3] & 0b111100) >> 2 bootdev = boot_devices.get(bootnum) if bootdev: return {'bootdev': bootdev, 'persistent': persistent, 'uefimode': uefimode} else: return {'bootdev': bootnum, 'persistent': persistent, 'uefimode': uefimode} async def reseat_bay(self, bay): """Request the reseat of a bay Request the enclosure manager to reseat the system in a particular bay. :param bay: The bay identifier to reseat :return: """ await self.oem_init() await self._oem.reseat_bay(bay) async def set_power(self, powerstate, wait=False, bridge_request=None): """Request power state change (helper) :param powerstate: * on -- Request system turn on * off -- Request system turn off without waiting for OS to shutdown * shutdown -- Have system request OS proper shutdown * reset -- Request system reset without waiting for OS * boot -- If system is off, then 'on', else 'reset' :param wait: If True, do not return until system actually completes requested state change for 300 seconds. If a non-zero number, adjust the wait time to the requested number of seconds :param bridge_request: The target slave address and channel number for the bridge request. :raises: IpmiException on an error :returns: dict -- A dict describing the response retrieved """ await self.oem_init() if hasattr(self._oem, 'set_power'): return self._oem.set_power(powerstate, bridge_request=bridge_request) if hasattr(self._oem, 'process_power_state'): powerstate = self._oem.process_power_state( powerstate, bridge_request=bridge_request) if powerstate not in power_states: raise exc.InvalidParameterValue( "Unknown power state %s requested" % powerstate) newpowerstate = powerstate oldpowerstate = await self._get_power_state(bridge_request=bridge_request) if oldpowerstate == newpowerstate: return {'powerstate': oldpowerstate} if newpowerstate == 'boot': newpowerstate = 'on' if oldpowerstate == 'off' else 'reset' response = await self.raw_command( netfn=0, command=2, data=[power_states[newpowerstate]], bridge_request=bridge_request) lastresponse = {'pendingpowerstate': newpowerstate} waitattempts = 300 if not isinstance(wait, bool): waitattempts = wait if wait and newpowerstate in ('on', 'off', 'shutdown', 'softoff'): if newpowerstate in ('softoff', 'shutdown'): waitpowerstate = 'off' else: waitpowerstate = newpowerstate currpowerstate = None while currpowerstate != waitpowerstate and waitattempts > 0: await asyncio.sleep(1) currpowerstate = await self._get_power_state( bridge_request=bridge_request) waitattempts -= 1 if currpowerstate != waitpowerstate: raise exc.IpmiException( "System did not accomplish power state change") return {'powerstate': currpowerstate} else: return lastresponse async def _get_power_state(self, bridge_request=None): response = await self.raw_command(netfn=0, command=1, bridge_request=bridge_request) assert (response['command'] == 1 and response['netfn'] == 1) curr_power_state = 'on' if (response['data'][0] & 1) else 'off' return curr_power_state async def get_video_launchdata(self): """Get data required to launch a remote video session to target. This is a highly proprietary scenario, the return data may vary greatly host to host. The return should be a dict describing the type of data and the data. For example {'jnlp': jnlpstring} """ await self.oem_init() return await self._oem.get_video_launchdata() async def reset_bmc(self): """Do a cold reset in BMC""" response = await self.raw_command(netfn=6, command=2, retry=False) if response and 'error' in response: raise exc.IpmiException(response['error']) async def set_bootdev(self, bootdev, persist=False, uefiboot=False): """Set boot device to use on next reboot (helper) :param bootdev: *network -- Request network boot *hd -- Boot from hard drive *safe -- Boot from hard drive, requesting 'safe mode' *optical -- boot from CD/DVD/BD drive *setup -- Boot into setup utility *default -- remove any IPMI directed boot device request :param persist: If true, ask that system firmware use this device beyond next boot. Be aware many systems do not honor this :param uefiboot: If true, request UEFI boot explicitly. Strictly speaking, the spec sugests that if not set, the system should BIOS boot and offers no "don't care" option. In practice, this flag not being set does not preclude UEFI boot on any system I've encountered. :raises: IpmiException on an error. :returns: dict or True -- If callback is not provided, the response """ if bootdev not in boot_devices: return {'error': "Unknown bootdevice %s requested" % bootdev} bootdevnum = boot_devices[bootdev] # first, we disable timer by way of set system boot options, # then move on to set chassis capabilities # Set System Boot Options is netfn=0, command=8, data response = await self.raw_command(netfn=0, command=8, data=(3, 8)) if 'error' in response: raise exc.IpmiException(response['error']) bootflags = 0x80 if uefiboot: bootflags |= 1 << 5 if persist: bootflags |= 1 << 6 if bootdevnum == 0: bootflags = 0 data = (5, bootflags, bootdevnum, 0, 0, 0) response = await self.raw_command(netfn=0, command=8, data=data) if 'error' in response: raise exc.IpmiException(response['error']) return {'bootdev': bootdev} async def xraw_command(self, **kwargs): raise Exception("Don't use this anymore") return await self.raw_command(**kwargs) async def raw_command(self, netfn, command, bridge_request=(), data=(), retry=True, timeout=None, rslun=0): """Send raw ipmi command to BMC, raising exception on error This is identical to raw_command, except it raises exceptions on IPMI errors and returns data as a buffer. This is the recommend function to use. The response['data'] being a buffer allows traditional indexed access as well as works nicely with struct.unpack_from when certain data is coming back. :param netfn: Net function number :param command: Command value :param bridge_request: The target slave address and channel number for the bridge request. :param data: Command data as a tuple or list :param retry: Whether to retry this particular payload or not, defaults to true. :param timeout: A custom time to wait for initial reply, useful for a slow command. This may interfere with retry logic. :returns: dict -- The response from IPMI device """ rsp = await self.ipmi_session.raw_command(netfn=netfn, command=command, bridge_request=bridge_request, data=data, retry=retry, timeout=timeout, rslun=rslun) if rsp and 'error' in rsp: raise exc.IpmiException(rsp['error'], rsp['code']) if rsp and 'data' in rsp: rsp['data'] = buffer(rsp['data']) return rsp async def get_diagnostic_data(self, savefile, progress=None, autosuffix=False): if os.path.exists(savefile) and not os.path.isdir(savefile): raise exc.InvalidParameterValue( 'Not allowed to overwrite existing file: {0}'.format( savefile)) await self.oem_init() return await self._oem.get_diagnostic_data(savefile, progress, autosuffix) async def get_description(self): """Get physical attributes for the system, e.g. for GUI use :returns: dict -- dict containing attributes, 'height' is for how many U tall, 'slot' for what slot in a blade enclosure or 0 if not blade, for example. """ await self.oem_init() return await self._oem.get_description() async def oldraw_command(self, netfn, command, bridge_request=(), data=(), retry=True, timeout=None, rslun=0): """Send raw ipmi command to BMC This allows arbitrary IPMI bytes to be issued. This is commonly used for certain vendor specific commands. Example: ipmicmd.raw_command(netfn=0,command=4,data=(5)) :param netfn: Net function number :param command: Command value :param bridge_request: The target slave address and channel number for the bridge request. :param data: Command data as a tuple or list :param retry: Whether or not to retry command if no response received. Defaults to True :param timeout: A custom amount of time to wait for initial reply :returns: dict -- The response from IPMI device """ rsp = await self.ipmi_session.raw_command(netfn=netfn, command=command, bridge_request=bridge_request, data=data, retry=retry, timeout=timeout, rslun=rslun) return rsp async def get_power(self, bridge_request=None): """Get current power state of the managed system The response, if successful, should contain 'powerstate' key and either 'on' or 'off' to indicate current state. :param bridge_request: The target slave address and channel number for the bridge request. :returns: dict -- {'powerstate': value} """ await self.oem_init() if hasattr(self._oem, 'get_power'): return {'powerstate': await self._oem.get_power( bridge_request=bridge_request)} return {'powerstate': await self._get_power_state( bridge_request=bridge_request)} async def set_identify(self, on=True, duration=None, blink=False): """Request identify light Request the identify light to turn off, on for a duration, or on indefinitely. Other than error exceptions, :param on: Set to True to force on or False to force off :param duration: Set if wanting to request turn on for a duration rather than indefinitely on """ await self.oem_init() try: await self._oem.set_identify(on, duration, blink) return except exc.BypassGenericBehavior: return except exc.UnsupportedFunctionality: pass if blink: raise exc.IpmiException('Blink not supported with generic IPMI') if duration is not None: duration = int(duration) if duration > 255: duration = 255 if duration < 0: duration = 0 response = await self.raw_command(netfn=0, command=4, data=[duration]) return forceon = 0 if on: forceon = 1 if self.ipmi_session.ipmiversion < 2.0: # ipmi 1.5 made due with just one byte, make best effort # to imitate indefinite as close as possible identifydata = [255 * forceon] else: identifydata = [0, forceon] response = await self.raw_command(netfn=0, command=4, data=identifydata) async def init_sdr(self): """Initialize SDR Do the appropriate action to have a relevant sensor description repository for the current management controller """ # For now, return current sdr if it exists and still connected # future, check SDR timestamp for continued relevance # further future, optionally support a cache directory/file # to store cached copies for given device id, product id, mfg id, # sdr timestamp, our data version revision, aux firmware revision, # and oem defined field await self.oem_init() if self._sdr is None: if hasattr(self._oem, 'init_sdr'): self._sdr = await self._oem.init_sdr() else: self._sdr = sdr.SDR(self, self._sdrcachedir) await self._sdr.initialize() return self._sdr async def get_event_constants(self): await self.oem_init() return await self._oem.get_oem_event_const() async def get_event_log(self, clear=False): """Retrieve the log of events, optionally clearing The contents of the SEL are returned as an iterable. Timestamps are given as local time, ISO 8601 (whether the target has an accurate clock or not). Timestamps may be omitted for events that cannot be given a timestamp, leaving only the raw timecode to provide relative time information. clear set to true will result in the log being cleared as it is returned. This allows an atomic fetch and clear behavior so that no log entries will be lost between the fetch and clear actions. There is no 'clear_event_log' function to encourage users to create code that is not at risk for losing events. :param clear: Whether to remove the SEL entries from the target BMC """ await self.oem_init() evthdlr = await sel.EventHandler.create(await self.init_sdr(), self) async for logent in evthdlr.fetch_sel(self, clear): yield logent async def decode_pet(self, specifictrap, petdata): """Decode PET to an event In IPMI, the alert format are PET alerts. It is a particular set of data put into an SNMPv1 trap and sent. It bears no small resemblence to the SEL entries. This function takes data that would have been received by an SNMP trap handler, and provides an event decode, similar to one entry of get_event_log. :param specifictrap: The specific trap, as either a bytearray or int :param petdata: An iterable of the octet data of varbind for 1.3.6.1.4.1.3183.1.1.1 :returns: A dict event similar to one iteration of get_event_log """ await self.oem_init() evthdlr = await sel.EventHandler.create(await self.init_sdr(), self) return await evthdlr.decode_pet(specifictrap, petdata) async def get_ikvm_methods(self): await self.oem_init() return await self._oem.get_ikvm_methods() async def get_ikvm_launchdata(self): await self.oem_init() return await self._oem.get_ikvm_launchdata() async def get_inventory_descriptions(self): """Retrieve list of things that could be inventoried This permits a caller to examine the available items without actually causing the inventory data to be gathered. It returns an iterable of string descriptions """ yield "System" await self.init_sdr() for fruid in sorted(self._sdr.fru): yield self._sdr.fru[fruid].fru_name await self.oem_init() async for compname in self._oem.get_oem_inventory_descriptions(): yield compname async def get_inventory_of_component(self, component): """Retrieve inventory of a component Retrieve detailed inventory information for only the requested component. """ await self.oem_init() if component == 'System': return await self._get_zero_fru() await self.init_sdr() for fruid in self._sdr.fru: if self._sdr.fru[fruid].fru_name == component: return self._oem.process_fru(fru.FRU( ipmicmd=self, fruid=fruid, sdr=self._sdr.fru[fruid]).info, component) return await self._oem.get_inventory_of_component(component) async def _get_zero_fru(self): # Add some fields returned by get device ID command to FRU 0 # Also rename them to something more in line with FRU 0 field naming # standards device_id = await self._get_device_id() device_id['Device ID'] = device_id.pop('device_id') device_id['Device Revision'] = device_id.pop('device_revision') device_id['Manufacturer ID'] = device_id.pop('manufacturer_id') device_id['Product ID'] = device_id.pop('product_id') tfru = fru.FRU(ipmicmd=self, fruid=0) await tfru.initialize() zerofru = tfru.info if zerofru is None: zerofru = {} zerofru.update(device_id) zerofru = await self._oem.process_zero_fru(zerofru) # If uuid is not returned in OEM processing, # then it is expected that a manufacturer matches SMBIOS to IPMI # get system uuid return data. if 'UUID' not in zerofru: guiddata = await self.raw_command(netfn=6, command=0x37) zerofru['UUID'] = util.\ decode_wireformat_uuid(guiddata['data']) return zerofru async def get_inventory(self): """Retrieve inventory of system Retrieve inventory of the targeted system. This frequently includes serial numbers, sometimes hardware addresses, sometimes memory modules This function will retrieve whatever the underlying platform provides and apply some structure. Iterating over the return yields tuples of a name for the inventoried item and dictionary of descriptions or None for items not present. """ await self.oem_init() yield ("System", await self._get_zero_fru()) await self.init_sdr() for fruid in sorted(self._sdr.fru): tfru = fru.FRU(ipmicmd=self, fruid=fruid, sdr=self._sdr.fru[fruid]) await tfru.initialize() fruinf = tfru.info if fruinf is not None: fruinf = await self._oem.process_fru(fruinf, self._sdr.fru[fruid].fru_name) # check the fruinf again as the oem process may return None if fruinf: yield (self._sdr.fru[fruid].fru_name, fruinf) async for componentpair in self._oem.get_oem_inventory(): yield componentpair async def get_leds(self): """Get LED status information This provides a detailed view of the LEDs of the managed system. """ await self.oem_init() return await self._oem.get_leds() async def get_ntp_enabled(self): await self.oem_init() return await self._oem.get_ntp_enabled() async def set_ntp_enabled(self, enable): await self.oem_init() return await self._oem.set_ntp_enabled(enable) async def get_ntp_servers(self): await self.oem_init() return await self._oem.get_ntp_servers() async def set_ntp_server(self, server, index=0): await self.oem_init() return await self._oem.set_ntp_server(server, index) async def get_health(self): """Summarize health of managed system This provides a summary of the health of the managed system. It additionally provides an iterable list of reasons for warning, critical, or failed assessments. """ summary = {'badreadings': [], 'health': const.Health.Ok} fallbackreadings = [] try: await self.oem_init() fallbackreadings = await self._oem.get_health(summary) async for reading in self.get_sensor_data(): if reading.health != const.Health.Ok: summary['health'] |= reading.health summary['badreadings'].append(reading) except exc.BypassGenericBehavior: pass if not summary['badreadings']: summary['badreadings'] = fallbackreadings return summary async def get_system_power_watts(self): await self.oem_init() return await self._oem.get_system_power_watts(self) async def get_inlet_temperature(self): await self.oem_init() return await self._oem.get_inlet_temperature(self) async def get_average_processor_temperature(self): await self.oem_init() return await self._oem.get_average_processor_temperature(self) async def get_sensor_reading(self, sensorname): """Get a sensor reading by name Returns a single decoded sensor reading per the name passed in :param sensorname: Name of the desired sensor :returns: sdr.SensorReading object """ await self.init_sdr() for sensor in self._sdr.get_sensor_numbers(): if self._sdr.sensors[sensor].name == sensorname: currsensor = self._sdr.sensors[sensor] rsp = await self.raw_command(command=0x2d, netfn=4, rslun=currsensor.sensor_lun, data=(currsensor.sensor_number,)) return self._sdr.sensors[sensor].decode_sensor_reading( self, rsp['data']) await self.oem_init() return await self._oem.get_sensor_reading(sensorname) async def _fetch_lancfg_param(self, channel, param, prefixlen=False): """Internal helper for fetching lan cfg parameters If the parameter revison != 0x11, bail. Further, if 4 bytes, return string with ipv4. If 6 bytes, colon delimited hex (mac address). If one byte, return the int value """ fetchcmd = bytearray((channel, param, 0, 0)) try: fetched = await self.oldraw_command(0xc, 2, data=fetchcmd) except exc.IpmiException as ie: if ie.ipmicode == 0x80: return None raise fetchdata = fetched['data'] if bytearray(fetchdata)[0] != 17: return None if param == 0x14: vlaninfo = struct.unpack('BB', currpol['data'][2:4]) if not polidx & 0b1000: if availpolnum is None: availpolnum = polnum continue if chandest == desiredchandest: return True # If chandest did not equal desiredchandest ever, we need to use a slot if availpolnum is None: raise Exception("No available alert policy entry") # 24 = 1 << 4 | 8 # 1 == set to which this rule belongs # 8 == 0b1000, in other words, enable this policy, always send to # indicated destination await self.raw_command(netfn=4, command=0x12, data=(9, availpolnum, 24, desiredchandest, 0)) async def get_alert_community(self, channel=None): """Get the current community string for alerts Returns the community string that will be in SNMP traps from this BMC :param channel: The channel to get configuration for, autodetect by default :returns: The community string """ if channel is None: channel = await self.get_network_channel() rsp = await self.raw_command(netfn=0xc, command=2, data=(channel, 16, 0, 0)) return rsp['data'][1:].partition('\x00')[0] async def _supports_standard_ipv6(self): # Supports the *standard* ipv6 commands for various things # used to internally steer some commands to standard or OEM # handler of commands lanchan = await self.get_network_channel() if self._ipv6support is None: rsp = await self.raw_command(netfn=0xc, command=0x2, data=(2, lanchan, 0x32, 0, 0)) self._ipv6support = rsp['code'] == 0 return self._ipv6support async def set_alert_destination(self, ip=None, acknowledge_required=None, acknowledge_timeout=None, retries=None, destination=0, channel=None): """Configure one or more parameters of an alert destination If any parameter is 'None' (default), that parameter is left unchanged. Otherwise, all given parameters are set by this command. :param ip: IP address of the destination. It is currently expected that the calling code will handle any name lookup and present this data as IP address. :param acknowledge_required: Whether or not the target should expect an acknowledgement from this alert target. :param acknowledge_timeout: Time to wait for acknowledgement if enabled :param retries: How many times to attempt transmit of an alert. :param destination: Destination index, defaults to 0. :param channel: The channel to configure the alert on. Defaults to current """ await self.oem_init() if hasattr(self._oem, 'set_alert_destination'): await self._oem.set_alert_destination(ip) return if channel is None: channel = await self.get_network_channel() if (acknowledge_required is not None or retries is not None or acknowledge_timeout is not None): currtype = await self.raw_command(netfn=0xc, command=2, data=( channel, 18, destination, 0)) if currtype['data'][0] != b'\x11': raise exc.PyghmiException("Unknown parameter format") currtype = bytearray(currtype['data'][1:]) if acknowledge_required is not None: if acknowledge_required: currtype[1] |= 0b10000000 else: currtype[1] &= 0b1111111 # set PET trap destination currtype[1] &= 0b1111000 if acknowledge_timeout is not None: currtype[2] = acknowledge_timeout if retries is not None: currtype[3] = retries destreq = bytearray((channel, 18)) destreq.extend(currtype) await self.raw_command(netfn=0xc, command=1, data=destreq) if ip is not None: destdata = bytearray((channel, 19, destination)) try: parsedip = socket.inet_pton(socket.AF_INET, ip) destdata.extend((0, 0)) destdata.extend(parsedip) destdata.extend('\x00\x00\x00\x00\x00\x00') except socket.error: parsedip = socket.inet_pton(socket.AF_INET6, ip) destdata.append(0b10000000) destdata.extend(parsedip) await self.raw_command(netfn=0xc, command=1, data=destdata) if not ip == '0.0.0.0': await self._assure_alert_policy(channel, destination) async def get_hostname(self): """Get the hostname used by the BMC in various contexts This can vary somewhat in interpretation, but generally speaking this should be the name that shows up on UIs and in DHCP requests and DNS registration requests, as applicable. :return: current hostname """ await self.oem_init() try: return await self._oem.get_hostname() except exc.UnsupportedFunctionality: # Use the DCMI MCI field as a fallback, since it's the closest # thing in the IPMI Spec for this return await self.get_mci() async def get_mci(self): """Set the management controller identifier. Try the OEM command first,if False, then set it per DCMI specification :returns: The identifier as a string """ await self.oem_init() identifier = await self._oem.get_oem_identifier() if identifier: return identifier return await self._chunkwise_dcmi_fetch(9) async def set_hostname(self, hostname): """Set the hostname to be used by the BMC in various contexts. See get_hostname for details :param hostname: The hostname to set :return: Nothing """ await self.oem_init() try: return await self._oem.set_hostname(hostname) except exc.UnsupportedFunctionality: return await self.set_mci(hostname) async def set_mci(self, mci): """Set the management controller identifier. Try the OEM command first, if False, then set it per DCMI specification """ await self.oem_init() if not isinstance(mci, bytes): mci = mci.encode('utf8') ret = await self._oem.set_oem_identifier(mci) if ret: return return await self._chunkwise_dcmi_set(0xa, mci + b'\x00') async def get_asset_tag(self): """Get the system asset tag, per DCMI specification :returns: The asset tag """ await self.oem_init() if hasattr(self._oem, 'get_asset_tag'): return await self._oem.get_asset_tag() return await self._chunkwise_dcmi_fetch(6) async def set_asset_tag(self, tag): """Set the asset tag value """ await self.oem_init() if hasattr(self._oem, 'set_asset_tag'): return await self._oem.set_asset_tag(tag) return await self._chunkwise_dcmi_set(8, tag) async def _chunkwise_dcmi_fetch(self, command): szdata = await self.raw_command( netfn=0x2c, command=command, data=(0xdc, 0, 0)) totalsize = bytearray(szdata['data'])[1] chksize = 0xf offset = 0 retstr = b'' while offset < totalsize: if (offset + chksize) > totalsize: chksize = totalsize - offset chk = await self.raw_command( netfn=0x2c, command=command, data=(0xdc, offset, chksize)) retstr += chk['data'][2:] offset += chksize if not isinstance(retstr, str): retstr = retstr.decode('utf-8') return retstr async def _chunkwise_dcmi_set(self, command, data): chunks = [data[i:i + 15] for i in range(0, len(data), 15)] offset = 0 for chunk in chunks: chunk = bytearray(chunk) cmddata = bytearray((0xdc, offset, len(chunk))) cmddata += chunk # set offset, otherwise the last setting will override # the previous setting offset += len(chunk) await self.raw_command(netfn=0x2c, command=command, data=cmddata) async def set_channel_access(self, channel=None, access_update_mode='non_volatile', alerting=False, per_msg_auth=False, user_level_auth=False, access_mode='always', privilege_update_mode='non_volatile', privilege_level='administrator'): """Set channel access :param channel: number [1:7] :param access_update_mode: dont_change = don't set or change Channel Access non_volatile = set non-volatile Channel Access volatile = set volatile (active) setting of Channel Access :param alerting: PEF Alerting Enable/Disable True = enable PEF Alerting False = disable PEF Alerting on this channel (Alert Immediate command can still be used to generate alerts) :param per_msg_auth: Per-message Authentication True = enable False = disable Per-message Authentication. [Authentication required to activate any session on this channel, but authentication not used on subsequent packets for the session.] :param user_level_auth: User Level Authentication Enable/Disable. True = enable User Level Authentication. All User Level commands are to be authenticated per the Authentication Type that was negotiated when the session was activated. False = disable User Level Authentication. Allow User Level commands to be executed without being authenticated. If the option to disable User Level Command authentication is accepted, the BMC will accept packets with Authentication Type set to None if they contain user level commands. For outgoing packets, the BMC returns responses with the same Authentication Type that was used for the request. :param access_mode: Access Mode for IPMI messaging (PEF Alerting is enabled/disabled separately from IPMI messaging) disabled = disabled for IPMI messaging pre_boot = pre-boot only channel only available when system is in a powered down state or in BIOS prior to start of boot. always = channel always available regardless of system mode. BIOS typically dedicates the serial connection to the BMC. shared = same as always available, but BIOS typically leaves the serial port available for software use. :param privilege_update_mode: Channel Privilege Level Limit. This value sets the maximum privilege level that can be accepted on the specified channel. dont_change = don't set or change channel Privilege Level Limit non_volatile = non-volatile Privilege Level Limit according volatile = volatile setting of Privilege Level Limit :param privilege_level: Channel Privilege Level Limit * reserved = unused * callback * user * operator * administrator * proprietary = used by OEM """ if channel is None: channel = await self.get_network_channel() data = [] data.append(channel & 0b00001111) access_update_modes = { 'dont_change': 0, 'non_volatile': 1, 'volatile': 2, # 'reserved': 3 } b = 0 b |= (access_update_modes[access_update_mode] << 6) & 0b11000000 if alerting: b |= 0b00100000 if per_msg_auth: b |= 0b00010000 if user_level_auth: b |= 0b00001000 access_modes = { 'disabled': 0, 'pre_boot': 1, 'always': 2, 'shared': 3, } b |= access_modes[access_mode] & 0b00000111 data.append(b) b = 0 privilege_update_modes = { 'dont_change': 0, 'non_volatile': 1, 'volatile': 2, # 'reserved': 3 } b |= (privilege_update_modes[privilege_update_mode] << 6) & 0b11000000 privilege_levels = { 'reserved': 0, 'callback': 1, 'user': 2, 'operator': 3, 'administrator': 4, 'proprietary': 5, # 'no_access': 0x0F, } b |= privilege_levels[privilege_level] & 0b00000111 data.append(b) response = self.raw_command(netfn=0x06, command=0x40, data=data) if 'error' in response: raise Exception(response['error']) return True async def get_channel_access(self, channel=None, read_mode='volatile'): """Get channel access :param channel: number [1:7] :param read_mode: non_volatile = get non-volatile Channel Access volatile = get present volatile (active) setting of Channel Access :return: A Python dict with the following keys/values: { - alerting: - per_msg_auth: - user_level_auth: - access_mode:{ 0: 'disabled', 1: 'pre_boot', 2: 'always', 3: 'shared' } - privilege_level: { 1: 'callback', 2: 'user', 3: 'operator', 4: 'administrator', 5: 'proprietary', } } """ if channel is None: channel = await self.get_network_channel() data = [] data.append(channel & 0b00001111) b = 0 read_modes = { 'non_volatile': 1, 'volatile': 2, } b |= (read_modes[read_mode] << 6) & 0b11000000 data.append(b) response = await self.raw_command(netfn=0x06, command=0x41, data=data) if 'error' in response: raise Exception(response['error']) data = response['data'] if len(data) != 2: raise Exception('expecting 2 data bytes') r = {} r['alerting'] = data[0] & 0b10000000 > 0 r['per_msg_auth'] = data[0] & 0b01000000 > 0 r['user_level_auth'] = data[0] & 0b00100000 > 0 access_modes = { 0: 'disabled', 1: 'pre_boot', 2: 'always', 3: 'shared' } r['access_mode'] = access_modes[data[0] & 0b00000011] privilege_levels = { 0: 'reserved', 1: 'callback', 2: 'user', 3: 'operator', 4: 'administrator', 5: 'proprietary', # 0x0F: 'no_access' } r['privilege_level'] = privilege_levels[data[1] & 0b00001111] return r async def get_screenshot(self, outfile): await self.oem_init() return await self._oem.get_screenshot(outfile) async def get_channel_info(self, channel=None): """Get channel info :param channel: number [1:7] :return: session_support: no_session: channel is session-less single: channel is single-session multi: channel is multi-session auto: channel is session-based (channel could alternate between single- and multi-session operation, as can occur with a serial/modem channel that supports connection mode auto-detect) """ if channel is None: channel = await self.get_network_channel() data = [] data.append(channel & 0b00001111) response = await self.raw_command(netfn=0x06, command=0x42, data=data) if 'error' in response: raise Exception(response['error']) data = response['data'] if len(data) != 9: raise Exception('expecting 10 data bytes got: {0}'.format(data)) r = {} r['Actual channel'] = data[0] & 0b00000111 channel_medium_types = { 0: 'reserved', 1: 'IPMB', 2: 'ICMB v1.0', 3: 'ICMB v0.9', 4: '802.3 LAN', 5: 'Asynch. Serial/Modem (RS-232)', 6: 'Other LAN', 7: 'PCI SMBus', 8: 'SMBus v1.0/1.1', 9: 'SMBus v2.0', 0x0a: 'reserved for USB 1.x', 0x0b: 'reserved for USB 2.x', 0x0c: 'System Interface (KCS, SMIC, or BT)', # 60h-7Fh: OEM # all other reserved } t = data[1] & 0b01111111 if t in channel_medium_types: r['Channel Medium type'] = channel_medium_types[t] else: r['Channel Medium type'] = 'OEM {:02X}'.format(t) r['5-bit Channel IPMI Messaging Protocol Type'] = data[2] & 0b00001111 session_supports = { 0: 'no_session', 1: 'single', 2: 'multi', 3: 'auto' } r['session_support'] = session_supports[(data[3] & 0b11000000) >> 6] r['active_session_count'] = data[3] & 0b00111111 r['Vendor ID'] = [data[4], data[5], data[6]] r['Auxiliary Channel Info'] = [data[7], data[8]] return r async def set_user_access(self, uid, channel=None, callback=False, link_auth=True, ipmi_msg=True, privilege_level='user'): """Set user access :param uid: user number [1:16] :param channel: number [1:7] :param callback: User Restricted to Callback False = User Privilege Limit is determined by the User Privilege Limit parameter, below, for both callback and non-callback connections. True = User Privilege Limit is determined by the User Privilege Limit parameter for callback connections, but is restricted to Callback level for non-callback connections. Thus, a user can only initiate a Callback when they 'call in' to the BMC, but once the callback connection has been made, the user could potentially establish a session as an Operator. :param link_auth: User Link authentication enable/disable (used to enable whether this user's name and password information will be used for link authentication, e.g. PPP CHAP) for the given channel. Link authentication itself is a global setting for the channel and is enabled/disabled via the serial/modem configuration parameters. :param ipmi_msg: User IPMI Messaginge: (used to enable/disable whether this user's name and password information will be used for IPMI Messaging. In this case, 'IPMI Messaging' refers to the ability to execute generic IPMI commands that are not associated with a particular payload type. For example, if IPMI Messaging is disabled for a user, but that user is enabled for activatallow_authing the SOL payload type, then IPMI commands associated with SOL and session management, such as Get SOL Configuration Parameters and Close Session are available, but generic IPMI commands such as Get SEL Time are unavailable.) :param privilege_level: User Privilege Limit. (Determines the maximum privilege level that the user is allowed to switch to on the specified channel.) * callback * user * operator * administrator * proprietary * no_access * custom. """ await self.oem_init() if hasattr(self._oem, 'oem_user_access'): callback, privilege_level = self._oem.oem_user_access( callback, privilege_level) if channel is None: channel = await self.get_network_channel() b = 0b10000000 if callback: b |= 0b01000000 if link_auth: b |= 0b00100000 if ipmi_msg: b |= 0b00010000 b |= channel & 0b00001111 privilege_levels = { 'reserved': 0, 'callback': 1, 'user': 2, 'operator': 3, 'administrator': 4, 'proprietary': 5, 'no_access': 0x0F, } await self._oem.set_user_access( uid, channel, callback, link_auth, ipmi_msg, privilege_level) if privilege_level.startswith('custom.'): return True # unable to proceed with standard support data = [b, uid & 0b00111111, privilege_levels[privilege_level] & 0b00001111, 0] response = await self.raw_command(netfn=0x06, command=0x43, data=data) if 'error' in response: raise Exception(response['error']) # Set KVM and VMedia Allowed if is administrator if privilege_level == 'administrator': await self.set_extended_privilleges(uid) return True async def get_user_access(self, uid, channel=None): """Get user access :param uid: user number [1:16] :param channel: number [1:7] :return: channel_info: max_user_count = maximum number of user IDs on this channel enabled_users = count of User ID slots presently in use users_with_fixed_names = count of user IDs with fixed names access: callback link_auth ipmi_msg privilege_level: [reserved, callback, user, operatorm administrator, proprietary, no_access] """ # user access available during call-in or callback direct connection if channel is None: channel = await self.get_network_channel() data = [channel, uid] response = await self.raw_command(netfn=0x06, command=0x44, data=data) if 'error' in response: raise Exception(response['error']) data = response['data'] if len(data) != 4: raise Exception('expecting 4 data bytes') r = {'channel_info': {}, 'access': {}} r['channel_info']['max_user_count'] = data[0] r['channel_info']['enabled_users'] = data[1] & 0b00111111 r['channel_info']['users_with_fixed_names'] = data[2] & 0b00111111 r['access']['callback'] = (data[3] & 0b01000000) != 0 r['access']['link_auth'] = (data[3] & 0b00100000) != 0 r['access']['ipmi_msg'] = (data[3] & 0b00010000) != 0 await self.oem_init() oempriv = await self._oem.get_user_privilege_level(uid) if oempriv: r['access']['privilege_level'] = oempriv else: privilege_levels = { 0: 'reserved', 1: 'callback', 2: 'user', 3: 'operator', 4: 'administrator', 5: 'proprietary', 0x0F: 'no_access' } r['access']['privilege_level'] = privilege_levels[data[3] & 0b00001111] return r async def set_user_name(self, uid, name): """Set user name :param uid: user number [1:16] :param name: username (limit of 16bytes) """ data = [uid] if not isinstance(name, bytes): name = name.encode('utf-8') if len(name) > 16: raise Exception('name must be less than or = 16 chars') name = name.ljust(16, b'\x00') name = bytearray(name) data.extend(name) # set timeout to 2s to avoid retry causing enable failure await self.raw_command(netfn=0x06, command=0x45, data=data, timeout=2) return True async def get_user_name(self, uid, return_none_on_error=True): """Get user name :param uid: user number [1:16] :param return_none_on_error: return None on error TODO: investigate return code on error """ response = await self.raw_command(netfn=0x06, command=0x46, data=(uid,)) if 'error' in response: if return_none_on_error: return None raise Exception(response['error']) name = None if 'data' in response: data = response['data'] if len(data) == 16: # convert int array to string n = ''.join(chr(data[i]) for i in range(0, len(data))) # remove padded \x00 chars n = n.rstrip("\x00") if len(n) > 0: name = n return name async def set_user_password(self, uid, mode='set_password', password=None): """Set user password and (modes) :param uid: id number of user. see: get_names_uid()['name'] :param mode: disable = disable user connections enable = enable user connections set_password = set or ensure password test_password = test password is correct :param password: max 16 char string (optional when mode is [disable or enable]) :return: True on success when mode = test_password, return False on bad password """ mode_mask = { 'disable': 0, 'enable': 1, 'set_password': 2, 'test_password': 3 } data = [uid, mode_mask[mode]] if password: if not isinstance(password, bytes): password = password.encode('utf8') if 21 > len(password) > 16: password = password.ljust(20, b'\x00') data[0] |= 0b10000000 elif len(password) > 20: raise Exception('password has limit of 20 chars') else: password = password.ljust(16, b'\x00') data.extend(bytearray(password)) await self.oem_init() data = await self._oem.process_password(password, data) try: await self.raw_command(netfn=0x06, command=0x47, data=data) except exc.IpmiException as ie: if mode == 'test_password': return False elif mode in ('enable', 'disable') and ie.ipmicode == 0xcc: # Some BMCs see redundant calls to password disable/enable # as invalid return True raise return True async def get_channel_max_user_count(self, channel=None): """Get max users in channel (helper) :param channel: number [1:7] :return: int -- often 16 """ if channel is None: channel = await self.get_network_channel() access = await self.get_user_access(channel=channel, uid=1) return access['channel_info']['max_user_count'] async def get_user(self, uid, channel=None): """Get user (helper) :param uid: user number [1:16] :param channel: number [1:7] :return: name: (str) uid: (int) channel: (int) access: callback (bool) link_auth (bool) ipmi_msg (bool) privilege_level: (str)[callback, user, operatorm administrator, proprietary, no_access] expiration: None for 'unknown', 0 for no expiry, days to expire otherwise. """ if channel is None: channel = await self.get_network_channel() name = await self.get_user_name(uid) access = await self.get_user_access(uid, channel) await self.oem_init() expiration = await self._oem.get_user_expiration(uid) data = {'name': name, 'uid': uid, 'channel': channel, 'access': access['access'], 'expiration': expiration} return data async def get_name_uids(self, name, channel=None): """get list of users (helper) :param channel: number [1:7] :return: list of users """ if channel is None: channel = await self.get_network_channel() uid_list = [] max_ids = await self.get_channel_max_user_count(channel) for uid in range(1, max_ids): if name == await self.get_user_name(uid=uid): uid_list.append(uid) return uid_list async def get_users(self, channel=None): """get list of users and channel access information (helper) :param channel: number [1:7] :return: name: (str) uid: (int) channel: (int) access: callback (bool) link_auth (bool) ipmi_msg (bool) privilege_level: (str)[callback, user, operatorm administrator, proprietary, no_access] """ await self.oem_init() if channel is None: channel = await self.get_network_channel() names = {} max_ids = await self.get_channel_max_user_count(channel) for uid in range(1, max_ids + 1): name = await self.get_user_name(uid=uid) if await self._oem.is_valid(name): names[uid] = await self.get_user(uid=uid, channel=channel) return names async def create_user(self, uid, name, password, channel=None, callback=False, link_auth=True, ipmi_msg=True, privilege_level='user'): """create/ensure a user is created with provided settings (helper) :param privilege_level: User Privilege Limit. (Determines the maximum privilege level that the user is allowed to switch to on the specified channel.) * callback * user * operator * administrator * proprietary * no_access """ # current user might be trying to update.. dont disable # set_user_password(uid, password, mode='disable') if channel is None: channel = await self.get_network_channel() await self.set_user_name(uid, name) await self.set_user_password(uid, password=password) await self.set_user_password(uid, mode='enable', password=password) await self.set_user_access(uid, channel, callback=callback, link_auth=link_auth, ipmi_msg=ipmi_msg, privilege_level=privilege_level) return True async def user_delete(self, uid, channel=None): """Delete user (helper) Note that in IPMI, user 'deletion' isn't a concept. This function will make a best effort to provide the expected result (e.g. web interfaces skipping names and ipmitool skipping as well. :param uid: user number [1:16] :param channel: number [1:7] """ # TODO(jjohnson2): Provide OEM extensibility to cover user deletion await self.oem_init() if hasattr(self._oem, 'user_delete'): try: await self._oem.user_delete(uid, channel) except exc.BypassGenericBehavior: return if hasattr(self._oem, 'user_delete_privilege_level'): privilege_level = await self._oem.user_delete_privilege_level() else: privilege_level = 'no_access' if channel is None: channel = await self.get_network_channel() await self.set_user_password(uid, mode='disable', password=None) # TODO(steveweber) perhaps should set user access on all channels # so new users dont get extra access await self.set_user_access(uid, channel=channel, callback=False, link_auth=False, ipmi_msg=False, privilege_level=privilege_level) try: # First try to set name to all \x00 explicitly # Fix bug-174389, don't try to send \xff command, # will cause IMM1 can't login await self.set_user_name(uid, '') except exc.IpmiException: raise return True async def disable_user(self, uid, mode): """Disable User Just disable the User. This will not disable the password or revoke privileges. :param uid: user number [1:16] :param mode: disable = disable user connections enable = enable user connections """ await self.set_user_password(uid, mode) return True async def update_user(self, user): """Update User Update user attributes, include name, password, access :param user: user attributes """ if 'username' in user: await self.set_user_name(uid=user['uid'], name=user['username']) privilege_level = None if 'privilege_level' in user: privilege_level = user['privilege_level'] if privilege_level and privilege_level == 'no_access': return await self.upate_user_no_access(user, privilege_level) else: return await self.update_user_default(user, privilege_level) async def upate_user_no_access(self, user, privilege_level): # if set to no_access, modify password first if 'password' in user: await self.set_user_password(uid=user['uid'], password=user['password']) await self.set_user_access(uid=user['uid'], privilege_level=privilege_level) return True async def update_user_default(self, user, privilege_level): if privilege_level: await self.set_user_access(uid=user['uid'], privilege_level=privilege_level) if 'password' in user: await self.set_user_password(uid=user['uid'], password=user['password']) await self.set_user_password(uid=user['uid'], mode='enable', password=user['password']) if 'enabled' in user: if user['enabled'] == 'yes': mode = 'enable' else: mode = 'disable' await self.disable_user(user['uid'], mode) return True async def get_firmware(self, components=(), category=None): """Retrieve OEM Firmware information""" await self.oem_init() mcinfo = await self.raw_command(netfn=6, command=1) major, minor = struct.unpack('BB', mcinfo['data'][2:4]) bmcver = '{0}.{1}'.format(major, hex(minor)[2:]) async for x in self._oem.get_oem_firmware(bmcver, components, category): yield x async def get_capping_enabled(self): """Get PSU based power capping status :return: True if enabled and False if disabled """ await self.oem_init() return await self._oem.get_oem_capping_enabled() async def set_capping_enabled(self, enable): """Set PSU based power capping :param enable: True for enable and False for disable """ await self.oem_init() return await self._oem.set_oem_capping_enabled(enable) async def set_server_capping(self, value): await self.oem_init() await self._oem.set_oem_server_capping(value) async def get_server_capping(self): await self.oem_init() return await self._oem.get_oem_server_capping() async def get_remote_kvm_available(self): """Get remote KVM availability""" await self.oem_init() return await self._oem.get_oem_remote_kvm_available() async def get_domain_name(self): """Get Domain name""" await self.oem_init() return await self._oem.get_oem_domain_name() async def set_domain_name(self, name): """Set Domain name :param name: domain name to be set """ await self.oem_init() await self._oem.set_oem_domain_name(name) async def get_graphical_console(self): """Get graphical console launcher""" await self.oem_init() return await self._oem.get_graphical_console() async def get_update_status(self): await self.oem_init() return await self._oem.get_update_status() async def update_firmware(self, filename, data=None, progress=None, bank=None): """Send file to BMC to perform firmware update :param filename: The filename to upload to the target BMC :param data: The payload of the firmware. Default is to read from specified filename. :param progress: A callback that will be given a dict describing update process. Provide if :param bank: Indicate a target 'bank' of firmware if supported """ await self.oem_init() if progress is None: progress = lambda x: True return await self._oem.update_firmware(filename, data, progress, bank) async def attach_remote_media(self, url, username=None, password=None): """Attach remote media by url Given a url, attach remote media (cd/usb image) to the target system. :param url: URL to indicate where to find image (protocol support varies by BMC) :param username: Username for endpoint to use when accessing the URL. If applicable, 'domain' would be indicated by '@' or '\' syntax. :param password: Password for endpoint to use when accessing the URL. """ await self.oem_init() return await self._oem.attach_remote_media(url, username, password) async def detach_remote_media(self): await self.oem_init() return await self._oem.detach_remote_media() async def upload_media(self, filename, progress=None, data=None): """Upload a file to be hosted on the target BMC This will upload the specified data to the BMC so that it will make it available to the system as an emulated USB device. :param filename: The filename to use, the basename of the parameter will be given to the bmc. :param progress: Optional callback for progress updates """ await self.oem_init() return await self._oem.upload_media(filename, progress, data) async def list_media(self): """List attached remote media :returns: An iterable list of attached media """ await self.oem_init() async for m in self._oem.list_media(): yield m async def get_licenses(self): await self.oem_init() async for x in self._oem.get_licenses(): yield x async def delete_license(self, name): await self.oem_init() return await self._oem.delete_license(name) async def save_licenses(self, directory): if os.path.exists(directory) and not os.path.isdir(directory): raise exc.InvalidParameterValue( 'Not allowed to overwrite existing file: {0}'.format( directory)) await self.oem_init() async for lic in self._oem.save_licenses(directory): yield lic async def apply_license(self, filename, progress=None, data=None): await self.oem_init() async for x in self._oem.apply_license(filename, progress, data): yield x async def set_extended_privilleges(self, uid): """Set user extended privillege as 'KVM & VMedia Allowed' """ await self.oem_init() return await self._oem.set_oem_extended_privilleges(uid)