def halt(force): """ Shut down the VM. """ try: vm.stop(force=force) except YurtException as e: logging.error(e.message) if not force: logging.info("Try forcing shutdown with 'yurt shutdown --force'.")
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 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 tearDownClass(cls): if cls.discard_vm: vm.stop(force=True) vm.destroy()