def _CleanupInstance(cl, notepad, inst, locks): n = notepad.NumberOfCleanupAttempts(inst.name) if inst.name in locks: logging.info("Not cleaning up instance '%s', instance is locked", inst.name) return if n > MAXTRIES: logging.warning("Not cleaning up instance '%s', retries exhausted", inst.name) return logging.info( "Instance '%s' was shutdown by the user, cleaning up instance", inst.name) op = opcodes.OpInstanceShutdown(instance_name=inst.name, admin_state_source=constants.USER_SOURCE) op.reason = [(constants.OPCODE_REASON_SRC_WATCHER, "Cleaning up instance %s" % inst.name, utils.EpochNano())] try: cli.SubmitOpCode(op, cl=cl) if notepad.NumberOfCleanupAttempts(inst.name): notepad.RemoveInstance(inst.name) except Exception: # pylint: disable=W0703 logging.exception("Error while cleaning up instance '%s'", inst.name) notepad.RecordCleanupAttempt(inst.name)
def _CleanupInstance(cl, notepad, inst, locks): n = notepad.NumberOfCleanupAttempts(inst.name) if inst.name in locks: logging.info("Not cleaning up instance '%s', instance is locked", inst.name) return if n > MAXTRIES: logging.warning("Not cleaning up instance '%s', retries exhausted", inst.name) return logging.info( "Instance '%s' was shutdown by the user, cleaning up instance", inst.name) op = opcodes.OpInstanceShutdown(instance_name=inst.name) try: cli.SubmitOpCode(op, cl=cl) if notepad.NumberOfCleanupAttempts(inst.name): notepad.RemoveInstance(inst.name) except Exception: # pylint: disable=W0703 logging.exception("Error while cleaning up instance '%s'", inst.name) notepad.RecordCleanupAttempt(inst.name)
def Restart(self, cl): """Encapsulates the start of an instance. """ op = opcodes.OpInstanceStartup(instance_name=self.name, force=False) op.reason = [(constants.OPCODE_REASON_SRC_WATCHER, "Restarting instance %s" % self.name, utils.EpochNano())] cli.SubmitOpCode(op, cl=cl)
def ActivateDisks(self, cl): """Encapsulates the activation of all disks of an instance. """ op = opcodes.OpInstanceActivateDisks(instance_name=self.name) op.reason = [(constants.OPCODE_REASON_SRC_WATCHER, "Activating disks for instance %s" % self.name, utils.EpochNano())] cli.SubmitOpCode(op, cl=cl)
def ActivateDisks(self, cl): """Encapsulates the activation of all disks of an instance. """ op = opcodes.OpInstanceActivateDisks(instance_name=self.name) cli.SubmitOpCode(op, cl=cl)
def Restart(self, cl): """Encapsulates the start of an instance. """ op = opcodes.OpInstanceStartup(instance_name=self.name, force=False) cli.SubmitOpCode(op, cl=cl)