コード例 #1
0
def destroy(force):
    """
    Destroy the VM. Deletes all resources. Start over with 'yurt vm init'.
    """

    try:
        vm_state = vm.state()

        if vm_state == vm.State.NotInitialized:
            logging.info(
                "The VM has not been initialized. Initialize with 'yurt vm init'."
            )
        elif vm_state == vm.State.Running:
            logging.error(
                "Cannot destroy while VM is running. Stop it first with 'yurt shutdown'"
            )
        else:
            vm.destroy()
    except YurtException as e:
        if force:
            vm.delete_instance_files()
        else:
            logging.error(e.message)
            logging.info(
                "Run 'yurt vm destroy --force' to force deletion of VM resources belonging to Yurt."
            )
    except Exception:
        if force:
            vm.delete_instance_files()
コード例 #2
0
    def setUpClass(cls):
        cls.discard_vm = os.environ.get(
            "YURT_TEST_DISCARD_VM_POLICY") == "discard"

        if cls.discard_vm:
            if vm.state() == vm.State.Running:
                vm.stop(force=True)
            if vm.state() == vm.State.Stopped:
                vm.destroy()

        if vm.state() == vm.State.NotInitialized:
            vm.init()
            logging.info("Waiting for VM registration...")
            time.sleep(3)

        if vm.state() == vm.State.Stopped:
            vm.start()
            lxc.configure_lxd()

        def check_if_running():
            if vm.state() != vm.State.Running:
                raise YurtException("VM Not running")

        util.retry(check_if_running)
コード例 #3
0
 def tearDownClass(cls):
     if cls.discard_vm:
         vm.stop(force=True)
         vm.destroy()