@@ -58,35 +58,36 @@ impl FeOSAPI {
5858 log_receiver,
5959 }
6060 }
61- }
6261
63- fn handle_error ( e : vm:: Error ) -> tonic:: Status {
64- match e {
65- vm:: Error :: AlreadyExists => Status :: new ( tonic:: Code :: AlreadyExists , "vm already exists" ) ,
66- vm:: Error :: NotFound => Status :: new ( tonic:: Code :: NotFound , "vm not found" ) ,
67- vm:: Error :: SocketFailure ( e) => {
68- info ! ( "socket error: {:?}" , e) ;
69- Status :: new ( tonic:: Code :: Internal , "failed to " )
70- }
71- vm:: Error :: InvalidInput ( e) => {
72- info ! ( "invalid input error: {:?}" , e) ;
73- Status :: new ( tonic:: Code :: Internal , "invalid input" )
74- }
75- vm:: Error :: CHCommandFailure ( e) => {
76- info ! ( "failed to connect to cloud hypervisor: {:?}" , e) ;
77- Status :: new (
78- tonic:: Code :: Internal ,
79- "failed to connect to cloud hypervisor" ,
80- )
81- }
82- vm:: Error :: CHApiFailure ( e) => {
83- info ! ( "failed to connect to cloud hypervisor api: {:?}" , e) ;
84- Status :: new (
85- tonic:: Code :: Internal ,
86- "failed to connect to cloud hypervisor api" ,
87- )
62+ fn handle_error ( & self , e : vm:: Error ) -> Status {
63+ match e {
64+ vm:: Error :: AlreadyExists => {
65+ Status :: new ( tonic:: Code :: AlreadyExists , "vm already exists" )
66+ }
67+ vm:: Error :: NotFound => Status :: new ( tonic:: Code :: NotFound , "vm not found" ) ,
68+ vm:: Error :: SocketFailure ( e) => {
69+ info ! ( "socket error: {:?}" , e) ;
70+ Status :: new ( tonic:: Code :: Internal , "failed to " )
71+ }
72+ vm:: Error :: InvalidInput ( e) => {
73+ info ! ( "invalid input error: {:?}" , e) ;
74+ Status :: new ( tonic:: Code :: Internal , "invalid input" )
75+ }
76+ vm:: Error :: CHCommandFailure ( e) => {
77+ info ! ( "failed to connect to cloud hypervisor: {:?}" , e) ;
78+ Status :: new (
79+ tonic:: Code :: Internal ,
80+ "failed to connect to cloud hypervisor" ,
81+ )
82+ }
83+ vm:: Error :: CHApiFailure ( e) => {
84+ info ! ( "failed to connect to cloud hypervisor api: {:?}" , e) ;
85+ Status :: new (
86+ tonic:: Code :: Internal ,
87+ "failed to connect to cloud hypervisor api" ,
88+ )
89+ }
8890 }
89- vm:: Error :: Failed => Status :: new ( tonic:: Code :: AlreadyExists , "vm already exists" ) ,
9091 }
9192}
9293
@@ -191,7 +192,9 @@ impl FeosGrpc for FeOSAPI {
191192 info ! ( "Got create_vm request" ) ;
192193
193194 let id = Uuid :: new_v4 ( ) ;
194- self . vmm . init_vmm ( id, true ) . map_err ( handle_error) ?;
195+ self . vmm
196+ . init_vmm ( id, true )
197+ . map_err ( |e| self . handle_error ( e) ) ?;
195198
196199 let root_fs = PathBuf :: from ( format ! (
197200 "./images/{}/application.vnd.ironcore.image.rootfs.v1alpha1.rootfs" ,
@@ -205,7 +208,7 @@ impl FeosGrpc for FeOSAPI {
205208 vm:: BootMode :: FirmwareBoot ( vm:: FirmwareBootMode { root_fs } ) ,
206209 request. get_ref ( ) . ignition . clone ( ) ,
207210 )
208- . map_err ( handle_error) ?;
211+ . map_err ( |e| self . handle_error ( e ) ) ?;
209212
210213 Ok ( Response :: new ( feos_grpc:: CreateVmResponse {
211214 uuid : id. to_string ( ) ,
@@ -221,8 +224,8 @@ impl FeosGrpc for FeOSAPI {
221224 let id = request. get_ref ( ) . uuid . to_owned ( ) ;
222225 let id =
223226 Uuid :: parse_str ( & id) . map_err ( |_| Status :: invalid_argument ( "failed to parse uuid" ) ) ?;
224- self . vmm . ping_vmm ( id) . map_err ( handle_error) ?;
225- let vm_status = self . vmm . get_vm ( id) . map_err ( handle_error) ?;
227+ self . vmm . ping_vmm ( id) . map_err ( |e| self . handle_error ( e ) ) ?;
228+ let vm_status = self . vmm . get_vm ( id) . map_err ( |e| self . handle_error ( e ) ) ?;
226229
227230 Ok ( Response :: new ( feos_grpc:: GetVmResponse { info : vm_status } ) )
228231 }
@@ -236,7 +239,7 @@ impl FeosGrpc for FeOSAPI {
236239 let id = Uuid :: parse_str ( & request. get_ref ( ) . uuid )
237240 . map_err ( |_| Status :: invalid_argument ( "Failed to parse UUID" ) ) ?;
238241
239- self . vmm . boot_vm ( id) . map_err ( handle_error) ?;
242+ self . vmm . boot_vm ( id) . map_err ( |e| self . handle_error ( e ) ) ?;
240243
241244 Ok ( Response :: new ( feos_grpc:: BootVmResponse { } ) )
242245 }
@@ -263,7 +266,10 @@ impl FeosGrpc for FeOSAPI {
263266 } ;
264267 let id = Uuid :: parse_str ( & initial_request. uuid )
265268 . map_err ( |_| Status :: invalid_argument ( "failed to parse uuid" ) ) ?;
266- let socket_path = self . vmm . get_vm_console_path ( id) . map_err ( handle_error) ?;
269+ let socket_path = self
270+ . vmm
271+ . get_vm_console_path ( id)
272+ . map_err ( |e| self . handle_error ( e) ) ?;
267273
268274 tokio:: spawn ( async move {
269275 let stream = match UnixStream :: connect ( & socket_path) . await {
@@ -331,7 +337,7 @@ impl FeosGrpc for FeOSAPI {
331337
332338 self . vmm
333339 . add_net_device ( id, net_config)
334- . map_err ( handle_error) ?;
340+ . map_err ( |e| self . handle_error ( e ) ) ?;
335341
336342 Ok ( Response :: new ( feos_grpc:: AttachNicVmResponse { } ) )
337343 }
@@ -346,7 +352,7 @@ impl FeosGrpc for FeOSAPI {
346352 . map_err ( |_| Status :: invalid_argument ( "Failed to parse UUID" ) ) ?;
347353
348354 // TODO differentiate between kill and shutdown
349- self . vmm . kill_vm ( id) . map_err ( handle_error) ?;
355+ self . vmm . kill_vm ( id) . map_err ( |e| self . handle_error ( e ) ) ?;
350356
351357 Ok ( Response :: new ( feos_grpc:: ShutdownVmResponse { } ) )
352358 }
@@ -507,11 +513,7 @@ pub async fn daemon_start(
507513 Ok ( ( ) )
508514}
509515
510- pub async fn start_feos (
511- ipv6_address : Ipv6Addr ,
512- prefix_length : u8 ,
513- test_mode : bool ,
514- ) -> Result < ( ) , String > {
516+ pub async fn start_feos ( ipv6_address : Ipv6Addr , prefix_length : u8 ) -> Result < ( ) , String > {
515517 println ! (
516518 "
517519
0 commit comments