-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #503 from flouthoc/netavark-network-update
update: add support for `netavark update` command
- Loading branch information
Showing
8 changed files
with
177 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod setup; | ||
pub mod teardown; | ||
pub mod update; | ||
pub mod version; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
use crate::dns::aardvark::Aardvark; | ||
use crate::error::{NetavarkError, NetavarkResult}; | ||
use crate::network::core_utils; | ||
|
||
use clap::Parser; | ||
use log::debug; | ||
use std::path::Path; | ||
|
||
#[derive(Parser, Debug)] | ||
pub struct Update { | ||
/// Network name to update | ||
#[clap(forbid_empty_values = true, required = true)] | ||
network_name: String, | ||
/// DNS Servers to update for the network | ||
#[clap(long, required = true, forbid_empty_values = true)] | ||
network_dns_servers: Vec<String>, | ||
} | ||
|
||
impl Update { | ||
/// Updates network dns servers for an already configured network | ||
pub fn new(network_name: String, network_dns_servers: Vec<String>) -> Self { | ||
Self { | ||
network_name, | ||
network_dns_servers, | ||
} | ||
} | ||
|
||
pub fn exec( | ||
&self, | ||
config_dir: String, | ||
aardvark_bin: String, | ||
rootless: bool, | ||
) -> NetavarkResult<()> { | ||
let dns_port = core_utils::get_netavark_dns_port()?; | ||
|
||
if Path::new(&aardvark_bin).exists() { | ||
let path = Path::new(&config_dir).join("aardvark-dns"); | ||
if let Ok(path_string) = path.into_os_string().into_string() { | ||
let aardvark_interface = | ||
Aardvark::new(path_string, rootless, aardvark_bin, dns_port); | ||
if let Err(err) = aardvark_interface | ||
.modify_network_dns_servers(&self.network_name, &self.network_dns_servers) | ||
{ | ||
return Err(NetavarkError::wrap( | ||
"unable to modify network dns servers", | ||
NetavarkError::Io(err), | ||
)); | ||
} | ||
} else { | ||
return Err(NetavarkError::msg( | ||
"Unable to parse aardvark config directory", | ||
)); | ||
} | ||
} | ||
|
||
debug!("Network update complete"); | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters