Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 10 additions & 0 deletions doc/flake-ctl-firecracker-register.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ SYNOPSIS

OPTIONS:
--app <APP>
--force
--include-tar <INCLUDE_TAR>...
--include-path <INCLUDE_PATH>...
--no-net
Expand Down Expand Up @@ -52,6 +53,15 @@ OPTIONS
the target option, the application will be called with that path inside
of the VM

--force

Force writing the registration even if a registration
of the same name already exists. This is done by deleting
an eventual existing registration prio creating the new
registration. Please have in mind that a failed registration
still causes an eventual existing former registration to be
deleted in this case !

--include-tar <INCLUDE_TAR>...

Name of a tar file to be included on top of the VM instance.
Expand Down
11 changes: 9 additions & 2 deletions doc/flake-ctl-list.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,22 @@ SYNOPSIS
flake-ctl list

OPTIONS:
-h, --help Print help information
-V, --version Print version information
--user
--help


DESCRIPTION
-----------

List registered flake applications.

OPTIONS
-------

--user

List registered flake applications for the calling user

FILES
-----

Expand Down
15 changes: 14 additions & 1 deletion doc/flake-ctl-podman-register.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ SYNOPSIS
.. code:: bash

USAGE:
flake-ctl podman register [OPTIONS] --container <CONTAINER> --app <APP>
flake-ctl podman [--user] register [OPTIONS] --container <CONTAINER> --app <APP>

OPTIONS:
--app <APP>
--attach
--base <BASE>
--check_host_dependencies
--container <CONTAINER>
--force
--include-tar <INCLUDE_TAR>...
--include-path <INCLUDE_PATH>...
--info
Expand All @@ -44,6 +45,9 @@ like a normal application on this host.
For further details about the flake configuration please refer to
the **podman-pilot** manual page.

For further details about the flake configuration when `--user` is
used please refer to the **flake-pilot** manual page.

NOTE
----

Expand Down Expand Up @@ -81,6 +85,15 @@ OPTIONS
Check if the container has dependencies to the host When using
a base container this check is enabled by default.

--force

Force writing the registration even if a registration
of the same name already exists. This is done by deleting
an eventual existing registration prio creating the new
registration. Please have in mind that a failed registration
still causes an eventual existing former registration to be
deleted in this case !

--include-tar <INCLUDE_TAR>...

Name of a tar file to be included on top of the container instance.
Expand Down
62 changes: 40 additions & 22 deletions flake-ctl/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ pub fn create_vm_config(
}

