forked from agama-project/agama
-
Notifications
You must be signed in to change notification settings - Fork 1
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 #4 from jcronenberg/migrate-wicked-cli
Implement a separate cli for wicked to NM migration
- Loading branch information
Showing
8 changed files
with
133 additions
and
12 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,11 @@ | ||
# Migrate wicked | ||
This project creates a `migrate-wicked` binary which is able to parse wicked xml configs and send them to a NetworkManager dbus service. | ||
## Architecture | ||
`migrate-wicked` uses agama as a library to communicate the parsed network state to NetworkManager | ||
but the binary is completely independent of any agama services and can be run standalone | ||
## Obtaining wicked xml config | ||
A wicked config xml can be generated by running `wicked show-config > wicked.xml` which can then be passed to `migrate-wicked` | ||
## Testing | ||
Running the migration on a live system isn't currently recommended. To test it's recommended to use a container | ||
(instructions how to set one up can be found [here](https://github.com/openSUSE/agama/blob/master/rust/agama-cli/doc/backend-for-testing.md)) | ||
Example configurations can be found under `tests` |
This file was deleted.
Oops, something went wrong.
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,106 @@ | ||
mod interface; | ||
mod migrate; | ||
mod reader; | ||
|
||
use clap::builder::TypedValueParser; | ||
use clap::{Args, Parser, Subcommand}; | ||
use log::*; | ||
use migrate::migrate; | ||
use reader::read as wicked_read; | ||
use std::process::{ExitCode, Termination}; | ||
|
||
#[derive(Parser)] | ||
#[command(name = "migrate-wicked", version, about, long_about = None)] | ||
struct Cli { | ||
#[clap(flatten)] | ||
global_opts: GlobalOpts, | ||
|
||
#[command(subcommand)] | ||
pub command: Commands, | ||
} | ||
|
||
#[derive(Debug, Args)] | ||
struct GlobalOpts { | ||
#[arg(long, global = true, default_value_t = LevelFilter::Error, value_parser = clap::builder::PossibleValuesParser::new(["TRACE", "DEBUG", "INFO", "WARN", "ERROR"]).map(|s| s.parse::<LevelFilter>().unwrap()),)] | ||
pub log_level: LevelFilter, | ||
} | ||
|
||
#[derive(Subcommand)] | ||
pub enum Commands { | ||
/// Shows the current xml wicked configuration | ||
Show { | ||
/// Format output | ||
#[arg(value_enum, short, long, default_value_t = Format::Json)] | ||
format: Format, | ||
|
||
/// Path to file or directory where the wicked xml config is located | ||
path: String, | ||
}, | ||
/// Migrate wicked state at path | ||
Migrate { | ||
/// Path to file or directory where the wicked xml config is located | ||
path: String, | ||
}, | ||
} | ||
|
||
/// Supported output formats | ||
#[derive(clap::ValueEnum, Clone)] | ||
pub enum Format { | ||
Json, | ||
PrettyJson, | ||
Yaml, | ||
Text, | ||
} | ||
|
||
async fn run_command(cli: Cli) -> anyhow::Result<()> { | ||
match cli.command { | ||
Commands::Show { path, format } => { | ||
let interfaces = wicked_read(path.into()).await?; | ||
let output: String = match format { | ||
Format::Json => serde_json::to_string(&interfaces)?, | ||
Format::PrettyJson => serde_json::to_string_pretty(&interfaces)?, | ||
Format::Yaml => serde_yaml::to_string(&interfaces)?, | ||
Format::Text => format!("{:?}", interfaces), | ||
}; | ||
println!("{}", output); | ||
Ok(()) | ||
} | ||
Commands::Migrate { path } => { | ||
migrate(path).await.unwrap(); | ||
Ok(()) | ||
} | ||
} | ||
} | ||
|
||
/// Represents the result of execution. | ||
pub enum CliResult { | ||
/// Successful execution. | ||
Ok = 0, | ||
/// Something went wrong. | ||
Error = 1, | ||
} | ||
|
||
impl Termination for CliResult { | ||
fn report(self) -> ExitCode { | ||
ExitCode::from(self as u8) | ||
} | ||
} | ||
|
||
#[async_std::main] | ||
async fn main() -> CliResult { | ||
let cli = Cli::parse(); | ||
|
||
simplelog::TermLogger::init( | ||
cli.global_opts.log_level, | ||
simplelog::Config::default(), | ||
simplelog::TerminalMode::Stderr, | ||
simplelog::ColorChoice::Auto, | ||
) | ||
.unwrap(); | ||
|
||
if let Err(error) = run_command(cli).await { | ||
eprintln!("{:?}", error); | ||
return CliResult::Error; | ||
} | ||
CliResult::Ok | ||
} |