Skip to content
Merged
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
17 changes: 13 additions & 4 deletions src/platform/backends/hyperv/hyperv_virtual_machine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,6 @@ void mp::HyperVVirtualMachine::shutdown(ShutdownPolicy shutdown_policy)
state_wait.wait(lock, [this] { return shutdown_while_starting; });
}

ip = std::nullopt;
update_state();
}

Expand Down Expand Up @@ -440,6 +439,16 @@ void mp::HyperVVirtualMachine::ensure_vm_is_running()

void mp::HyperVVirtualMachine::update_state()
{
// Invalidate the management IP address on state update.
if (current_state() == VirtualMachine::State::running)
{
// Cached IPs become stale when the guest is restarted from within. By resetting them here
// we at least cover multipass's restart initiatives, which include state updates.
mpl::log(mpl::Level::debug,
vm_name,
"Invalidating cached mgmt IP address upon state update");
management_ip = std::nullopt;
}
monitor->persist_state_for(vm_name, state);
}

Expand All @@ -455,17 +464,17 @@ std::string mp::HyperVVirtualMachine::ssh_username()

std::string mp::HyperVVirtualMachine::management_ipv4()
{
if (!ip)
if (!management_ip)
{
// Not using cached SSH session for this because a) the underlying functions do not
// guarantee constness; b) we endure the penalty of creating a new session only when we
// don't have the IP yet.
auto result =
remote_ip(VirtualMachine::ssh_hostname(), ssh_port(), ssh_username(), key_provider);
if (result)
ip.emplace(result.value());
management_ip.emplace(result.value());
}
return ip ? ip.value().as_string() : "UNKNOWN";
return management_ip ? management_ip.value().as_string() : "UNKNOWN";
}

std::string mp::HyperVVirtualMachine::ipv6()
Expand Down
1 change: 0 additions & 1 deletion src/platform/backends/hyperv/hyperv_virtual_machine.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ class HyperVVirtualMachine final : public BaseVirtualMachine

VirtualMachineDescription desc; // TODO we should probably keep this in the base class instead
const QString name;
std::optional<multipass::IPAddress> ip;
std::unique_ptr<PowerShell> power_shell;
VMStatusMonitor* monitor;
bool update_suspend_status{true};
Expand Down
Loading