-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite commit tracking API and plugin (sima)
Upon `apply` action, a NetworkCommit will be created and send to plugin with role `NipartRole::Commit`. The NetworkCommit holds: * `id`: NipartUuid (internal is u128) * `time`: time in UTC timezone. * `desired_state`: User defined state Instead of using git as storage backend in sima plugin, we use: * /var/lib/nipart/commits # holding all commits * /var/lib/nipart/post_apply_state.yml # full running state after last commit For CLI user: * `nipc show`: Current running full network state * `nipc show --diff`: Get changed state since last commit * `nipc show --saved`: Get stored network state merged from all commits * `nipc apply --diff`: Apply changed state since last commit * `nipc commit show`: Show all network commits * `nipc commit show <id>`: Show specified commit * `nipc commit revert <id>`: Add new commit to revert changes of specified commit. * `nipc commit remove <id>..`: Remove specified commits. * `nipc commit rollback <id>`: Rollback to specified commit, all commit after it will be reverted and removed. For sys-admin user: * TODO: Place YAML to /etc/nipart/states folder and then `nipc daemon reload` will commit YAMLs base on the alphabet order of filename. Signed-off-by: Gris Ge <[email protected]>
- Loading branch information
Showing
47 changed files
with
2,337 additions
and
909 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
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,36 @@ | ||
* Checkpoint | ||
* /etc/nipart/conf.d/ for choosing which DHCP plugin to load | ||
* Native plugin should has its own log postfix | ||
* Wait online | ||
|
||
``` | ||
wait-onlines: | ||
- global: | ||
- link | ||
- name: link | ||
type: link | ||
timeout: 30 # maximum wait for link up of interfaces | ||
post-sleep: 1 # sleep after link up of all interfaces before notify | ||
links: | ||
- all | ||
- name: arp | ||
type: arp | ||
addresses: | ||
- 192.168.1.1 | ||
- name: nfs | ||
type: ping | ||
addresses: | ||
- 192.168.1.1 | ||
- name: dns | ||
type: dns-resolve | ||
dns-reoslve: | ||
- www.example.com | ||
``` | ||
|
||
* Isolate secrets to separate file | ||
* Stealth(Minimum footprint) mode | ||
* DBUS API | ||
* NM1 Keyfile support | ||
* Instead process NipartEvent in `handle_event()`, we should provide | ||
default implementation of each event type as function in | ||
`NipartNativePlugin` and `NipartExternalPlugin`. |
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,61 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use nipart::{NipartApplyOption, NipartConnection}; | ||
|
||
use crate::{show::ShowCommand, state::state_from_file, CliError}; | ||
|
||
pub(crate) struct ApplyCommand; | ||
|
||
impl ApplyCommand { | ||
pub(crate) const NAME: &str = "apply"; | ||
|
||
pub(crate) fn gen_command() -> clap::Command { | ||
clap::Command::new("apply") | ||
.alias("set") | ||
.alias("a") | ||
.about("Apply network config") | ||
.arg( | ||
clap::Arg::new("STATE_FILE") | ||
.required(false) | ||
.index(1) | ||
.help("Network state file"), | ||
) | ||
.arg( | ||
clap::Arg::new("MEMORY_ONLY") | ||
.long("memory-only") | ||
.action(clap::ArgAction::SetTrue) | ||
.required(false) | ||
.help("Do not make the state persistent"), | ||
) | ||
.arg( | ||
clap::Arg::new("DIFF") | ||
.long("diff") | ||
.action(clap::ArgAction::SetTrue) | ||
.required(false) | ||
.help("Apply changed state since last commit"), | ||
) | ||
} | ||
|
||
pub(crate) async fn handle( | ||
matches: &clap::ArgMatches, | ||
) -> Result<(), CliError> { | ||
let mut conn = NipartConnection::new().await?; | ||
let state = | ||
if let Some(file_path) = matches.get_one::<String>("STATE_FILE") { | ||
state_from_file(file_path)? | ||
} else if matches.get_flag("DIFF") { | ||
let mut state = ShowCommand::get_diff_state(&mut conn).await?; | ||
state.description = format!("nipc apply --diff"); | ||
state | ||
} else { | ||
state_from_file("-")? | ||
}; | ||
let mut opt = NipartApplyOption::default(); | ||
if matches.get_flag("MEMORY_ONLY") { | ||
opt.memory_only = true; | ||
} | ||
conn.apply_net_state(state.clone(), opt).await?; | ||
println!("{}", serde_yaml::to_string(&state)?); | ||
Ok(()) | ||
} | ||
} |
Oops, something went wrong.