def is_up(self): try: from libcloud.compute.types import NodeState except ImportError: raise ex.Error("missing required module libcloud.compute.types") n = self.get_node() if n is not None and n.state == NodeState().RUNNING: return True if n is None: self.status_log("state:unknown") else: self.status_log("state:" + NodeState().tostring(n.state)) return False
def container_start(self): """ RUNNING = 0 REBOOTING = 1 TERMINATED = 2 PENDING = 3 UNKNOWN = 4 STOPPED = 5 SUSPENDED = 6 ERROR = 7 PAUSED = 8 """ try: from libcloud.compute.types import NodeState except ImportError: raise ex.Error("missing required module libcloud.compute.types") n = self.get_node() if n is None: self.provision() return elif n.state == NodeState().RUNNING: self.log.info("already running") return elif n.state == NodeState().PENDING: self.log.info("already pending. wait for running state.") self.wait_for_fn(self.is_up, self.start_timeout, 5) return elif n.state == NodeState().REBOOTING: self.log.info("currently rebooting. wait for running state.") self.wait_for_fn(self.is_up, self.start_timeout, 5) return elif n.state == NodeState().STOPPED: self.log.info("starting ebs ec2 instance through aws") self.cloud.driver.ex_start_node(n) self.log.info("wait for container up status") self.wait_for_fn(self.is_up, self.start_timeout, 5) return raise ex.Error("don't know what to do with node in state: %s" % NodeState().tostring(n.state))