Skip to content

Commit 9dee271

Browse files
authored
Rename RemoveNic/Disk to DetachNic/Disk (#97)
* Rename VM Api GRPC call RemoveNic to DetachNic Signed-off-by: Guvenc Gulce <[email protected]> * Rename VM Api GRPC call RemoveDisk to DetachDisk Signed-off-by: Guvenc Gulce <[email protected]> * Linter corrections Signed-off-by: Guvenc Gulce <[email protected]> --------- Signed-off-by: Guvenc Gulce <[email protected]>
1 parent 755d421 commit 9dee271

File tree

10 files changed

+107
-108
lines changed

10 files changed

+107
-108
lines changed

cli/src/vm_commands.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ use crossterm::tty::IsTty;
88
use feos_proto::vm_service::{
99
net_config, stream_vm_console_request as console_input, vm_service_client::VmServiceClient,
1010
AttachConsoleMessage, AttachDiskRequest, AttachNicRequest, ConsoleData, CpuConfig,
11-
CreateVmRequest, DeleteVmRequest, DiskConfig, GetVmRequest, ListVmsRequest, MemoryConfig,
12-
NetConfig, PauseVmRequest, PingVmRequest, RemoveDiskRequest, RemoveNicRequest, ResumeVmRequest,
13-
ShutdownVmRequest, StartVmRequest, StreamVmConsoleRequest, StreamVmEventsRequest, TapConfig,
14-
VfioPciConfig, VmConfig, VmState, VmStateChangedEvent,
11+
CreateVmRequest, DeleteVmRequest, DetachDiskRequest, DetachNicRequest, DiskConfig,
12+
GetVmRequest, ListVmsRequest, MemoryConfig, NetConfig, PauseVmRequest, PingVmRequest,
13+
ResumeVmRequest, ShutdownVmRequest, StartVmRequest, StreamVmConsoleRequest,
14+
StreamVmEventsRequest, TapConfig, VfioPciConfig, VmConfig, VmState, VmStateChangedEvent,
1515
};
1616
use prost::Message;
1717
use tokio::io::{AsyncReadExt, AsyncWriteExt};
@@ -153,14 +153,14 @@ pub enum VmCommand {
153153
#[arg(long, required = true, help = "Path to the disk image file")]
154154
path: String,
155155
},
156-
/// Remove a disk from a virtual machine
157-
RemoveDisk {
156+
/// Detach a disk from a virtual machine
157+
DetachDisk {
158158
#[arg(long, required = true, help = "VM identifier")]
159159
vm_id: String,
160160
#[arg(
161161
long,
162162
required = true,
163-
help = "Device identifier of the disk to remove"
163+
help = "Device identifier of the disk to detach"
164164
)]
165165
device_id: String,
166166
},
@@ -185,11 +185,11 @@ pub enum VmCommand {
185185
#[arg(long, help = "Custom device identifier for the new interface")]
186186
device_id: Option<String>,
187187
},
188-
/// Remove a network interface from a VM
189-
RemoveNic {
188+
/// Detach a network interface from a VM
189+
DetachNic {
190190
#[arg(long, required = true, help = "VM identifier")]
191191
vm_id: String,
192-
#[arg(long, required = true, help = "Device identifier of the NIC to remove")]
192+
#[arg(long, required = true, help = "Device identifier of the NIC to detach")]
193193
device_id: String,
194194
},
195195
}
@@ -262,8 +262,8 @@ pub async fn handle_vm_command(args: VmArgs) -> Result<()> {
262262
VmCommand::Events { vm_id } => watch_events(&mut client, vm_id).await?,
263263
VmCommand::Console { vm_id } => console_vm(&mut client, vm_id).await?,
264264
VmCommand::AttachDisk { vm_id, path } => attach_disk(&mut client, vm_id, path).await?,
265-
VmCommand::RemoveDisk { vm_id, device_id } => {
266-
remove_disk(&mut client, vm_id, device_id).await?
265+
VmCommand::DetachDisk { vm_id, device_id } => {
266+
detach_disk(&mut client, vm_id, device_id).await?
267267
}
268268
VmCommand::AttachNic {
269269
vm_id,
@@ -282,8 +282,8 @@ pub async fn handle_vm_command(args: VmArgs) -> Result<()> {
282282
)
283283
.await?
284284
}
285-
VmCommand::RemoveNic { vm_id, device_id } => {
286-
remove_nic(&mut client, vm_id, device_id).await?
285+
VmCommand::DetachNic { vm_id, device_id } => {
286+
detach_nic(&mut client, vm_id, device_id).await?
287287
}
288288
}
289289

@@ -783,17 +783,17 @@ async fn attach_disk(
783783
Ok(())
784784
}
785785

786-
async fn remove_disk(
786+
async fn detach_disk(
787787
client: &mut VmServiceClient<Channel>,
788788
vm_id: String,
789789
device_id: String,
790790
) -> Result<()> {
791-
let request = RemoveDiskRequest {
791+
let request = DetachDiskRequest {
792792
vm_id: vm_id.clone(),
793793
device_id: device_id.clone(),
794794
};
795-
client.remove_disk(request).await?;
796-
println!("Disk remove request sent for device {device_id} on VM {vm_id}");
795+
client.detach_disk(request).await?;
796+
println!("Disk detach request sent for device {device_id} on VM {vm_id}");
797797
Ok(())
798798
}
799799

@@ -833,16 +833,16 @@ async fn attach_nic(
833833
Ok(())
834834
}
835835

836-
async fn remove_nic(
836+
async fn detach_nic(
837837
client: &mut VmServiceClient<Channel>,
838838
vm_id: String,
839839
device_id: String,
840840
) -> Result<()> {
841-
let request = RemoveNicRequest {
841+
let request = DetachNicRequest {
842842
vm_id: vm_id.clone(),
843843
device_id: device_id.clone(),
844844
};
845-
client.remove_nic(request).await?;
846-
println!("NIC remove request sent for device {device_id} on VM {vm_id}");
845+
client.detach_nic(request).await?;
846+
println!("NIC detach request sent for device {device_id} on VM {vm_id}");
847847
Ok(())
848848
}

feos/services/vm-service/src/api.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ use crate::Command;
55
use feos_proto::vm_service::{
66
vm_service_server::VmService, AttachDiskRequest, AttachDiskResponse, AttachNicRequest,
77
AttachNicResponse, CreateVmRequest, CreateVmResponse, DeleteVmRequest, DeleteVmResponse,
8-
GetVmRequest, ListVmsRequest, ListVmsResponse, PauseVmRequest, PauseVmResponse, PingVmRequest,
9-
PingVmResponse, RemoveDiskRequest, RemoveDiskResponse, RemoveNicRequest, RemoveNicResponse,
10-
ResumeVmRequest, ResumeVmResponse, ShutdownVmRequest, ShutdownVmResponse, StartVmRequest,
11-
StartVmResponse, StreamVmConsoleRequest, StreamVmConsoleResponse, StreamVmEventsRequest,
12-
VmEvent, VmInfo,
8+
DetachDiskRequest, DetachDiskResponse, DetachNicRequest, DetachNicResponse, GetVmRequest,
9+
ListVmsRequest, ListVmsResponse, PauseVmRequest, PauseVmResponse, PingVmRequest,
10+
PingVmResponse, ResumeVmRequest, ResumeVmResponse, ShutdownVmRequest, ShutdownVmResponse,
11+
StartVmRequest, StartVmResponse, StreamVmConsoleRequest, StreamVmConsoleResponse,
12+
StreamVmEventsRequest, VmEvent, VmInfo,
1313
};
1414
use log::info;
1515
use std::pin::Pin;
@@ -195,13 +195,13 @@ impl VmService for VmApiHandler {
195195
.await
196196
}
197197

198-
async fn remove_disk(
198+
async fn detach_disk(
199199
&self,
200-
request: Request<RemoveDiskRequest>,
201-
) -> Result<Response<RemoveDiskResponse>, Status> {
202-
info!("VmApi: Received RemoveDisk request.");
200+
request: Request<DetachDiskRequest>,
201+
) -> Result<Response<DetachDiskResponse>, Status> {
202+
info!("VmApi: Received DetachDisk request.");
203203
dispatch_and_wait(&self.dispatcher_tx, |resp_tx| {
204-
Command::RemoveDisk(request.into_inner(), resp_tx)
204+
Command::DetachDisk(request.into_inner(), resp_tx)
205205
})
206206
.await
207207
}
@@ -217,13 +217,13 @@ impl VmService for VmApiHandler {
217217
.await
218218
}
219219

220-
async fn remove_nic(
220+
async fn detach_nic(
221221
&self,
222-
request: Request<RemoveNicRequest>,
223-
) -> Result<Response<RemoveNicResponse>, Status> {
224-
info!("VmApi: Received RemoveNic request.");
222+
request: Request<DetachNicRequest>,
223+
) -> Result<Response<DetachNicResponse>, Status> {
224+
info!("VmApi: Received DetachNic request.");
225225
dispatch_and_wait(&self.dispatcher_tx, |resp_tx| {
226-
Command::RemoveNic(request.into_inner(), resp_tx)
226+
Command::DetachNic(request.into_inner(), resp_tx)
227227
})
228228
.await
229229
}

feos/services/vm-service/src/dispatcher.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
use crate::{
55
dispatcher_handlers::{
66
handle_attach_disk_command, handle_attach_nic_command, handle_create_vm_command,
7-
handle_delete_vm_command, handle_get_vm_command, handle_list_vms_command,
8-
handle_pause_vm_command, handle_remove_disk_command, handle_remove_nic_command,
7+
handle_delete_vm_command, handle_detach_disk_command, handle_detach_nic_command,
8+
handle_get_vm_command, handle_list_vms_command, handle_pause_vm_command,
99
handle_resume_vm_command, handle_shutdown_vm_command, handle_start_vm_command,
1010
handle_stream_vm_console_command, handle_stream_vm_events_command,
1111
perform_startup_sanity_check,
@@ -107,14 +107,14 @@ impl VmServiceDispatcher {
107107
Command::AttachDisk(req, responder) => {
108108
handle_attach_disk_command(&self.repository, req, responder, hypervisor).await;
109109
}
110-
Command::RemoveDisk(req, responder) => {
111-
handle_remove_disk_command(&self.repository, req, responder, hypervisor).await;
110+
Command::DetachDisk(req, responder) => {
111+
handle_detach_disk_command(&self.repository, req, responder, hypervisor).await;
112112
}
113113
Command::AttachNic(req, responder) => {
114114
handle_attach_nic_command(&self.repository, req, responder, hypervisor).await;
115115
}
116-
Command::RemoveNic(req, responder) => {
117-
handle_remove_nic_command(&self.repository, req, responder, hypervisor).await;
116+
Command::DetachNic(req, responder) => {
117+
handle_detach_nic_command(&self.repository, req, responder, hypervisor).await;
118118
}
119119
}
120120
},

feos/services/vm-service/src/dispatcher_handlers.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ use feos_proto::{
1212
vm_service::{
1313
net_config, stream_vm_console_request as console_input, AttachConsoleMessage,
1414
AttachDiskRequest, AttachDiskResponse, AttachNicRequest, AttachNicResponse,
15-
CreateVmRequest, CreateVmResponse, DeleteVmRequest, DeleteVmResponse, GetVmRequest,
16-
ListVmsRequest, ListVmsResponse, PauseVmRequest, PauseVmResponse, RemoveDiskRequest,
17-
RemoveDiskResponse, RemoveNicRequest, RemoveNicResponse, ResumeVmRequest, ResumeVmResponse,
15+
CreateVmRequest, CreateVmResponse, DeleteVmRequest, DeleteVmResponse, DetachDiskRequest,
16+
DetachDiskResponse, DetachNicRequest, DetachNicResponse, GetVmRequest, ListVmsRequest,
17+
ListVmsResponse, PauseVmRequest, PauseVmResponse, ResumeVmRequest, ResumeVmResponse,
1818
ShutdownVmRequest, ShutdownVmResponse, StartVmRequest, StartVmResponse,
1919
StreamVmConsoleRequest, StreamVmConsoleResponse, StreamVmEventsRequest, VmEvent, VmInfo,
2020
VmState, VmStateChangedEvent,
@@ -677,10 +677,10 @@ pub(crate) async fn handle_attach_disk_command(
677677
tokio::spawn(worker::handle_attach_disk(req, responder, hypervisor));
678678
}
679679

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

705-
tokio::spawn(worker::handle_remove_disk(req, responder, hypervisor));
705+
tokio::spawn(worker::handle_detach_disk(req, responder, hypervisor));
706706
}
707707

708708
pub(crate) async fn handle_attach_nic_command(
@@ -749,10 +749,10 @@ pub(crate) async fn handle_attach_nic_command(
749749
tokio::spawn(worker::handle_attach_nic(req, responder, hypervisor));
750750
}
751751

752-
pub(crate) async fn handle_remove_nic_command(
752+
pub(crate) async fn handle_detach_nic_command(
753753
repository: &VmRepository,
754-
req: RemoveNicRequest,
755-
responder: oneshot::Sender<Result<RemoveNicResponse, VmServiceError>>,
754+
req: DetachNicRequest,
755+
responder: oneshot::Sender<Result<DetachNicResponse, VmServiceError>>,
756756
hypervisor: Arc<dyn Hypervisor>,
757757
) {
758758
let (_vm_id, mut record) = match parse_vm_id_and_get_record(&req.vm_id, repository).await {
@@ -766,7 +766,7 @@ pub(crate) async fn handle_remove_nic_command(
766766
let current_state = record.status.state;
767767
if matches!(current_state, VmState::Creating | VmState::Crashed) {
768768
let _ = responder.send(Err(VmServiceError::InvalidState(format!(
769-
"Cannot remove NIC from VM in {current_state:?} state."
769+
"Cannot detach NIC from VM in {current_state:?} state."
770770
))));
771771
return;
772772
}
@@ -790,7 +790,7 @@ pub(crate) async fn handle_remove_nic_command(
790790
return;
791791
}
792792

793-
tokio::spawn(worker::handle_remove_nic(req, responder, hypervisor));
793+
tokio::spawn(worker::handle_detach_nic(req, responder, hypervisor));
794794
}
795795

796796
pub(crate) async fn check_and_cleanup_vms(

feos/services/vm-service/src/lib.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
use crate::error::VmServiceError;
55
use feos_proto::vm_service::{
66
AttachDiskRequest, AttachDiskResponse, AttachNicRequest, AttachNicResponse, CreateVmRequest,
7-
CreateVmResponse, DeleteVmRequest, DeleteVmResponse, GetVmRequest, ListVmsRequest,
8-
ListVmsResponse, PauseVmRequest, PauseVmResponse, PingVmRequest, PingVmResponse,
9-
RemoveDiskRequest, RemoveDiskResponse, RemoveNicRequest, RemoveNicResponse, ResumeVmRequest,
7+
CreateVmResponse, DeleteVmRequest, DeleteVmResponse, DetachDiskRequest, DetachDiskResponse,
8+
DetachNicRequest, DetachNicResponse, GetVmRequest, ListVmsRequest, ListVmsResponse,
9+
PauseVmRequest, PauseVmResponse, PingVmRequest, PingVmResponse, ResumeVmRequest,
1010
ResumeVmResponse, ShutdownVmRequest, ShutdownVmResponse, StartVmRequest, StartVmResponse,
1111
StreamVmConsoleRequest, StreamVmConsoleResponse, StreamVmEventsRequest, VmEvent, VmInfo,
1212
};
@@ -80,17 +80,17 @@ pub enum Command {
8080
AttachDiskRequest,
8181
oneshot::Sender<Result<AttachDiskResponse, VmServiceError>>,
8282
),
83-
RemoveDisk(
84-
RemoveDiskRequest,
85-
oneshot::Sender<Result<RemoveDiskResponse, VmServiceError>>,
83+
DetachDisk(
84+
DetachDiskRequest,
85+
oneshot::Sender<Result<DetachDiskResponse, VmServiceError>>,
8686
),
8787
AttachNic(
8888
AttachNicRequest,
8989
oneshot::Sender<Result<AttachNicResponse, VmServiceError>>,
9090
),
91-
RemoveNic(
92-
RemoveNicRequest,
93-
oneshot::Sender<Result<RemoveNicResponse, VmServiceError>>,
91+
DetachNic(
92+
DetachNicRequest,
93+
oneshot::Sender<Result<DetachNicResponse, VmServiceError>>,
9494
),
9595
}
9696

@@ -111,9 +111,9 @@ impl std::fmt::Debug for Command {
111111
Command::PauseVm(req, _) => f.debug_tuple("PauseVm").field(req).finish(),
112112
Command::ResumeVm(req, _) => f.debug_tuple("ResumeVm").field(req).finish(),
113113
Command::AttachDisk(req, _) => f.debug_tuple("AttachDisk").field(req).finish(),
114-
Command::RemoveDisk(req, _) => f.debug_tuple("RemoveDisk").field(req).finish(),
114+
Command::DetachDisk(req, _) => f.debug_tuple("DetachDisk").field(req).finish(),
115115
Command::AttachNic(req, _) => f.debug_tuple("AttachNic").field(req).finish(),
116-
Command::RemoveNic(req, _) => f.debug_tuple("RemoveNic").field(req).finish(),
116+
Command::DetachNic(req, _) => f.debug_tuple("DetachNic").field(req).finish(),
117117
}
118118
}
119119
}

feos/services/vm-service/src/vmm/ch_adapter.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ use cloud_hypervisor_client::{
1212
};
1313
use feos_proto::vm_service::{
1414
net_config, AttachDiskRequest, AttachDiskResponse, AttachNicRequest, AttachNicResponse,
15-
CreateVmRequest, DeleteVmRequest, DeleteVmResponse, GetVmRequest, PauseVmRequest,
16-
PauseVmResponse, PingVmRequest, PingVmResponse, RemoveDiskRequest, RemoveDiskResponse,
17-
RemoveNicRequest, RemoveNicResponse, ResumeVmRequest, ResumeVmResponse, ShutdownVmRequest,
15+
CreateVmRequest, DeleteVmRequest, DeleteVmResponse, DetachDiskRequest, DetachDiskResponse,
16+
DetachNicRequest, DetachNicResponse, GetVmRequest, PauseVmRequest, PauseVmResponse,
17+
PingVmRequest, PingVmResponse, ResumeVmRequest, ResumeVmResponse, ShutdownVmRequest,
1818
ShutdownVmResponse, StartVmRequest, StartVmResponse, VmConfig, VmInfo, VmState,
1919
};
2020
use hyper_util::client::legacy::Client;
@@ -499,9 +499,9 @@ impl Hypervisor for CloudHypervisorAdapter {
499499
))
500500
}
501501

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

@@ -536,7 +536,7 @@ impl Hypervisor for CloudHypervisorAdapter {
536536
})
537537
}
538538

539-
async fn remove_nic(&self, req: RemoveNicRequest) -> Result<RemoveNicResponse, VmmError> {
539+
async fn detach_nic(&self, req: DetachNicRequest) -> Result<DetachNicResponse, VmmError> {
540540
let api_client = self.get_ch_api_client(&req.vm_id)?;
541541
let device_to_remove = models::VmRemoveDevice {
542542
id: Some(req.device_id),
@@ -545,6 +545,6 @@ impl Hypervisor for CloudHypervisorAdapter {
545545
.vm_remove_device_put(device_to_remove)
546546
.await
547547
.map_err(|e| VmmError::ApiOperationFailed(format!("vm.remove-device failed: {e}")))?;
548-
Ok(RemoveNicResponse {})
548+
Ok(DetachNicResponse {})
549549
}
550550
}

feos/services/vm-service/src/vmm/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
use crate::VmEventWrapper;
55
use feos_proto::vm_service::{
66
AttachDiskRequest, AttachDiskResponse, AttachNicRequest, AttachNicResponse, CreateVmRequest,
7-
DeleteVmRequest, DeleteVmResponse, GetVmRequest, PauseVmRequest, PauseVmResponse,
8-
PingVmRequest, PingVmResponse, RemoveDiskRequest, RemoveDiskResponse, RemoveNicRequest,
9-
RemoveNicResponse, ResumeVmRequest, ResumeVmResponse, ShutdownVmRequest, ShutdownVmResponse,
7+
DeleteVmRequest, DeleteVmResponse, DetachDiskRequest, DetachDiskResponse, DetachNicRequest,
8+
DetachNicResponse, GetVmRequest, PauseVmRequest, PauseVmResponse, PingVmRequest,
9+
PingVmResponse, ResumeVmRequest, ResumeVmResponse, ShutdownVmRequest, ShutdownVmResponse,
1010
StartVmRequest, StartVmResponse, VmEvent, VmInfo, VmStateChangedEvent,
1111
};
1212
use prost::Message;
@@ -90,9 +90,9 @@ pub trait Hypervisor: Send + Sync {
9090
async fn pause_vm(&self, req: PauseVmRequest) -> Result<PauseVmResponse, VmmError>;
9191
async fn resume_vm(&self, req: ResumeVmRequest) -> Result<ResumeVmResponse, VmmError>;
9292
async fn attach_disk(&self, req: AttachDiskRequest) -> Result<AttachDiskResponse, VmmError>;
93-
async fn remove_disk(&self, req: RemoveDiskRequest) -> Result<RemoveDiskResponse, VmmError>;
93+
async fn detach_disk(&self, req: DetachDiskRequest) -> Result<DetachDiskResponse, VmmError>;
9494
async fn attach_nic(&self, req: AttachNicRequest) -> Result<AttachNicResponse, VmmError>;
95-
async fn remove_nic(&self, req: RemoveNicRequest) -> Result<RemoveNicResponse, VmmError>;
95+
async fn detach_nic(&self, req: DetachNicRequest) -> Result<DetachNicResponse, VmmError>;
9696
}
9797

9898
pub async fn broadcast_state_change_event(

0 commit comments

Comments
 (0)