-class Reset:
- """
- Keeps track of state information for resets and kills
-
- resettimeleft - timeout before checking for next reset
- resetcount - number of strikes
- killtimeleft - time out before removing from kill queue
- {kill,reset}mail - Time of last email
- kill - State of kill. If slice is already being killed, wait before retry.
- """
-
- def __init__(self,name):
- self.name = name
- self.resetmail = 0
- self.killmail = 0
-
- def __repr__(self):
- return self.name
-
- # Reset slice
- def reset(self, params):
- if self.resetcount == 0 or self.resettimeleft == 0:
- print "%s has %s seconds to die and has been reset %s times" \
- %(self.name, self.resettimeleft, self.resetcount)
- if debug:
- print reset_subject % params
- print reset_body % params
- try:
- pid = os.fork()
- if pid == 0:
- print "Resetting slice " + self.name
- vserver = VServer(self.name)
- vserver.stop()
- vserver.start()
- os._exit(0)
- else:
- os.waitpid(pid,0)
- except Exception, err:
- print "Warning: Exception received while resetting slice %s:" \
- % self.name, err
- if (time.time() - self.resetmail) > email_timeout:
- slicemail(self.name, reset_subject % params, reset_body % params)
- print "Sending Reset email for slice %s" % self.name
- self.resetmail = time.time()
-