Skip to content

Commit

Permalink
[lxd] Move link finding to net info struct
Browse files Browse the repository at this point in the history
  • Loading branch information
ricab committed Apr 29, 2021
1 parent f07ce5b commit 6699815
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 7 additions & 0 deletions include/multipass/network_interface_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,20 @@
#include <multipass/ip_address.h>
#include <multipass/optional.h>

#include <algorithm>
#include <string>
#include <vector>

namespace multipass
{
struct NetworkInterfaceInfo
{
bool has_link(const std::string& net) const
{
auto end = links.cend();
return std::find(links.cbegin(), end, net) != end;
}

std::string id;
std::string type;
std::string description;
Expand Down
4 changes: 1 addition & 3 deletions src/platform/backends/lxd/lxd_virtual_machine_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,7 @@ void mp::LXDVirtualMachineFactory::prepare_networking(std::vector<NetworkInterfa
if (it != host_nets.end() && it->type == "ethernet")
{
it = std::find_if(host_nets.cbegin(), host_nets.cend(), [&net](const mp::NetworkInterfaceInfo& info) {
const auto& end = info.links.cend();
return info.type == "bridge" &&
std::find(info.links.cbegin(), end, net.id) != end; // TODO@ricab move in
return info.type == "bridge" && info.has_link(net.id);
});
net.id = it != host_nets.cend() ? it->id : mp::backend::create_bridge_with(net.id);
}
Expand Down

0 comments on commit 6699815

Please sign in to comment.