Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
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)
Ejemplo n.º 3
0
    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)
Ejemplo n.º 4
0
    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)
Ejemplo n.º 5
0
    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)
Ejemplo n.º 6
0
    def Restart(self, cl):
        """Encapsulates the start of an instance.

    """
        op = opcodes.OpInstanceStartup(instance_name=self.name, force=False)
        cli.SubmitOpCode(op, cl=cl)