pub fn remove(
app: &str, engine: &str, usermode: bool, silent: bool
app: &str, engine: &str, usermode: bool, silent: bool, force: bool
) -> bool {
/*!
Delete application link and config files
Expand All @@ -242,40 +242,58 @@ pub fn remove(
"{}/{}.d", get_flakes_dir(usermode), &app_basename
);
if ! Path::new(&config_file).exists() {
error!("No app config file found: {config_file}");
if !silent {
error!("No app config file found: {config_file}");
}
return false
}
if ! Path::new(&app_config_dir).exists() {
error!("No app directory found: {app_config_dir}");
if !silent {
error!("No app directory found: {app_config_dir}");
}
return false
}

// remove pilot link if valid
match fs::read_link(app) {
Ok(link_name) => {
if link_name.into_os_string() == engine {
match fs::remove_file(app) {
Ok(_) => {}
Err(error) => {
if !silent {
error!("Error removing pilot link: {app}: {error:?}");
};
return false
if force {
match fs::remove_file(app) {
Ok(_) => {}
Err(error) => {
if !silent {
error!("Error removing: {app}: {error:?}");
};
return false
}
}
} else {
// remove pilot link if valid
match fs::read_link(app) {
Ok(link_name) => {
if link_name.into_os_string() == engine {
match fs::remove_file(app) {
Ok(_) => {}
Err(error) => {
if !silent {
error!(
"Error removing pilot link: {app}: {error:?}"
);
};
return false
}
}
} else {
if !silent {
error!("Symlink not pointing to {engine}: {app}");
};
return false
}
} else {
}
Err(error) => {
if !silent {
error!("Symlink not pointing to {engine}: {app}");
error!("Failed to read as symlink: {app}: {error:?}");
};
return false
}
}
Err(error) => {
if !silent {
error!("Failed to read as symlink: {app}: {error:?}");
};
return false
}
}
// remove config file and config directory
match fs::remove_file(&config_file) {
Expand Down
10 changes: 10 additions & 0 deletions flake-ctl/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,11 @@ pub enum Firecracker {
/// specified multiple times.
#[clap(long, multiple = true, requires = "overlay-size")]
include_path: Option<Vec<String>>,

/// Force writing the registration even if a registration
/// of the same name already exists
#[clap(long)]
force: bool,
},
/// Remove application registration or entire VM
#[clap(group(
Expand Down Expand Up @@ -311,6 +316,11 @@ pub enum Podman {
/// Print registration information from container if provided
#[clap(long)]
info: bool,

/// Force writing the registration even if a registration
/// of the same name already exists
#[clap(long)]
force: bool,
},
}

Expand Down
2 changes: 1 addition & 1 deletion flake-ctl/src/firecracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ pub fn purge_vm(vm: &str) {
{
app::remove(
&app_conf.vm.as_mut().unwrap().host_app_path,
defaults::FIRECRACKER_PILOT, false, false
defaults::FIRECRACKER_PILOT, false, false, false
);
}
},
Expand Down
82 changes: 53 additions & 29 deletions flake-ctl/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,17 @@ async fn main() -> Result<ExitCode, Box<dyn std::error::Error>> {
// register
cli::Firecracker::Register {
vm, app, target, run_as, overlay_size, no_net, resume,
force_vsock, include_tar, include_path
force_vsock, include_tar, include_path, force
} => {
if *force {
app::remove(
app,
defaults::FIRECRACKER_PILOT,
false,
true,
*force
);
}
if app::init(Some(app), false) {
let mut ok = app::register(
Some(app), target.as_ref(),
Expand All @@ -117,7 +126,8 @@ async fn main() -> Result<ExitCode, Box<dyn std::error::Error>> {
app::remove(
app, defaults::FIRECRACKER_PILOT,
false,
true
true,
*force
);
return Ok(ExitCode::FAILURE)
}
Expand All @@ -131,6 +141,7 @@ async fn main() -> Result<ExitCode, Box<dyn std::error::Error>> {
app.as_ref().map(String::as_str).unwrap(),
defaults::FIRECRACKER_PILOT,
false,
false,
false
) {
return Ok(ExitCode::FAILURE)
Expand Down Expand Up @@ -165,43 +176,55 @@ async fn main() -> Result<ExitCode, Box<dyn std::error::Error>> {
cli::Podman::Register {
container, app, target, base, check_host_dependencies,
layer, include_tar, include_path, resume, attach,
opt, info
opt, info, force
} => {
if *info {
podman::print_container_info(container);
} else if app::init(app.as_ref(), user) {
let mut ok = app::register(
app.as_ref(), target.as_ref(),
defaults::PODMAN_PILOT,
user
);
if ok {
ok = app::create_container_config(
container,
app.as_ref(),
target.as_ref(),
base.as_ref(),
*check_host_dependencies,
layer.as_ref().cloned(),
include_tar.as_ref().cloned(),
include_path.as_ref().cloned(),
*resume,
*attach,
user,
opt.as_ref().cloned()
);
}
if ! ok {
} else {
if *force {
app::remove(
app.as_ref().map(String::as_str).unwrap(),
defaults::PODMAN_PILOT,
user,
true
true,
*force
);
}
if app::init(app.as_ref(), user) {
let mut ok = app::register(
app.as_ref(), target.as_ref(),
defaults::PODMAN_PILOT,
user
);
if ok {
ok = app::create_container_config(
container,
app.as_ref(),
target.as_ref(),
base.as_ref(),
*check_host_dependencies,
layer.as_ref().cloned(),
include_tar.as_ref().cloned(),
include_path.as_ref().cloned(),
*resume,
*attach,
user,
opt.as_ref().cloned(),
);
}
if ! ok {
app::remove(
app.as_ref().map(String::as_str).unwrap(),
defaults::PODMAN_PILOT,
user,
true,
*force
);
return Ok(ExitCode::FAILURE)
}
} else {
return Ok(ExitCode::FAILURE)
}
} else {
return Ok(ExitCode::FAILURE)
}
},
// remove
Expand All @@ -210,6 +233,7 @@ async fn main() -> Result<ExitCode, Box<dyn std::error::Error>> {
app.as_ref().map(String::as_str).unwrap(),
defaults::PODMAN_PILOT,
user,
false,
false
) {
return Ok(ExitCode::FAILURE)
Expand Down
1 change: 1 addition & 0 deletions flake-ctl/src/podman.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ pub fn purge_container(container: &str, usermode: bool) {
&app_conf.container.as_mut().unwrap().host_app_path,
defaults::PODMAN_PILOT,
usermode,
false,
false
);
}
Expand Down