def _got_bootdev(self, response): # interpret response per 'get system boot options' self.requestpending = False if 'error' in response: _raiseorcall( self.commandcallback, response, self.commandcallbackargs) return # 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): self.lastresponse = {'bootdev': 'default'} else: # will consult data2 of the boot flags parameter for the data bootnum = (response['data'][3] & 0b111100) >> 2 bootdev = boot_devices[bootnum] if (bootdev): self.lastresponse = {'bootdev': bootdev} else: self.lastresponse = {'bootdev': bootnum} if self.commandcallback: session.call_with_optional_args(self.commandcallback, self.lastresponse, self.commandcallbackargs)
def _got_bootdev(self,response): #interpret response per 'get system boot options' self.requestpending=False if 'error' in response: _raiseorcall(self.commandcallback,response,self.commandcallbackargs) return #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): self.lastresponse={ 'bootdev': 'default' } else: #will consult data2 of the boot flags parameter for the data bootnum = (response['data'][3] & 0b111100) >> 2 bootdev = boot_devices[bootnum] if (bootdev): self.lastresponse={'bootdev': bootdev} else: self.lastresponse={'bootdev': bootnum} if self.commandcallback: call_with_optional_args(self.commandcallback, self.lastresponse, self.commandcallbackargs)
def _got_power(self,response): self.requestpending=False if 'error' in response: _raiseorcall(self.commandcallback,response,self.commandcallbackargs) return assert(response['command'] == 1 and response['netfn'] == 1) self.powerstate = 'on' if (response['data'][0] & 1) else 'off' self.lastresponse={'powerstate': self.powerstate} if self.commandcallback: call_with_optional_args(self.commandcallback, self.lastresponse, self.commandcallbackargs)
def _got_power(self, response): self.requestpending = False if 'error' in response: _raiseorcall( self.commandcallback, response, self.commandcallbackargs) return assert(response['command'] == 1 and response['netfn'] == 1) self.powerstate = 'on' if (response['data'][0] & 1) else 'off' self.lastresponse = {'powerstate': self.powerstate} if self.commandcallback: session.call_with_optional_args(self.commandcallback, self.lastresponse, self.commandcallbackargs)
def _power_wait(self,response): if 'error' in response: _raiseorcall(self.commandcallback,response,self.commandcallbackargs) return self.powerstate = 'on' if (response['data'][0] & 1) else 'off' if self.powerstate==self.waitpowerstate: self.requestpending=False self.lastresponse={'powerstate': self.powerstate} if self.commandcallback: call_with_optional_args(self.commandcallback, self.lastresponse, self.commandcallbackargs) return self.ipmi_session.raw_command(netfn=0, command=1, callback=self._power_wait)
def _power_wait(self, response): if 'error' in response: _raiseorcall( self.commandcallback, response, self.commandcallbackargs) return self.powerstate = 'on' if (response['data'][0] & 1) else 'off' if self.powerstate == self.waitpowerstate: self.requestpending = False self.lastresponse = {'powerstate': self.powerstate} if self.commandcallback: session.call_with_optional_args(self.commandcallback, self.lastresponse, self.commandcallbackargs) return self.ipmi_session.raw_command(netfn=0, command=1, callback=self._power_wait)
def _power_set(self,response): if 'error' in response: _raiseorcall(self.commandcallback,response,self.commandcallbackargs) return self.lastresponse={'pendingpowerstate': self.newpowerstate} if (self.wait_for_power and self.newpowerstate in ('on','off','shutdown','softoff')): if self.newpowerstate in ('softoff','shutdown'): self.waitpowerstate='off' else: self.waitpowerstate=self.newpowerstate self.ipmi_session.raw_command(netfn=0, command=1, callback=self._power_wait) else: self.requestpending=False if self.commandcallback: call_with_optional_args(self.commandcallback, self.lastresponse, self.commandcallbackargs)
def _power_set(self, response): if 'error' in response: _raiseorcall( self.commandcallback, response, self.commandcallbackargs) return self.lastresponse = {'pendingpowerstate': self.newpowerstate} if (self.wait_for_power and self.newpowerstate in ('on', 'off', 'shutdown', 'softoff')): if self.newpowerstate in ('softoff', 'shutdown'): self.waitpowerstate = 'off' else: self.waitpowerstate = self.newpowerstate self.ipmi_session.raw_command(netfn=0, command=1, callback=self._power_wait) else: self.requestpending = False if self.commandcallback: session.call_with_optional_args(self.commandcallback, self.lastresponse, self.commandcallbackargs)
def _raiseorcall(callback,response,args=None): if callback is None: if 'error' in response: raise Exception(response['error']) else: call_with_optional_args(callback,args)
def _raiseorcall(callback, response, args=None): if callback is None: if 'error' in response: raise Exception(response['error']) else: session.call_with_optional_args(callback, args)