-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for multiple connection files per logical interface #114
base: main
Are you sure you want to change the base?
Changes from 3 commits
33aad3b
9a8b97d
425f1f5
4ad178b
13a168b
d7a5d2b
ed6ded9
8e27a63
68418be
cd7f3b3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
target/ | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -183,29 +183,36 @@ fn copy_connection_files( | |
|
||
for interface in &host.interfaces { | ||
info!("Processing interface '{}'...", &interface.logical_name); | ||
let connections = &interface | ||
.connection_ids | ||
.clone() | ||
koendelaat marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.unwrap_or(vec![interface.logical_name.clone()]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it safer to always include the logical name? Do we anticipate that it will always be present in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added the logical_name here as a fallback mechanism mainly for backwards compatibility. Although I doubt if we need backwards compatibility (I assume same NMC version is used for generating and applying). No, the logical name won't be always present in the See also the example - logical_name: ovs0
connection_ids:
- ovs0-port
- ovs0-if
interface_type: ovs-interface There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't there an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
let mut filename = &interface.logical_name; | ||
for connection in connections { | ||
info!("Processing connection '{}'...", connection); | ||
let mut filename = connection.clone(); | ||
|
||
let filepath = keyfile_path(host_config_dir, filename) | ||
.ok_or_else(|| anyhow!("Determining source keyfile path"))?; | ||
let filepath = keyfile_path(host_config_dir, &filename) | ||
.ok_or_else(|| anyhow!("Determining source keyfile path"))?; | ||
|
||
let mut contents = fs::read_to_string(filepath).context("Reading file")?; | ||
let mut contents = fs::read_to_string(filepath).context("Reading file")?; | ||
|
||
// Update the name and all references of the host NIC in the settings file if there is a difference from the static config. | ||
match local_interfaces.get(&interface.logical_name) { | ||
None => {} | ||
Some(local_name) => { | ||
info!( | ||
"Using interface name '{}' instead of the preconfigured '{}'", | ||
local_name, interface.logical_name | ||
); | ||
|
||
contents = contents.replace(&interface.logical_name, local_name); | ||
filename = local_name; | ||
// Update the name and all references of the host NIC in the settings file if there is a difference from the static config. | ||
match local_interfaces.get(&interface.logical_name) { | ||
None => {} | ||
Some(local_name) => { | ||
info!( | ||
"Using interface name '{}' instead of the preconfigured '{}'", | ||
local_name, interface.logical_name | ||
); | ||
|
||
contents = contents.replace(&interface.logical_name, local_name); | ||
filename = filename.replace(&interface.logical_name, local_name); | ||
koendelaat marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
} | ||
|
||
store_connection_file(filename, contents, destination_dir).context("Storing file")?; | ||
store_connection_file(&filename, contents, destination_dir).context("Storing file")?; | ||
} | ||
} | ||
|
||
Ok(()) | ||
|
@@ -302,6 +309,7 @@ mod tests { | |
logical_name: "eth0".to_string(), | ||
mac_address: Option::from("00:11:22:33:44:55".to_string()), | ||
interface_type: "ethernet".to_string(), | ||
connection_ids: None, | ||
koendelaat marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}], | ||
}, | ||
Host { | ||
|
@@ -310,6 +318,7 @@ mod tests { | |
logical_name: "".to_string(), | ||
mac_address: Option::from("10:10:10:10:10:10".to_string()), | ||
interface_type: "".to_string(), | ||
connection_ids: None, | ||
}], | ||
}, | ||
]; | ||
|
@@ -336,6 +345,7 @@ mod tests { | |
logical_name: "eth0".to_string(), | ||
mac_address: Option::from("00:11:22:33:44:55".to_string()), | ||
interface_type: "ethernet".to_string(), | ||
connection_ids: None, | ||
}] | ||
); | ||
} | ||
|
@@ -349,6 +359,7 @@ mod tests { | |
logical_name: "eth0".to_string(), | ||
mac_address: Option::from("10:20:30:40:50:60".to_string()), | ||
interface_type: "ethernet".to_string(), | ||
connection_ids: None, | ||
}], | ||
}, | ||
Host { | ||
|
@@ -357,6 +368,7 @@ mod tests { | |
logical_name: "".to_string(), | ||
mac_address: Option::from("00:10:20:30:40:50".to_string()), | ||
interface_type: "".to_string(), | ||
connection_ids: None, | ||
}], | ||
}, | ||
]; | ||
|
@@ -389,21 +401,25 @@ mod tests { | |
logical_name: "eth0".to_string(), | ||
mac_address: Option::from("00:11:22:33:44:55".to_string()), | ||
interface_type: "ethernet".to_string(), | ||
connection_ids: None, | ||
}, | ||
Interface { | ||
logical_name: "eth1".to_string(), | ||
mac_address: Option::from("00:11:22:33:44:58".to_string()), | ||
interface_type: "ethernet".to_string(), | ||
connection_ids: None, | ||
}, | ||
Interface { | ||
logical_name: "eth2".to_string(), | ||
mac_address: Option::from("36:5e:6b:a2:ed:80".to_string()), | ||
interface_type: "ethernet".to_string(), | ||
connection_ids: None, | ||
}, | ||
Interface { | ||
logical_name: "bond0".to_string(), | ||
mac_address: Option::from("00:11:22:aa:44:58".to_string()), | ||
interface_type: "bond".to_string(), | ||
connection_ids: None, | ||
}, | ||
], | ||
}, | ||
|
@@ -414,11 +430,13 @@ mod tests { | |
logical_name: "eth0".to_string(), | ||
mac_address: Option::from("36:5e:6b:a2:ed:81".to_string()), | ||
interface_type: "ethernet".to_string(), | ||
connection_ids: None, | ||
}, | ||
Interface { | ||
logical_name: "eth0.1365".to_string(), | ||
mac_address: None, | ||
interface_type: "vlan".to_string(), | ||
connection_ids: None, | ||
}, | ||
], | ||
}, | ||
|
@@ -435,26 +453,31 @@ mod tests { | |
logical_name: "eth0".to_string(), | ||
mac_address: Option::from("00:11:22:33:44:55".to_string()), | ||
interface_type: "ethernet".to_string(), | ||
connection_ids: None, | ||
}, | ||
Interface { | ||
logical_name: "eth0.1365".to_string(), | ||
mac_address: None, | ||
interface_type: "vlan".to_string(), | ||
connection_ids: None, | ||
}, | ||
Interface { | ||
logical_name: "eth2".to_string(), | ||
mac_address: Option::from("00:11:22:33:44:56".to_string()), | ||
interface_type: "ethernet".to_string(), | ||
connection_ids: None, | ||
}, | ||
Interface { | ||
logical_name: "eth2.bridge".to_string(), | ||
mac_address: None, | ||
interface_type: "linux-bridge".to_string(), | ||
connection_ids: None, | ||
}, | ||
Interface { | ||
logical_name: "bond0".to_string(), | ||
mac_address: Option::from("00:11:22:33:44:58".to_string()), | ||
interface_type: "bond".to_string(), | ||
connection_ids: None, | ||
}, | ||
], | ||
}; | ||
|
@@ -522,26 +545,31 @@ mod tests { | |
logical_name: "eth0".to_string(), | ||
mac_address: Option::from("00:11:22:33:44:55".to_string()), | ||
interface_type: "ethernet".to_string(), | ||
connection_ids: None, | ||
}, | ||
Interface { | ||
logical_name: "eth0.1365".to_string(), | ||
mac_address: None, | ||
interface_type: "vlan".to_string(), | ||
connection_ids: None, | ||
}, | ||
Interface { | ||
logical_name: "eth2".to_string(), | ||
mac_address: Option::from("00:11:22:33:44:56".to_string()), | ||
interface_type: "ethernet".to_string(), | ||
connection_ids: None, | ||
}, | ||
Interface { | ||
logical_name: "eth1".to_string(), | ||
mac_address: Option::from("00:11:22:33:44:57".to_string()), | ||
interface_type: "ethernet".to_string(), | ||
connection_ids: None, | ||
}, | ||
Interface { | ||
logical_name: "bond0".to_string(), | ||
mac_address: Option::from("00:11:22:33:44:58".to_string()), | ||
interface_type: "bond".to_string(), | ||
connection_ids: None, | ||
}, | ||
], | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can probably get rid of this file as we never build nmc in a container.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I added it because the CI builds a container, and when I tried locally this was a speedup
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is interesting, I wasn't aware it could be a speedup locally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When built locally, a lot of files are created in the
target/
directory. When trying to build the dockerimage, all the files in thetarget/
directory are copied over to the docker build context. This takes "long" for > 1GB of data...So this was just a quick fix to remediate this issue. I'm also fine by removing it as we don't need the docker image in the end.