Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/platform/backends/applevz/applevz_virtual_machine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ AppleVZVirtualMachine::~AppleVZVirtualMachine()

if (vm_handle)
{
update_shutdown_status = false;
multipass::top_catch_all(vm_name, [this]() {
if (state == State::running)
{
suspend();
// TODO: Call suspend() once fully implemented
shutdown();
}
else
{
Expand Down Expand Up @@ -205,6 +207,9 @@ void AppleVZVirtualMachine::shutdown(ShutdownPolicy shutdown_policy)

void AppleVZVirtualMachine::suspend()
{
throw NotImplementedOnThisBackendException{"suspend"};

// TODO: remove the throw above once suspend-to-disk is implemented
if (!vm_handle)
{
assert(state == State::stopped);
Expand Down Expand Up @@ -275,7 +280,8 @@ std::optional<IPAddress> AppleVZVirtualMachine::management_ipv4()

void AppleVZVirtualMachine::handle_state_update()
{
monitor->persist_state_for(vm_name, state);
if (update_shutdown_status)
monitor->persist_state_for(vm_name, state);
}

void AppleVZVirtualMachine::update_cpus(int num_cores)
Expand Down Expand Up @@ -310,7 +316,9 @@ void AppleVZVirtualMachine::set_state(applevz::AppleVMState vm_state)
case applevz::AppleVMState::running:
case applevz::AppleVMState::stopping:
// No `stopping` state in Multipass yet
state = State::running;
// Let wait_until_ssh_up decide when we are running
if (state != State::starting)
state = State::running;
break;
case applevz::AppleVMState::paused:
state = State::suspended;
Expand Down Expand Up @@ -382,8 +390,6 @@ void AppleVZVirtualMachine::initialize_vm_handle()
fmt::format("Failed to create VM handle for '{}': {}", vm_name, error));
}

set_state(MP_APPLEVZ.get_state(vm_handle));

mpl::trace(log_category, "initialize_vm_handle() -> Created handle for VM '{}'", vm_name);
}
} // namespace multipass::applevz
8 changes: 8 additions & 0 deletions src/platform/backends/applevz/applevz_virtual_machine.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ class AppleVZVirtualMachine : public BaseVirtualMachine
void resize_memory(const MemorySize& new_size) override;
void resize_disk(const MemorySize& new_size) override;

std::shared_ptr<const Snapshot> take_snapshot(const VMSpecs& /*specs*/,
const std::string& /*snapshot_name*/,
const std::string& /*comment*/) override
{
throw NotImplementedOnThisBackendException{"snapshots"};
}

private:
void initialize_vm_handle();
void set_state(applevz::AppleVMState vm_state);
Expand All @@ -64,5 +71,6 @@ class AppleVZVirtualMachine : public BaseVirtualMachine
VirtualMachineDescription desc;
VMStatusMonitor* monitor;
VMHandle vm_handle{nullptr};
bool update_shutdown_status{true};
};
} // namespace multipass::applevz
Loading