def Get(self, msg): """Get the power status of a device. Arguments: msg: type control_pb2.GetRequest Returns: control_pb2.GetResponse """ if msg.type != control_pb2.FEAT_PWR: log.exception('Invalid Type: %d' % (msg.type)) response = control_pb2.GetResponse() errorIndication, errorStatus, errorIndex, varBinds = self.cmdGen.getCmd( cmdgen.CommunityData(SNMP_APC_USER, mpModel=0), cmdgen.UdpTransportTarget((self.device.server, SNMP_UDP_PORT)), cmdgen.MibVariable(SNMP_APC_PORT_VAR + str(self.device.port)) ) if self._CheckResponseOk(response, errorIndication, errorStatus, errorIndex, varBinds): assert(len(varBinds) == 1) val = varBinds[0][1] for k, v in PWR_COMMANDS.iteritems(): if val == v: response.value = k response.result = True log.debug('Return %d' % response.value) return response
def Get(self, msg): """Get the power status of a device. Arguments: msg: type control_pb2.GetRequest Returns: control_pb2.GetResponse """ response = control_pb2.GetResponse() response.result = True response.value = global_values[msg.type] log.debug('Got %d: %d' % (msg.type, response.value)) return response
def GetCommand(self, command): response = control_pb2.GetResponse() rc = self.Checkcommand(command) if rc is None: response.result = False response.error = "No communication" return response for k, v in EPSON_PORT_VALUE.iteritems(): if rc in v['out']: response.result = True response.value = k return response response.result = False response.error = "Invalid response 0x%2x" % (rc) return response
def Get(self, msg): """Get the power status of a device. Arguments: msg: type control_pb2.GetRequest Returns: control_pb2.GetResponse """ if msg.type != control_pb2.FEAT_PWR: log.exception('Invalid Type: %d' % (msg.type)) response = control_pb2.GetResponse() response.result = True response.value = self.get_value log.debug('Return %d' % response.value) return response
def Set(self, msg): """Set the power status of a device. Arguments: msg: type control_pb2.SetRequest Returns: control_pb2.SetResponse """ if msg.type != control_pb2.FEAT_PWR: log.exception('Invalid Type: %d' % (msg.type)) self.cmd.append(PWR_COMMANDS[msg.value]) log.debug('issuing %s' % (" ".join(self.cmd))) r = subprocess.call(self.cmd) response = control_pb2.GetResponse() response.result = (r == 0) return response
def Set(self, msg): """Set the power status of a device. Arguments: msg: type control_pb2.SetRequest Returns: control_pb2.SetResponse """ if msg.type != control_pb2.FEAT_PWR: log.exception('Invalid Type: %d' % (msg.type)) if msg.value == control_pb2.POWER_ON: subprocess.call(['wakeonlan', self.device.port]) timeout = 60 else: timeout = 10 response = control_pb2.GetResponse() response.result = (self.ping(timeout) == msg.value) return response
def Set(self, msg): """Set the power status of a device. Arguments: msg: type control_pb2.SetRequest Returns: control_pb2.SetResponse """ if msg.type != control_pb2.FEAT_PWR: log.exception('Invalid Type: %d' % (msg.type)) log.debug('Got %d' % msg.value) errorIndication, errorStatus, errorIndex, varBinds = self.cmdGen.setCmd( cmdgen.CommunityData(SNMP_APC_USER, mpModel=0), cmdgen.UdpTransportTarget((self.device.server, SNMP_UDP_PORT)), (SNMP_APC_PORT_VAR + str(self.device.port), rfc1902.Integer(PWR_COMMANDS[msg.value])) ) response = control_pb2.GetResponse() self._CheckResponseOk(response, errorIndication, errorStatus, errorIndex, varBinds) return response
def GetCommand(self, command): response = control_pb2.GetResponse() for _ in xrange(0, 3): rc = self.Checkcommand(command[0], 0) if rc is None: time.sleep(command[2]) else: break if rc is None: response.result = False response.error = "No communication" return response for k, v in command[1].iteritems(): if rc == v: response.result = True response.value = k return response response.result = False response.error = "Invalid response %d" % (rc) return response
def Set(self, msg): """Set the power status of a device. Arguments: msg: type control_pb2.SetRequest Returns: control_pb2.SetResponse """ if msg.type != control_pb2.FEAT_PWR: log.exception('Invalid Type: %d' % (msg.type)) log.debug('Got %d' % msg.value) url = self.urlbase + "/set.xml?value=" + PWR_COMMANDS[msg.value]['out'] try: request = urllib2.urlopen(url, timeout=2) except urllib2.URLError as e: print "Unable to access %s: %s" % (url, e) response = control_pb2.GetResponse() response.result = True return response
def Set(self, msg): """Set the power status of a device. Arguments: msg: type control_pb2.SetRequest Returns: control_pb2.SetResponse """ if msg.type != control_pb2.FEAT_PWR: log.exception('Invalid Type: %d' % (msg.type)) rc, result = self.ipmi_cmd(PWR_COMMANDS[msg.value]) response = control_pb2.GetResponse() if rc == 0 and result == self.OK: response.result = True response.value = msg.value else: response.result = False response.error = result return response
def Get(self, msg): """Get the power status of a device. Arguments: msg: type control_pb2.GetRequest Returns: control_pb2.GetResponse """ if msg.type != control_pb2.FEAT_PWR: log.exception('Invalid Type: %d' % (msg.type)) response = control_pb2.GetResponse() rc, result = self.ipmi_cmd(['--stat']) if rc == 0: response.result = True response.value = self.PWR_RESULTS[result] else: response.result = False response.error = result log.debug('Return %d' % response.value) return response
def Get(self, request): response = control_pb2.GetResponse() rc = self.check_command(ROTEL_REFRESH_DISPLAY) if request.type == control_pb2.FEAT_PWR: response.result = True if rc and self.source.isalnum(): response.value = control_pb2.POWER_ON else: response.value = control_pb2.POWER_OFF elif request.type == control_pb2.FEAT_INPUT: response.result = rc for k, v in ROTEL_PORT_VALUE.iteritems(): if self.source == v['in']: response.value = k break elif request.type == control_pb2.FEAT_PERCENT: response.result = rc response.percent = self.volume else: response.result = False response.error = "Unknown Command" return response
def Set(self, msg): """Set the power status of a device. Arguments: msg: type control_pb2.SetRequest Returns: control_pb2.SetResponse """ if msg.type != control_pb2.FEAT_PWR: log.exception('Invalid Type: %d' % (msg.type)) log.debug('Got %d' % msg.value) url = self.urlbase + '?CMD=SetPower+P%d=%d' % ( 59 + self.port, control_pb2.POWER_OFF - msg.value) try: resp = requests.get(url, auth=self.auth) except requests.exceptions.ConnectionError as e: print "Unable to access %s: %s" % (self.urlbase, e) parser = IppowerParser(self.port) parser.feed(resp.text) response = control_pb2.GetResponse() response.result = True return response
def Set(self, msg): """Set the power status of a device. Arguments: msg: type control_pb2.SetRequest Returns: control_pb2.SetResponse """ if msg.type != control_pb2.FEAT_PWR: log.exception('Invalid Type: %d' % (msg.type)) log.debug('Got %d' % msg.value) if self.get_value != msg.value: self.get_value = msg.value self.child.expect(self.cursor) self.child.sendline(PWR_COMMANDS[msg.value]['out'] + '\r') self.child.expect( 'Enter \'YES\' to continue or <ENTER> to cancel : ') self.child.sendline('YES\r') self.child.expect('Press <ENTER> to continue...') self.child.sendline('\r') response = control_pb2.GetResponse() response.result = True return response