//! PrismNET client for port management use prismnet_api::proto::{ port_service_client::PortServiceClient, GetPortRequest, AttachDeviceRequest, DetachDeviceRequest, }; use tonic::transport::Channel; /// PrismNET client wrapper pub struct PrismNETClient { port_client: PortServiceClient, } impl PrismNETClient { /// Create a new PrismNET client pub async fn new(endpoint: String) -> Result> { let channel = Channel::from_shared(endpoint)? .connect() .await?; let port_client = PortServiceClient::new(channel); Ok(Self { port_client }) } /// Get port details pub async fn get_port( &mut self, org_id: &str, project_id: &str, subnet_id: &str, port_id: &str, ) -> Result> { let request = tonic::Request::new(GetPortRequest { org_id: org_id.to_string(), project_id: project_id.to_string(), subnet_id: subnet_id.to_string(), id: port_id.to_string(), }); let response = self.port_client.get_port(request).await?; Ok(response.into_inner().port.ok_or("Port not found in response")?) } /// Attach a device to a port pub async fn attach_device( &mut self, org_id: &str, project_id: &str, subnet_id: &str, port_id: &str, device_id: &str, device_type: i32, ) -> Result<(), Box> { let request = tonic::Request::new(AttachDeviceRequest { org_id: org_id.to_string(), project_id: project_id.to_string(), subnet_id: subnet_id.to_string(), port_id: port_id.to_string(), device_id: device_id.to_string(), device_type, }); self.port_client.attach_device(request).await?; Ok(()) } /// Detach a device from a port pub async fn detach_device( &mut self, org_id: &str, project_id: &str, subnet_id: &str, port_id: &str, ) -> Result<(), Box> { let request = tonic::Request::new(DetachDeviceRequest { org_id: org_id.to_string(), project_id: project_id.to_string(), subnet_id: subnet_id.to_string(), port_id: port_id.to_string(), }); self.port_client.detach_device(request).await?; Ok(()) } }