@@ -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
@@ -477,9 +476,7 @@ async fn instance_ensure(
477
476
None
478
477
} ;
479
478
480
- Ok ( HttpResponseCreated ( propolis_client:: api:: InstanceEnsureResponse {
481
- migrate,
482
- } ) )
479
+ Ok ( HttpResponseCreated ( api:: InstanceEnsureResponse { migrate } ) )
483
480
}
484
481
485
482
#[ endpoint {
@@ -488,8 +485,7 @@ async fn instance_ensure(
488
485
} ]
489
486
async fn instance_get (
490
487
rqctx : Arc < RequestContext < DropshotEndpointContext > > ,
491
- ) -> Result < HttpResponseOk < propolis_client:: api:: InstanceGetResponse > , HttpError >
492
- {
488
+ ) -> Result < HttpResponseOk < api:: InstanceGetResponse > , HttpError > {
493
489
let ctx = rqctx. context ( ) ;
494
490
let instance_info = match & * ctx. services . vm . lock ( ) . await {
495
491
VmControllerState :: NotCreated => {
@@ -498,7 +494,7 @@ async fn instance_get(
498
494
) ) ;
499
495
}
500
496
VmControllerState :: Created ( vm) => {
501
- propolis_client :: api:: Instance {
497
+ api:: Instance {
502
498
properties : vm. properties ( ) . clone ( ) ,
503
499
state : vm. external_instance_state ( ) ,
504
500
disks : vec ! [ ] ,
@@ -517,9 +513,7 @@ async fn instance_get(
517
513
}
518
514
} ;
519
515
520
- Ok ( HttpResponseOk ( propolis_client:: api:: InstanceGetResponse {
521
- instance : instance_info,
522
- } ) )
516
+ Ok ( HttpResponseOk ( api:: InstanceGetResponse { instance : instance_info } ) )
523
517
}
524
518
525
519
#[ endpoint {
@@ -730,3 +724,25 @@ pub fn api() -> ApiDescription<DropshotEndpointContext> {
730
724
731
725
api
732
726
}
727
+
728
+ #[ cfg( test) ]
729
+ mod tests {
730
+ #[ test]
731
+ fn test_propolis_server_openapi ( ) {
732
+ let mut buf: Vec < u8 > = vec ! [ ] ;
733
+ super :: api ( )
734
+ . openapi ( "Oxide Propolis Server API" , "0.0.1" )
735
+ . description (
736
+ "API for interacting with the Propolis hypervisor frontend." ,
737
+ )
738
+ . contact_url ( "https://oxide.computer" )
739
+ . contact_email ( "api@oxide.computer" )
740
+ . write ( & mut buf)
741
+ . unwrap ( ) ;
742
+ let output = String :: from_utf8 ( buf) . unwrap ( ) ;
743
+ expectorate:: assert_contents (
744
+ "../../openapi/propolis-server.json" ,
745
+ & output,
746
+ ) ;
747
+ }
748
+ }
0 commit comments