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
44 changes: 22 additions & 22 deletions cli/src/vm_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ use crossterm::tty::IsTty;
use feos_proto::vm_service::{
net_config, stream_vm_console_request as console_input, vm_service_client::VmServiceClient,
AttachConsoleMessage, AttachDiskRequest, AttachNicRequest, ConsoleData, CpuConfig,
CreateVmRequest, DeleteVmRequest, DiskConfig, GetVmRequest, ListVmsRequest, MemoryConfig,
NetConfig, PauseVmRequest, PingVmRequest, RemoveDiskRequest, RemoveNicRequest, ResumeVmRequest,
ShutdownVmRequest, StartVmRequest, StreamVmConsoleRequest, StreamVmEventsRequest, TapConfig,
VfioPciConfig, VmConfig, VmState, VmStateChangedEvent,
CreateVmRequest, DeleteVmRequest, DetachDiskRequest, DetachNicRequest, DiskConfig,
GetVmRequest, ListVmsRequest, MemoryConfig, NetConfig, PauseVmRequest, PingVmRequest,
ResumeVmRequest, ShutdownVmRequest, StartVmRequest, StreamVmConsoleRequest,
StreamVmEventsRequest, TapConfig, VfioPciConfig, VmConfig, VmState, VmStateChangedEvent,
};
use prost::Message;
use tokio::io::{AsyncReadExt, AsyncWriteExt};
Expand Down Expand Up @@ -153,14 +153,14 @@ pub enum VmCommand {
#[arg(long, required = true, help = "Path to the disk image file")]
path: String,
},
/// Remove a disk from a virtual machine
RemoveDisk {
/// Detach a disk from a virtual machine
DetachDisk {
#[arg(long, required = true, help = "VM identifier")]
vm_id: String,
#[arg(
long,
required = true,
help = "Device identifier of the disk to remove"
help = "Device identifier of the disk to detach"
)]
device_id: String,
},
Expand All @@ -185,11 +185,11 @@ pub enum VmCommand {
#[arg(long, help = "Custom device identifier for the new interface")]
device_id: Option<String>,
},
/// Remove a network interface from a VM
RemoveNic {
/// Detach a network interface from a VM
DetachNic {
#[arg(long, required = true, help = "VM identifier")]
vm_id: String,
#[arg(long, required = true, help = "Device identifier of the NIC to remove")]
#[arg(long, required = true, help = "Device identifier of the NIC to detach")]
device_id: String,
},
}
Expand Down Expand Up @@ -262,8 +262,8 @@ pub async fn handle_vm_command(args: VmArgs) -> Result<()> {
VmCommand::Events { vm_id } => watch_events(&mut client, vm_id).await?,
VmCommand::Console { vm_id } => console_vm(&mut client, vm_id).await?,
VmCommand::AttachDisk { vm_id, path } => attach_disk(&mut client, vm_id, path).await?,
VmCommand::RemoveDisk { vm_id, device_id } => {
remove_disk(&mut client, vm_id, device_id).await?
VmCommand::DetachDisk { vm_id, device_id } => {
detach_disk(&mut client, vm_id, device_id).await?
}
VmCommand::AttachNic {
vm_id,
Expand All @@ -282,8 +282,8 @@ pub async fn handle_vm_command(args: VmArgs) -> Result<()> {
)
.await?
}
VmCommand::RemoveNic { vm_id, device_id } => {
remove_nic(&mut client, vm_id, device_id).await?
VmCommand::DetachNic { vm_id, device_id } => {
detach_nic(&mut client, vm_id, device_id).await?
}
}

Expand Down Expand Up @@ -783,17 +783,17 @@ async fn attach_disk(
Ok(())
}

async fn remove_disk(
async fn detach_disk(
client: &mut VmServiceClient<Channel>,
vm_id: String,
device_id: String,
) -> Result<()> {
let request = RemoveDiskRequest {
let request = DetachDiskRequest {
vm_id: vm_id.clone(),
device_id: device_id.clone(),
};
client.remove_disk(request).await?;
println!("Disk remove request sent for device {device_id} on VM {vm_id}");
client.detach_disk(request).await?;
println!("Disk detach request sent for device {device_id} on VM {vm_id}");
Ok(())
}

Expand Down Expand Up @@ -833,16 +833,16 @@ async fn attach_nic(
Ok(())
}

async fn remove_nic(
async fn detach_nic(
client: &mut VmServiceClient<Channel>,
vm_id: String,
device_id: String,
) -> Result<()> {
let request = RemoveNicRequest {
let request = DetachNicRequest {
vm_id: vm_id.clone(),
device_id: device_id.clone(),
};
client.remove_nic(request).await?;
println!("NIC remove request sent for device {device_id} on VM {vm_id}");
client.detach_nic(request).await?;
println!("NIC detach request sent for device {device_id} on VM {vm_id}");
Ok(())
}
30 changes: 15 additions & 15 deletions feos/services/vm-service/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ use crate::Command;
use feos_proto::vm_service::{
vm_service_server::VmService, AttachDiskRequest, AttachDiskResponse, AttachNicRequest,
AttachNicResponse, CreateVmRequest, CreateVmResponse, DeleteVmRequest, DeleteVmResponse,
GetVmRequest, ListVmsRequest, ListVmsResponse, PauseVmRequest, PauseVmResponse, PingVmRequest,
PingVmResponse, RemoveDiskRequest, RemoveDiskResponse, RemoveNicRequest, RemoveNicResponse,
ResumeVmRequest, ResumeVmResponse, ShutdownVmRequest, ShutdownVmResponse, StartVmRequest,
StartVmResponse, StreamVmConsoleRequest, StreamVmConsoleResponse, StreamVmEventsRequest,
VmEvent, VmInfo,
DetachDiskRequest, DetachDiskResponse, DetachNicRequest, DetachNicResponse, GetVmRequest,
ListVmsRequest, ListVmsResponse, PauseVmRequest, PauseVmResponse, PingVmRequest,
PingVmResponse, ResumeVmRequest, ResumeVmResponse, ShutdownVmRequest, ShutdownVmResponse,
StartVmRequest, StartVmResponse, StreamVmConsoleRequest, StreamVmConsoleResponse,
StreamVmEventsRequest, VmEvent, VmInfo,
};
use log::info;
use std::pin::Pin;
Expand Down Expand Up @@ -195,13 +195,13 @@ impl VmService for VmApiHandler {
.await
}

async fn remove_disk(
async fn detach_disk(
&self,
request: Request<RemoveDiskRequest>,
) -> Result<Response<RemoveDiskResponse>, Status> {
info!("VmApi: Received RemoveDisk request.");
request: Request<DetachDiskRequest>,
) -> Result<Response<DetachDiskResponse>, Status> {
info!("VmApi: Received DetachDisk request.");
dispatch_and_wait(&self.dispatcher_tx, |resp_tx| {
Command::RemoveDisk(request.into_inner(), resp_tx)
Command::DetachDisk(request.into_inner(), resp_tx)
})
.await
}
Expand All @@ -217,13 +217,13 @@ impl VmService for VmApiHandler {
.await
}

async fn remove_nic(
async fn detach_nic(
&self,
request: Request<RemoveNicRequest>,
) -> Result<Response<RemoveNicResponse>, Status> {
info!("VmApi: Received RemoveNic request.");
request: Request<DetachNicRequest>,
) -> Result<Response<DetachNicResponse>, Status> {
info!("VmApi: Received DetachNic request.");
dispatch_and_wait(&self.dispatcher_tx, |resp_tx| {
Command::RemoveNic(request.into_inner(), resp_tx)
Command::DetachNic(request.into_inner(), resp_tx)
})
.await
}
Expand Down
12 changes: 6 additions & 6 deletions feos/services/vm-service/src/dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
use crate::{
dispatcher_handlers::{
handle_attach_disk_command, handle_attach_nic_command, handle_create_vm_command,
handle_delete_vm_command, handle_get_vm_command, handle_list_vms_command,
handle_pause_vm_command, handle_remove_disk_command, handle_remove_nic_command,
handle_delete_vm_command, handle_detach_disk_command, handle_detach_nic_command,
handle_get_vm_command, handle_list_vms_command, handle_pause_vm_command,
handle_resume_vm_command, handle_shutdown_vm_command, handle_start_vm_command,
handle_stream_vm_console_command, handle_stream_vm_events_command,
perform_startup_sanity_check,
Expand Down Expand Up @@ -107,14 +107,14 @@ impl VmServiceDispatcher {
Command::AttachDisk(req, responder) => {
handle_attach_disk_command(&self.repository, req, responder, hypervisor).await;
}
Command::RemoveDisk(req, responder) => {
handle_remove_disk_command(&self.repository, req, responder, hypervisor).await;
Command::DetachDisk(req, responder) => {
handle_detach_disk_command(&self.repository, req, responder, hypervisor).await;
}
Command::AttachNic(req, responder) => {
handle_attach_nic_command(&self.repository, req, responder, hypervisor).await;
}
Command::RemoveNic(req, responder) => {
handle_remove_nic_command(&self.repository, req, responder, hypervisor).await;
Command::DetachNic(req, responder) => {
handle_detach_nic_command(&self.repository, req, responder, hypervisor).await;
}
}
},
Expand Down
26 changes: 13 additions & 13 deletions feos/services/vm-service/src/dispatcher_handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ use feos_proto::{
vm_service::{
net_config, stream_vm_console_request as console_input, AttachConsoleMessage,
AttachDiskRequest, AttachDiskResponse, AttachNicRequest, AttachNicResponse,
CreateVmRequest, CreateVmResponse, DeleteVmRequest, DeleteVmResponse, GetVmRequest,
ListVmsRequest, ListVmsResponse, PauseVmRequest, PauseVmResponse, RemoveDiskRequest,
RemoveDiskResponse, RemoveNicRequest, RemoveNicResponse, ResumeVmRequest, ResumeVmResponse,
CreateVmRequest, CreateVmResponse, DeleteVmRequest, DeleteVmResponse, DetachDiskRequest,
DetachDiskResponse, DetachNicRequest, DetachNicResponse, GetVmRequest, ListVmsRequest,
ListVmsResponse, PauseVmRequest, PauseVmResponse, ResumeVmRequest, ResumeVmResponse,
ShutdownVmRequest, ShutdownVmResponse, StartVmRequest, StartVmResponse,
StreamVmConsoleRequest, StreamVmConsoleResponse, StreamVmEventsRequest, VmEvent, VmInfo,
VmState, VmStateChangedEvent,
Expand Down Expand Up @@ -677,10 +677,10 @@ pub(crate) async fn handle_attach_disk_command(
tokio::spawn(worker::handle_attach_disk(req, responder, hypervisor));
}

pub(crate) async fn handle_remove_disk_command(
pub(crate) async fn handle_detach_disk_command(
repository: &VmRepository,
req: RemoveDiskRequest,
responder: oneshot::Sender<Result<RemoveDiskResponse, VmServiceError>>,
req: DetachDiskRequest,
responder: oneshot::Sender<Result<DetachDiskResponse, VmServiceError>>,
hypervisor: Arc<dyn Hypervisor>,
) {
let (_vm_id, record) = match parse_vm_id_and_get_record(&req.vm_id, repository).await {
Expand All @@ -697,12 +697,12 @@ pub(crate) async fn handle_remove_disk_command(
VmState::Created | VmState::Running | VmState::Paused | VmState::Stopped
) {
let _ = responder.send(Err(VmServiceError::InvalidState(format!(
"Cannot remove disk from VM in {current_state:?} state."
"Cannot detach disk from VM in {current_state:?} state."
))));
return;
}

tokio::spawn(worker::handle_remove_disk(req, responder, hypervisor));
tokio::spawn(worker::handle_detach_disk(req, responder, hypervisor));
}

pub(crate) async fn handle_attach_nic_command(
Expand Down Expand Up @@ -749,10 +749,10 @@ pub(crate) async fn handle_attach_nic_command(
tokio::spawn(worker::handle_attach_nic(req, responder, hypervisor));
}

pub(crate) async fn handle_remove_nic_command(
pub(crate) async fn handle_detach_nic_command(
repository: &VmRepository,
req: RemoveNicRequest,
responder: oneshot::Sender<Result<RemoveNicResponse, VmServiceError>>,
req: DetachNicRequest,
responder: oneshot::Sender<Result<DetachNicResponse, VmServiceError>>,
hypervisor: Arc<dyn Hypervisor>,
) {
let (_vm_id, mut record) = match parse_vm_id_and_get_record(&req.vm_id, repository).await {
Expand All @@ -766,7 +766,7 @@ pub(crate) async fn handle_remove_nic_command(
let current_state = record.status.state;
if matches!(current_state, VmState::Creating | VmState::Crashed) {
let _ = responder.send(Err(VmServiceError::InvalidState(format!(
"Cannot remove NIC from VM in {current_state:?} state."
"Cannot detach NIC from VM in {current_state:?} state."
))));
return;
}
Expand All @@ -790,7 +790,7 @@ pub(crate) async fn handle_remove_nic_command(
return;
}

tokio::spawn(worker::handle_remove_nic(req, responder, hypervisor));
tokio::spawn(worker::handle_detach_nic(req, responder, hypervisor));
}

pub(crate) async fn check_and_cleanup_vms(
Expand Down
22 changes: 11 additions & 11 deletions feos/services/vm-service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
use crate::error::VmServiceError;
use feos_proto::vm_service::{
AttachDiskRequest, AttachDiskResponse, AttachNicRequest, AttachNicResponse, CreateVmRequest,
CreateVmResponse, DeleteVmRequest, DeleteVmResponse, GetVmRequest, ListVmsRequest,
ListVmsResponse, PauseVmRequest, PauseVmResponse, PingVmRequest, PingVmResponse,
RemoveDiskRequest, RemoveDiskResponse, RemoveNicRequest, RemoveNicResponse, ResumeVmRequest,
CreateVmResponse, DeleteVmRequest, DeleteVmResponse, DetachDiskRequest, DetachDiskResponse,
DetachNicRequest, DetachNicResponse, GetVmRequest, ListVmsRequest, ListVmsResponse,
PauseVmRequest, PauseVmResponse, PingVmRequest, PingVmResponse, ResumeVmRequest,
ResumeVmResponse, ShutdownVmRequest, ShutdownVmResponse, StartVmRequest, StartVmResponse,
StreamVmConsoleRequest, StreamVmConsoleResponse, StreamVmEventsRequest, VmEvent, VmInfo,
};
Expand Down Expand Up @@ -80,17 +80,17 @@ pub enum Command {
AttachDiskRequest,
oneshot::Sender<Result<AttachDiskResponse, VmServiceError>>,
),
RemoveDisk(
RemoveDiskRequest,
oneshot::Sender<Result<RemoveDiskResponse, VmServiceError>>,
DetachDisk(
DetachDiskRequest,
oneshot::Sender<Result<DetachDiskResponse, VmServiceError>>,
),
AttachNic(
AttachNicRequest,
oneshot::Sender<Result<AttachNicResponse, VmServiceError>>,
),
RemoveNic(
RemoveNicRequest,
oneshot::Sender<Result<RemoveNicResponse, VmServiceError>>,
DetachNic(
DetachNicRequest,
oneshot::Sender<Result<DetachNicResponse, VmServiceError>>,
),
}

Expand All @@ -111,9 +111,9 @@ impl std::fmt::Debug for Command {
Command::PauseVm(req, _) => f.debug_tuple("PauseVm").field(req).finish(),
Command::ResumeVm(req, _) => f.debug_tuple("ResumeVm").field(req).finish(),
Command::AttachDisk(req, _) => f.debug_tuple("AttachDisk").field(req).finish(),
Command::RemoveDisk(req, _) => f.debug_tuple("RemoveDisk").field(req).finish(),
Command::DetachDisk(req, _) => f.debug_tuple("DetachDisk").field(req).finish(),
Command::AttachNic(req, _) => f.debug_tuple("AttachNic").field(req).finish(),
Command::RemoveNic(req, _) => f.debug_tuple("RemoveNic").field(req).finish(),
Command::DetachNic(req, _) => f.debug_tuple("DetachNic").field(req).finish(),
}
}
}
14 changes: 7 additions & 7 deletions feos/services/vm-service/src/vmm/ch_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ use cloud_hypervisor_client::{
};
use feos_proto::vm_service::{
net_config, AttachDiskRequest, AttachDiskResponse, AttachNicRequest, AttachNicResponse,
CreateVmRequest, DeleteVmRequest, DeleteVmResponse, GetVmRequest, PauseVmRequest,
PauseVmResponse, PingVmRequest, PingVmResponse, RemoveDiskRequest, RemoveDiskResponse,
RemoveNicRequest, RemoveNicResponse, ResumeVmRequest, ResumeVmResponse, ShutdownVmRequest,
CreateVmRequest, DeleteVmRequest, DeleteVmResponse, DetachDiskRequest, DetachDiskResponse,
DetachNicRequest, DetachNicResponse, GetVmRequest, PauseVmRequest, PauseVmResponse,
PingVmRequest, PingVmResponse, ResumeVmRequest, ResumeVmResponse, ShutdownVmRequest,
ShutdownVmResponse, StartVmRequest, StartVmResponse, VmConfig, VmInfo, VmState,
};
use hyper_util::client::legacy::Client;
Expand Down Expand Up @@ -499,9 +499,9 @@ impl Hypervisor for CloudHypervisorAdapter {
))
}

async fn remove_disk(&self, _req: RemoveDiskRequest) -> Result<RemoveDiskResponse, VmmError> {
async fn detach_disk(&self, _req: DetachDiskRequest) -> Result<DetachDiskResponse, VmmError> {
Err(VmmError::Internal(
"RemoveDisk not implemented for CloudHypervisorAdapter".to_string(),
"DetachDisk not implemented for CloudHypervisorAdapter".to_string(),
))
}

Expand Down Expand Up @@ -536,7 +536,7 @@ impl Hypervisor for CloudHypervisorAdapter {
})
}

async fn remove_nic(&self, req: RemoveNicRequest) -> Result<RemoveNicResponse, VmmError> {
async fn detach_nic(&self, req: DetachNicRequest) -> Result<DetachNicResponse, VmmError> {
let api_client = self.get_ch_api_client(&req.vm_id)?;
let device_to_remove = models::VmRemoveDevice {
id: Some(req.device_id),
Expand All @@ -545,6 +545,6 @@ impl Hypervisor for CloudHypervisorAdapter {
.vm_remove_device_put(device_to_remove)
.await
.map_err(|e| VmmError::ApiOperationFailed(format!("vm.remove-device failed: {e}")))?;
Ok(RemoveNicResponse {})
Ok(DetachNicResponse {})
}
}
10 changes: 5 additions & 5 deletions feos/services/vm-service/src/vmm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
use crate::VmEventWrapper;
use feos_proto::vm_service::{
AttachDiskRequest, AttachDiskResponse, AttachNicRequest, AttachNicResponse, CreateVmRequest,
DeleteVmRequest, DeleteVmResponse, GetVmRequest, PauseVmRequest, PauseVmResponse,
PingVmRequest, PingVmResponse, RemoveDiskRequest, RemoveDiskResponse, RemoveNicRequest,
RemoveNicResponse, ResumeVmRequest, ResumeVmResponse, ShutdownVmRequest, ShutdownVmResponse,
DeleteVmRequest, DeleteVmResponse, DetachDiskRequest, DetachDiskResponse, DetachNicRequest,
DetachNicResponse, GetVmRequest, PauseVmRequest, PauseVmResponse, PingVmRequest,
PingVmResponse, ResumeVmRequest, ResumeVmResponse, ShutdownVmRequest, ShutdownVmResponse,
StartVmRequest, StartVmResponse, VmEvent, VmInfo, VmStateChangedEvent,
};
use prost::Message;
Expand Down Expand Up @@ -90,9 +90,9 @@ pub trait Hypervisor: Send + Sync {
async fn pause_vm(&self, req: PauseVmRequest) -> Result<PauseVmResponse, VmmError>;
async fn resume_vm(&self, req: ResumeVmRequest) -> Result<ResumeVmResponse, VmmError>;
async fn attach_disk(&self, req: AttachDiskRequest) -> Result<AttachDiskResponse, VmmError>;
async fn remove_disk(&self, req: RemoveDiskRequest) -> Result<RemoveDiskResponse, VmmError>;
async fn detach_disk(&self, req: DetachDiskRequest) -> Result<DetachDiskResponse, VmmError>;
async fn attach_nic(&self, req: AttachNicRequest) -> Result<AttachNicResponse, VmmError>;
async fn remove_nic(&self, req: RemoveNicRequest) -> Result<RemoveNicResponse, VmmError>;
async fn detach_nic(&self, req: DetachNicRequest) -> Result<DetachNicResponse, VmmError>;
}

pub async fn broadcast_state_change_event(
Expand Down
Loading
Loading