Skip to content
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

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target/
Copy link
Collaborator

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.

Copy link
Author

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

Copy link
Collaborator

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.

Copy link
Author

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 the target/ 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.

7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ network-interface = "2.0.0"
nmstate = { version = "2.2.36", features = ["gen_conf"] }
serde = { version = "1.0.210", features = ["derive"] }
serde_yaml = "0.9.34"
configparser = "3.1.0"
62 changes: 45 additions & 17 deletions src/apply_conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()]);
Copy link
Collaborator

Choose a reason for hiding this comment

The 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 connections_id?

Copy link
Author

Choose a reason for hiding this comment

The 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 connection_ids.

See also the example

    - logical_name: ovs0
      connection_ids:
        - ovs0-port
        - ovs0-if
      interface_type: ovs-interface

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't there an ovs0.nmconnection file that we don't copy over with the current implementation?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ovs0.nmconnection is not generated by nmstate. When applying this configuration with the current implementation you'll get an error like described in #113 because the file is missing


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(())
Expand Down Expand Up @@ -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 {
Expand All @@ -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,
}],
},
];
Expand All @@ -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,
}]
);
}
Expand All @@ -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 {
Expand All @@ -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,
}],
},
];
Expand Down Expand Up @@ -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,
},
],
},
Expand All @@ -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,
},
],
},
Expand All @@ -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,
},
],
};
Expand Down Expand Up @@ -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,
},
],
};
Expand Down
Loading