Skip to content

Commit

Permalink
Rewrite commit tracking API and plugin (sima)
Browse files Browse the repository at this point in the history
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
cathay4t committed Jan 21, 2025
1 parent 97ec700 commit 1e1d6f1
Show file tree
Hide file tree
Showing 47 changed files with 2,337 additions and 909 deletions.
9 changes: 3 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ serde_json = "1.0.87"
serde_yaml = "0.9.27"
uuid = { version = "1.6.1", default-features = false, features = ["std", "v7"] }
futures = {version = "0.3.29", features = [ "std" ] }
clap = { version = "4.4" }
nispor = { version = "1.2", git = "https://github.com/nispor/nispor" }
#nispor = { version = "1.2", path = "../nispor/src/lib" }
clap = { version = "4.5" }
nispor = { version = "1.2" }
chrono = { version = "0.4" , features = ["serde"]}

[workspace.dependencies.tokio]
version ="1.35.0"
Expand Down Expand Up @@ -68,6 +68,3 @@ version = "0.19.0"

[workspace.dependencies.futures_channel]
version = "0.3.30"

[workspace.dependencies.gix]
version = "0.63.0"
33 changes: 33 additions & 0 deletions TODO.md
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`.
1 change: 1 addition & 0 deletions src/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ serde_yaml = { workspace = true }
tokio = { workspace = true }
nipart = { path = "../lib", version = "0.1" }
clap = { workspace = true }
chrono = { workspace = true }

[[bin]]
name = "nipc"
Expand Down
61 changes: 61 additions & 0 deletions src/cli/apply.rs
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(())
}
}
Loading

0 comments on commit 1e1d6f1

Please sign in to comment.