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()
def restart(force): """ Restart the VM. """ try: if vm.state() == vm.State.Running: vm.stop(force=force) vm.ensure_is_ready(prompt_init=True, prompt_start=False) except YurtException as e: logging.error(e.message)
def start_vm(): """ Start up the VM. """ try: if vm.state() == vm.State.Running: logging.info("Yurt is already running.") else: vm.ensure_is_ready(prompt_init=True, prompt_start=False) except YurtException as e: logging.error(e.message)
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)
def check_if_running(): if vm.state() != vm.State.Running: raise YurtException("VM Not running")