+ def do_discover(self):
+ self.set_discovered()
+
+ def do_provision(self):
+ self.set_provisioned()
+
+ def do_start(self):
+ self.set_started()
+
+ def do_stop(self):
+ self.set_stopped()
+
+ def do_deploy(self):
+ self.set_ready()
+
+ def do_release(self):
+ self.set_released()
+
+ def do_fail(self):
+ self.set_failed()
+ self.ec.inform_failure(self.guid)
+
+ def set_started(self, time = None):
+ """ Mark ResourceManager as STARTED """
+ self.set_state(ResourceState.STARTED, "_start_time", time)
+ self.debug("----- STARTED ---- ")
+
+ def set_stopped(self, time = None):
+ """ Mark ResourceManager as STOPPED """
+ self.set_state(ResourceState.STOPPED, "_stop_time", time)
+ self.debug("----- STOPPED ---- ")
+
+ def set_ready(self, time = None):
+ """ Mark ResourceManager as READY """
+ self.set_state(ResourceState.READY, "_ready_time", time)
+ self.debug("----- READY ---- ")
+
+ def set_released(self, time = None):
+ """ Mark ResourceManager as REALEASED """
+ self.set_state(ResourceState.RELEASED, "_release_time", time)
+
+ msg = " %s guid %d ----- RELEASED ----- " % (self._rtype, self.guid)
+ logger = Logger(self._rtype)
+ logger.debug(msg)
+
+ def set_failed(self, time = None):
+ """ Mark ResourceManager as FAILED """
+ self.set_state(ResourceState.FAILED, "_failed_time", time)
+
+ msg = " %s guid %d ----- FAILED ----- " % (self._rtype, self.guid)
+ logger = Logger(self._rtype)
+ logger.debug(msg)
+
+ def set_discovered(self, time = None):
+ """ Mark ResourceManager as DISCOVERED """
+ self.set_state(ResourceState.DISCOVERED, "_discover_time", time)
+ self.debug("----- DISCOVERED ---- ")
+
+ def set_provisioned(self, time = None):
+ """ Mark ResourceManager as PROVISIONED """
+ self.set_state(ResourceState.PROVISIONED, "_provision_time", time)
+ self.debug("----- PROVISIONED ---- ")
+
+ def set_state(self, state, state_time_attr, time = None):
+ """ Set the state of the RM while keeping a trace of the time """
+
+ # Ensure that RM state will not change after released
+ if self._state == ResourceState.RELEASED:
+ return
+
+ time = time or tnow()
+ self.set_state_time(state, state_time_attr, time)
+
+ def set_state_time(self, state, state_time_attr, time):
+ """ Set the time for the RM state change """
+ setattr(self, state_time_attr, time)
+ self._state = state
+