Exemplo n.º 1
0
 def insert_request(self, data):
     array = data.split(" ")
     delay = 10
     custom_delay = False
     now = int(time.time())
     if (len(array) < 3) or (len(array) > 4):
         log.info("Wrong data size")
         raise Exception("Unexpected data")
     if len(array) == 4:
         delay = int(array[3])
         custom_delay = True
     hostname = array[0]
     port = int(array[1])
     request = array[2]
     # this will throw if the pdu is not found
     drivername_from_hostname(hostname, self.server.config["pdus"])
     dbh = self.server.dbh
     if not (request in ["reboot", "on", "off"]):
         log.info("Unknown request: %s", request)
         raise Exception("Unknown request: %s", request)
     if request == "reboot":
         log.debug("reboot requested, submitting off/on")
         dbh.insert_request(hostname, port, "off", now)
         dbh.insert_request(hostname, port, "on", now + delay)
     else:
         if custom_delay:
             log.debug("using delay as requested")
             dbh.insert_request(hostname, port, request, now + delay)
         else:
             dbh.insert_request(hostname, port, request, now)
Exemplo n.º 2
0
 def insert_request(self, data):
     array = data.split(" ")
     delay = 10
     custom_delay = False
     now = int(time.time())
     if (len(array) < 3) or (len(array) > 4):
         log.info("Wrong data size")
         raise Exception("Unexpected data")
     if len(array) == 4:
         delay = int(array[3])
         custom_delay = True
     hostname = array[0]
     port = int(array[1])
     request = array[2]
     # this will throw if the pdu is not found
     drivername_from_hostname(hostname, self.server.config["pdus"])
     dbh = self.server.dbh
     if not (request in ["reboot", "on", "off"]):
         log.info("Unknown request: %s", request)
         raise Exception("Unknown request: %s", request)
     if request == "reboot":
         log.debug("reboot requested, submitting off/on")
         dbh.insert_request(hostname, port, "off", now)
         dbh.insert_request(hostname, port, "on", now + delay)
     else:
         if custom_delay:
             log.debug("using delay as requested")
             dbh.insert_request(hostname, port, request, now + delay)
         else:
             dbh.insert_request(hostname, port, request, now)
Exemplo n.º 3
0
 def driver_from_hostname(self, hostname):
     drivername = drivername_from_hostname(hostname, self.pdus)
     driver = PDUDriver.select(drivername)(hostname, self.pdus[hostname])
     return driver
Exemplo n.º 4
0
 def driver_from_hostname(self, hostname):
     drivername = drivername_from_hostname(hostname, self.pdus)
     driver = PDUDriver.select(drivername)(hostname, self.pdus[hostname])
     return driver