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
11 changes: 3 additions & 8 deletions crates/kit/src/domain_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
//! This module provides functionality to list libvirt domains created by bcvk libvirt,
//! using libvirt as the source of truth instead of the VmRegistry cache.

use crate::libvirt::virsh::VirshCommand;
use crate::xml_utils;
use base64::Engine;
use color_eyre::{eyre::Context, Result};
use serde::{Deserialize, Serialize};
use std::process::Command;
use std::time::SystemTime;

/// Information about a podman-bootc domain from libvirt
Expand Down Expand Up @@ -87,13 +87,8 @@ impl DomainLister {
}

/// Build a virsh command with optional connection URI
fn virsh_command(&self) -> Command {
let mut cmd = Command::new("virsh");
cmd.env("LC_ALL", "C");
if let Some(ref uri) = self.connect_uri {
cmd.arg("-c").arg(uri);
}
cmd
fn virsh_command(&self) -> VirshCommand {
VirshCommand::new(self.connect_uri.as_deref())
}

/// List all domains (running and inactive)
Expand Down
4 changes: 2 additions & 2 deletions crates/kit/src/libvirt/list_volumes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
//! This module provides functionality to discover and list bootc volumes
//! with their container image metadata and creation information.

use crate::libvirt::virsh::VirshCommand;
use clap::Parser;
use color_eyre::{eyre::eyre, Result};
use comfy_table::{presets::UTF8_FULL, Table};
use serde_json::{json, Value};
use std::process::Command;
use tracing::{debug, warn};

/// Configuration options for listing bootc volumes
Expand Down Expand Up @@ -71,7 +71,7 @@ impl BootcVolume {

impl LibvirtListVolumesOpts {
/// Build a virsh command with optional connection URI
fn virsh_command(&self, global_opts: &crate::libvirt::LibvirtOptions) -> Command {
fn virsh_command(&self, global_opts: &crate::libvirt::LibvirtOptions) -> VirshCommand {
global_opts.virsh_command()
}

Expand Down
10 changes: 3 additions & 7 deletions crates/kit/src/libvirt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ pub mod start;
pub mod status;
pub mod stop;
pub mod upload;
pub mod virsh;

/// Global options for libvirt operations
#[derive(Debug, Clone, Default)]
Expand All @@ -50,13 +51,8 @@ pub struct LibvirtOptions {

impl LibvirtOptions {
/// Create a virsh Command with the appropriate connection URI
pub fn virsh_command(&self) -> std::process::Command {
let mut cmd = std::process::Command::new("virsh");
cmd.env("LC_ALL", "C");
if let Some(ref uri) = self.connect {
cmd.arg("-c").arg(uri);
}
cmd
pub fn virsh_command(&self) -> virsh::VirshCommand {
virsh::VirshCommand::new(self.connect.as_deref())
}
}

Expand Down
9 changes: 2 additions & 7 deletions crates/kit/src/libvirt/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,8 @@ const SSH_WAIT_TIMEOUT_SECONDS: u64 = 180;
const UPDATE_FROM_HOST_TRANSPORT: &str = "containers-storage";

/// Create a virsh command with optional connection URI
pub(super) fn virsh_command(connect_uri: Option<&str>) -> Result<std::process::Command> {
let mut cmd = std::process::Command::new("virsh");
cmd.env("LC_ALL", "C");
if let Some(uri) = connect_uri {
cmd.arg("-c").arg(uri);
}
Ok(cmd)
pub(super) fn virsh_command(connect_uri: Option<&str>) -> Result<super::virsh::VirshCommand> {
Ok(super::virsh::VirshCommand::new(connect_uri))
}

/// Run a virsh command and handle errors consistently
Expand Down
4 changes: 2 additions & 2 deletions crates/kit/src/libvirt/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
//! This module provides a status command that outputs JSON metadata about
//! the libvirt environment, including version information and domain count.

use crate::libvirt::virsh::VirshCommand;
use clap::Parser;
use color_eyre::{eyre::Context, Result};
use serde::{Deserialize, Serialize};
use std::process::Command;

use crate::domain_list::DomainLister;

Expand Down Expand Up @@ -98,7 +98,7 @@ fn parse_libvirt_version_from_output(version_output: &str) -> Option<LibvirtVers

/// Parse libvirt version from virsh version output
pub fn parse_libvirt_version() -> Result<Option<LibvirtVersion>> {
let output = Command::new("virsh")
let output = VirshCommand::new(None)
.args(&["version"])
.output()
.with_context(|| "Failed to check libvirt version")?;
Expand Down
4 changes: 2 additions & 2 deletions crates/kit/src/libvirt/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

use crate::common_opts::MemoryOpts;
use crate::install_options::InstallOptions;
use crate::libvirt::virsh::VirshCommand;
use crate::to_disk::{run as to_disk, ToDiskAdditionalOpts, ToDiskOpts};
use crate::{images, utils};
use camino::Utf8PathBuf;
use clap::Parser;
use color_eyre::{eyre::eyre, Result};
use std::path::Path;
use std::process::Command;
use tracing::debug;

/// Configuration options for uploading a bootc disk image to libvirt
Expand Down Expand Up @@ -46,7 +46,7 @@ pub struct LibvirtUploadOpts {

impl LibvirtUploadOpts {
/// Build a virsh command with optional connection URI
fn virsh_command(&self, global_opts: &crate::libvirt::LibvirtOptions) -> Command {
fn virsh_command(&self, global_opts: &crate::libvirt::LibvirtOptions) -> VirshCommand {
global_opts.virsh_command()
}

Expand Down
Loading
Loading