@@ -42,18 +42,45 @@ void disableNetworkManagerDNSOverride()
4242
4343void configureNetworks (const std::list<Connection>& connections)
4444{
45- LOG_INFO (" Setting up networks 2" )
46-
4745 osservice ()->enableService (" NetworkManager" );
46+ disableNetworkManagerDNSOverride ();
47+ const auto shouldDisableIPV6 = []() -> bool {
48+ switch (cluster ()->getProvisioner ()) {
49+ case cloyster::models::Cluster::Provisioner::xCAT:
50+ return true ;
51+ case cloyster::models::Cluster::Provisioner::Confluent:
52+ return false ;
53+ default :
54+ // Unreachable
55+ cloyster::functions::abort (" BUG: Invalid provisioner in network setup" );
56+ }
57+ }();
4858
4959 for (const auto & connection : std::as_const (connections)) {
50- LOG_INFO (" Setting up networks ->> {}" , connection.getNetwork ()->getProfile ())
5160 /* For now, we just skip the external network to avoid disconnects */
5261 if (connection.getNetwork ()->getProfile () == Network::Profile::External) {
5362 continue ;
5463 }
5564
56- LOG_INFO (" Setting up networks {}" , connection.getNetwork ()->getProfile ())
65+ // These validations are sanity checks to improve error messages and
66+ // keep code future proof. The real validation should happen at
67+ // cluster.fillData method
68+ cloyster::functions::abortif (
69+ connection.getNetwork ()->getProfile () == Network::Profile::Management
70+ && connection.getNetwork ()->getGateway ().is_unspecified (),
71+ " Management network requires a gateway, please define a gateway in "
72+ " network_management section of the answerfile: {}" ,
73+ answerfile ()->path ());
74+
75+ if (connection.getNetwork ()->getProfile () != Network::Profile::Management &&
76+ !connection.getNetwork ()->getGateway ().is_unspecified ()) {
77+ LOG_WARN (" Ignoring gateway in {} network {}, only Management network should specify a gateway" ,
78+ connection.getNetwork ()->getGateway ().to_string (),
79+ connection.getNetwork ()->getProfile ());
80+ }
81+
82+ const auto shouldUseGateway = connection.getNetwork ()->getProfile ()
83+ == Network::Profile::Management;
5784
5885#ifndef NDEBUG
5986 if (!connection.getInterface ().has_value ()) {
@@ -65,72 +92,62 @@ void configureNetworks(const std::list<Connection>& connections)
6592
6693 std::vector<address> nameservers
6794 = connection.getNetwork ()->getNameservers ();
68- LOG_INFO (" Setting up networks {}" , connection.getNetwork ()->getProfile ())
6995 std::vector<std::string> formattedNameservers;
70- LOG_INFO (" Setting up networks {}" , connection.getNetwork ()->getProfile ())
7196 formattedNameservers.reserve (nameservers.size ());
7297 for (const auto & nameserver : nameservers) {
7398 formattedNameservers.emplace_back (nameserver.to_string ());
7499 }
75100
76101 LOG_INFO (" Setting up networks {}" , connection.getNetwork ()->getProfile ())
77- auto opts = options ();
78102 auto connectionName
79103 = cloyster::utils::enums::toString (connection.getNetwork ()->getProfile ());
80- if (!opts->dryRun
81-
82- && runner ()->executeCommand (
83- fmt::format (" nmcli connection show {}" , connectionName))
84- == 0 ) {
85- LOG_WARN (" Connection exists {}, skipping" , connectionName);
86- continue ;
87- }
88-
89- LOG_INFO (" Setting up networks {}" , connection.getNetwork ()->getProfile ())
90-
91104 deleteConnectionIfExists (connectionName);
105+
92106 ::runner ()->executeCommand(
93107 fmt::format (" nmcli device set {} managed yes" , interface));
94108 ::runner ()->executeCommand(
95109 fmt::format (" nmcli device set {} autoconnect yes" , interface));
110+ ::runner ()->executeCommand(
111+ fmt::format (" nmcli connection delete {}" , connection.getNetwork()->getProfile()));
112+
113+ // example
114+ // nmcli connection delete Management; nmcli connection add con-name Management ifname enp2s2 type Ethernet mtu 1500 ipv4.method manual ipv4.address 192.168.30.254/24 ipv4.dns "192.168.122.1"; nmcli device connect enp2s2
96115 ::runner ()->executeCommand(fmt::format(
97- " nmcli connection add con-name {} ifname {} type {} "
98- " mtu {} ipv4.method manual ipv4.address {}/{} "
99- " ipv4.dns \" {}\" "
100- // "ipv4.gateway {} ipv4.dns \"{}\" "
101- // @TODO: CFL only do this if we're using xCAT as provisioner
102- // @FIXME: This will break Confluent, is it required by xCAT?
103- " ipv4.dns-search {} ipv6.method disabled" ,
104- cloyster::utils::enums::toString (
105- connection.getNetwork()->getProfile()),
106- interface,
107- cloyster::utils::enums::toString(
108- connection.getNetwork()->getType()),
109- connection.getMTU(), connection.getAddress().to_string(),
110- connection.getNetwork()->cidr.at(
111- connection.getNetwork()->getSubnetMask().to_string()),
112- // connection.getNetwork()->getGateway().to_string(),
113- fmt::join(formattedNameservers, " " ),
114- connection.getNetwork()->getDomainName()));
116+ " nmcli connection add con-name {connName} ifname {ifname} type {type} "
117+ " mtu {mtu} ipv4.method manual ipv4.address {ip}/{cidr} "
118+ " ipv4.dns \" {dns}\" "
119+ // When I setup the gateway I lost the connection to the VM, so I'm commeting
120+ // it out for now
121+ // "{gw} "
122+ // "ipv4.dns-search {dnsSearch} "
123+ " {ipv6}" ,
124+ fmt::arg (" connName" , cloyster::utils::enums::toString(connection.getNetwork()->getProfile())),
125+ fmt::arg(" ifname" , interface),
126+ fmt::arg(" type" , cloyster::utils::enums::toString(connection.getNetwork()->getType())),
127+ fmt::arg(" mtu" , connection.getMTU()),
128+ fmt::arg(" ip" , connection.getAddress().to_string()),
129+ fmt::arg(" cidr" , connection.getNetwork()->cidr.at(connection.getNetwork()->getSubnetMask().to_string())),
130+ fmt::arg(" dns" , fmt::join(formattedNameservers, " " )),
131+ // fmt::arg("gw", shouldUseGateway
132+ // ? fmt::format("ipv4.gateway {}", connection.getNetwork()->getGateway().to_string())
133+ // : ""),
134+ // fmt::arg("dnsSearch", connection.getNetwork()->getDomainName()),
135+ fmt::arg(" ipv6" , shouldDisableIPV6 ? " ipv6.method disabled" : " " )
136+ ));
115137
116138
117- LOG_INFO (" Setting up networks {}" , connection.getNetwork()->getProfile())
118139 /* Give network manage some time to settle thing up
119140 * Avoids: Error: Connection activation failed: IP configuration could
120141 * not be reserved (no available address, timeout, etc.).
121142 */
122143 std::this_thread::sleep_for (std::chrono::milliseconds(200 ));
123144
124- LOG_INFO (" Setting up networks {}" , connection.getNetwork()->getProfile())
125-
126145 // Breaking my ssh connection during development
127146 runner ()->executeCommand(
128147 fmt::format (" nmcli device connect {}" , interface));
129148
130- LOG_INFO (" Setting up networks {} returning" , connection.getNetwork()->getProfile())
131149 }
132150
133- disableNetworkManagerDNSOverride ();
134151
135152}
136153
0 commit comments