Skip to content

Commit

Permalink
[lxd] Implement forced stop.
Browse files Browse the repository at this point in the history
  • Loading branch information
luis4a0 committed Aug 16, 2022
1 parent 5b4d0db commit 528d995
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
33 changes: 30 additions & 3 deletions src/platform/backends/lxd/lxd_virtual_machine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,35 @@ void mp::LXDVirtualMachine::start()
update_state();
}

void mp::LXDVirtualMachine::stop()
void mp::LXDVirtualMachine::stop(bool force)
{
if (force)
{
auto present_state = current_state();

if (present_state != State::stopped && present_state != State::off)
{
const QJsonObject state_json{{"action", "stop"}, {"force", true}};

auto state_task = lxd_request(manager, "PUT", state_url(), state_json, 5000);

try
{
lxd_wait(manager, base_url, state_task, 60000);
}
catch (const LXDNotFoundException&)
{
}

state = State::stopped;
}

if (update_shutdown_status)
update_state();

return;
}

std::unique_lock<decltype(state_mutex)> lock{state_mutex};
auto present_state = current_state();

Expand Down Expand Up @@ -263,9 +290,9 @@ void mp::LXDVirtualMachine::stop()
update_state();
}

void mp::LXDVirtualMachine::shutdown()
void mp::LXDVirtualMachine::shutdown(bool force)
{
stop();
stop(force);
}

void mp::LXDVirtualMachine::suspend()
Expand Down
4 changes: 2 additions & 2 deletions src/platform/backends/lxd/lxd_virtual_machine.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ class LXDVirtualMachine final : public BaseVirtualMachine
LXDVirtualMachine(const VirtualMachineDescription& desc, VMStatusMonitor& monitor, NetworkAccessManager* manager,
const QUrl& base_url, const QString& bridge_name, const QString& storage_pool);
~LXDVirtualMachine() override;
void stop() override;
void stop(bool force = false) override;
void start() override;
void shutdown() override;
void shutdown(bool force = false) override;
void suspend() override;
State current_state() override;
int ssh_port() override;
Expand Down

0 comments on commit 528d995

Please sign in to comment.