@@ -15,8 +15,10 @@ use dropshot::{
15
15
} ;
16
16
use hyper:: { Body , Response } ;
17
17
use oximeter:: types:: ProducerRegistry ;
18
- use propolis_client:: instance_spec;
19
- use propolis_client:: { api, instance_spec:: InstanceSpec } ;
18
+ use propolis_client:: {
19
+ handmade:: api,
20
+ instance_spec:: { self , InstanceSpec } ,
21
+ } ;
20
22
use propolis_server_config:: Config as VmTomlConfig ;
21
23
use rfb:: server:: VncServer ;
22
24
use slog:: { error, o, Logger } ;
@@ -111,9 +113,9 @@ impl VmControllerState {
111
113
/// `VmControllerState::Destroyed`.
112
114
pub fn take_controller ( & mut self ) -> Option < Arc < VmController > > {
113
115
if let VmControllerState :: Created ( vm) = self {
114
- let last_instance = propolis_client :: api:: Instance {
116
+ let last_instance = api:: Instance {
115
117
properties : vm. properties ( ) . clone ( ) ,
116
- state : propolis_client :: api:: InstanceState :: Destroyed ,
118
+ state : api:: InstanceState :: Destroyed ,
117
119
disks : vec ! [ ] ,
118
120
nics : vec ! [ ] ,
119
121
} ;
@@ -244,7 +246,7 @@ enum SpecCreationError {
244
246
/// Creates an instance spec from an ensure request. (Both types are foreign to
245
247
/// this crate, so implementing TryFrom for them is not allowed.)
246
248
fn instance_spec_from_request (
247
- request : & propolis_client :: api:: InstanceEnsureRequest ,
249
+ request : & api:: InstanceEnsureRequest ,
248
250
toml_config : & VmTomlConfig ,
249
251
) -> Result < ( InstanceSpec , BTreeMap < String , Vec < u8 > > ) , SpecCreationError > {
250
252
let mut in_memory_disk_contents: BTreeMap < String , Vec < u8 > > =
@@ -313,11 +315,8 @@ async fn register_oximeter(
313
315
} ]
314
316
async fn instance_ensure (
315
317
rqctx : Arc < RequestContext < DropshotEndpointContext > > ,
316
- request : TypedBody < propolis_client:: api:: InstanceEnsureRequest > ,
317
- ) -> Result <
318
- HttpResponseCreated < propolis_client:: api:: InstanceEnsureResponse > ,
319
- HttpError ,
320
- > {
318
+ request : TypedBody < api:: InstanceEnsureRequest > ,
319
+ ) -> Result < HttpResponseCreated < api:: InstanceEnsureResponse > , HttpError > {
321
320
let server_context = rqctx. context ( ) ;
322
321
let request = request. into_inner ( ) ;
323
322
@@ -448,9 +447,7 @@ async fn instance_ensure(
448
447
None
449
448
} ;
450
449
451
- Ok ( HttpResponseCreated ( propolis_client:: api:: InstanceEnsureResponse {
452
- migrate,
453
- } ) )
450
+ Ok ( HttpResponseCreated ( api:: InstanceEnsureResponse { migrate } ) )
454
451
}
455
452
456
453
#[ endpoint {
@@ -459,8 +456,7 @@ async fn instance_ensure(
459
456
} ]
460
457
async fn instance_get (
461
458
rqctx : Arc < RequestContext < DropshotEndpointContext > > ,
462
- ) -> Result < HttpResponseOk < propolis_client:: api:: InstanceGetResponse > , HttpError >
463
- {
459
+ ) -> Result < HttpResponseOk < api:: InstanceGetResponse > , HttpError > {
464
460
let ctx = rqctx. context ( ) ;
465
461
let instance_info = match & * ctx. services . vm . lock ( ) . await {
466
462
VmControllerState :: NotCreated => {
@@ -469,7 +465,7 @@ async fn instance_get(
469
465
) ) ;
470
466
}
471
467
VmControllerState :: Created ( vm) => {
472
- propolis_client :: api:: Instance {
468
+ api:: Instance {
473
469
properties : vm. properties ( ) . clone ( ) ,
474
470
state : vm. external_instance_state ( ) ,
475
471
disks : vec ! [ ] ,
@@ -488,9 +484,7 @@ async fn instance_get(
488
484
}
489
485
} ;
490
486
491
- Ok ( HttpResponseOk ( propolis_client:: api:: InstanceGetResponse {
492
- instance : instance_info,
493
- } ) )
487
+ Ok ( HttpResponseOk ( api:: InstanceGetResponse { instance : instance_info } ) )
494
488
}
495
489
496
490
#[ endpoint {
@@ -701,3 +695,25 @@ pub fn api() -> ApiDescription<DropshotEndpointContext> {
701
695
702
696
api
703
697
}
698
+
699
+ #[ cfg( test) ]
700
+ mod tests {
701
+ #[ test]
702
+ fn test_propolis_server_openapi ( ) {
703
+ let mut buf: Vec < u8 > = vec ! [ ] ;
704
+ super :: api ( )
705
+ . openapi ( "Oxide Propolis Server API" , "0.0.1" )
706
+ . description (
707
+ "API for interacting with the Propolis hypervisor frontend." ,
708
+ )
709
+ . contact_url ( "https://oxide.computer" )
710
+ . contact_email ( "api@oxide.computer" )
711
+ . write ( & mut buf)
712
+ . unwrap ( ) ;
713
+ let output = String :: from_utf8 ( buf) . unwrap ( ) ;
714
+ expectorate:: assert_contents (
715
+ "../../openapi/propolis-server.json" ,
716
+ & output,
717
+ ) ;
718
+ }
719
+ }
0 commit comments