Skip to content

Commit 36832fe

Browse files
sysvioncgwalters
authored andcommitted
project | libvirt: Minor config changes
I have changed some config changes like setting a default filesystem to make it more aligned to what the code says. And what my expectations are. libvirt: - add default filesystem var. (ext4 because it is allready used) - libvirt run: use default filesystem (Add by ai. Not manualy checked. Maybe i shouldn't use it.) project up: - use default fs - use relative path project down: - add --force flag that is passed down to libvirt functions - inlined functions Assisted-by: Cursor's automatic modelswicher Signed-off-by: Colin Walters <[email protected]>
1 parent 94ce1f1 commit 36832fe

File tree

5 files changed

+33
-30
lines changed

5 files changed

+33
-30
lines changed

crates/kit/src/libvirt/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ pub const LIBVIRT_DEFAULT_MEMORY: &str = "4G";
2323
/// Default disk size for libvirt base disks
2424
pub const LIBVIRT_DEFAULT_DISK_SIZE: &str = "20G";
2525

26+
/// Default filesystem for libvirt VMs
27+
pub const LIBVIRT_DEFAULT_FILESYSTEM: &str = "ext4";
28+
2629
pub mod base_disks;
2730
pub mod base_disks_cli;
2831
pub mod domain;

crates/kit/src/libvirt/run.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,7 @@ fn create_libvirt_domain_from_disk(
10031003
opts.install
10041004
.filesystem
10051005
.as_ref()
1006-
.unwrap_or(&"ext4".to_string()),
1006+
.unwrap_or(&crate::libvirt::LIBVIRT_DEFAULT_FILESYSTEM.to_string()),
10071007
)
10081008
.with_metadata("bootc:network", &opts.network)
10091009
.with_metadata("bootc:ssh-generated", "true")

crates/kit/src/project/down.rs

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ pub struct ProjectDownOpts {
1919
/// Remove the VM after shutting it down
2020
#[clap(long)]
2121
pub remove: bool,
22+
23+
#[clap(long)]
24+
pub force: bool,
2225
}
2326

2427
/// Run the project down command
@@ -38,18 +41,31 @@ pub fn run(opts: ProjectDownOpts) -> Result<()> {
3841
};
3942

4043
if !check_vm_exists(&vm_name, &libvirt_opts)? {
41-
println!("Project VM '{}' does not exist", vm_name);
44+
println!("Project is already down. vm_name: '{}'", vm_name);
4245
return Ok(());
4346
}
4447

4548
// Stop the VM
4649
println!("Shutting down project VM '{}'...", vm_name);
47-
stop_vm(&vm_name, &libvirt_opts)?;
50+
51+
let stop_opts = libvirt::stop::LibvirtStopOpts {
52+
name: vm_name.to_string(),
53+
force: opts.force,
54+
timeout: 60,
55+
};
56+
57+
let _ = libvirt::stop::run(&libvirt_opts, stop_opts);
4858

4959
// Remove if requested
5060
if opts.remove {
5161
println!("Removing project VM '{}'...", vm_name);
52-
remove_vm(&vm_name, &libvirt_opts)?;
62+
let rm_opts = libvirt::rm::LibvirtRmOpts {
63+
name: vm_name.to_string(),
64+
force: opts.force,
65+
stop: false,
66+
};
67+
68+
libvirt::rm::run(&libvirt_opts, rm_opts)?
5369
}
5470

5571
Ok(())
@@ -68,25 +84,3 @@ fn check_vm_exists(name: &str, libvirt_opts: &LibvirtOptions) -> Result<bool> {
6884

6985
Ok(domains.iter().any(|d| d.name == name))
7086
}
71-
72-
/// Stop a VM
73-
fn stop_vm(name: &str, libvirt_opts: &LibvirtOptions) -> Result<()> {
74-
let stop_opts = libvirt::stop::LibvirtStopOpts {
75-
name: name.to_string(),
76-
force: false,
77-
timeout: 60,
78-
};
79-
80-
libvirt::stop::run(libvirt_opts, stop_opts)
81-
}
82-
83-
/// Remove a VM
84-
fn remove_vm(name: &str, libvirt_opts: &LibvirtOptions) -> Result<()> {
85-
let rm_opts = libvirt::rm::LibvirtRmOpts {
86-
name: name.to_string(),
87-
force: false,
88-
stop: false,
89-
};
90-
91-
libvirt::rm::run(libvirt_opts, rm_opts)
92-
}

crates/kit/src/project/up.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,11 @@ fn create_vm(
219219
extra_smbios_credentials: vec![],
220220
};
221221

222-
if let Some(ref fs) = vm.filesystem {
223-
run_opts.install.filesystem = Some(fs.clone());
224-
}
222+
run_opts.install.filesystem = Some(
223+
vm.filesystem
224+
.clone()
225+
.unwrap_or_else(|| crate::libvirt::LIBVIRT_DEFAULT_FILESYSTEM.to_string()),
226+
);
225227

226228
// Bind project directory to /run/src read-only with auto-mount
227229
// (will fall back to read-write if libvirt doesn't support readonly virtiofs)
@@ -233,7 +235,7 @@ fn create_vm(
233235

234236
// Add configured mounts using bind mount options
235237
for mount in config.mounts.iter().flatten() {
236-
let mount_spec = format!("{}:{}", mount.host, mount.guest);
238+
let mount_spec = format!("{}/{}:{}", project_dir.as_str(), mount.host, mount.guest);
237239
let bind_mount = mount_spec
238240
.parse()
239241
.with_context(|| format!("Failed to parse mount spec: {}", mount_spec))?;

docs/src/man/bcvk-project-down.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ Shut down the project VM
2121

2222
Remove the VM after shutting it down
2323

24+
**--force**
25+
26+
27+
2428
<!-- END GENERATED OPTIONS -->
2529

2630
# EXAMPLES

0 commit comments

Comments
 (0)