#[allow(unused_imports)] use progenitor_client::{encode_path, RequestBuilderExt}; pub use progenitor_client::{ByteStream, Error, ResponseValue}; #[allow(unused_imports)] use reqwest::header::{HeaderMap, HeaderValue}; pub mod types { use serde::{Deserialize, Serialize}; #[allow(unused_imports)] use std::convert::TryFrom; #[derive(Clone, Debug, Deserialize, JsonSchema, Serialize)] pub struct CrucibleOpts { #[serde(default, skip_serializing_if = "Option::is_none")] pub cert_pem: Option, #[serde(default, skip_serializing_if = "Option::is_none")] pub control: Option, #[serde(default, skip_serializing_if = "Option::is_none")] pub flush_timeout: Option, pub id: uuid::Uuid, #[serde(default, skip_serializing_if = "Option::is_none")] pub key: Option, #[serde(default, skip_serializing_if = "Option::is_none")] pub key_pem: Option, pub lossy: bool, pub read_only: bool, #[serde(default, skip_serializing_if = "Option::is_none")] pub root_cert_pem: Option, pub target: Vec, } impl CrucibleOpts { pub fn builder() -> builder::CrucibleOpts { builder::CrucibleOpts::default() } } #[derive(Clone, Debug, Deserialize, JsonSchema, Serialize)] pub struct DiskAttachment { pub disk_id: uuid::Uuid, pub generation_id: u64, pub state: DiskAttachmentState, } impl DiskAttachment { pub fn builder() -> builder::DiskAttachment { builder::DiskAttachment::default() } } #[derive(Clone, Debug, Deserialize, JsonSchema, Serialize)] pub enum DiskAttachmentState { Detached, Destroyed, Faulted, Attached(uuid::Uuid), } #[derive(Clone, Debug, Deserialize, JsonSchema, Serialize)] pub struct DiskRequest { pub device: String, pub gen: u64, pub name: String, pub read_only: bool, pub slot: Slot, pub volume_construction_request: VolumeConstructionRequest, } impl DiskRequest { pub fn builder() -> builder::DiskRequest { builder::DiskRequest::default() } } ///Error information from a response. #[derive(Clone, Debug, Deserialize, JsonSchema, Serialize)] pub struct Error { #[serde(default, skip_serializing_if = "Option::is_none")] pub error_code: Option, pub message: String, pub request_id: String, } impl Error { pub fn builder() -> builder::Error { builder::Error::default() } } #[derive(Clone, Debug, Deserialize, JsonSchema, Serialize)] pub struct Instance { pub disks: Vec, pub nics: Vec, pub properties: InstanceProperties, pub state: InstanceState, } impl Instance { pub fn builder() -> builder::Instance { builder::Instance::default() } } #[derive(Clone, Debug, Deserialize, JsonSchema, Serialize)] pub struct InstanceEnsureRequest { #[serde(default, skip_serializing_if = "Option::is_none")] pub cloud_init_bytes: Option, #[serde(default, skip_serializing_if = "Vec::is_empty")] pub disks: Vec, #[serde(default, skip_serializing_if = "Option::is_none")] pub migrate: Option, #[serde(default, skip_serializing_if = "Vec::is_empty")] pub nics: Vec, pub properties: InstanceProperties, } impl InstanceEnsureRequest { pub fn builder() -> builder::InstanceEnsureRequest { builder::InstanceEnsureRequest::default() } } #[derive(Clone, Debug, Deserialize, JsonSchema, Serialize)] pub struct InstanceEnsureResponse { #[serde(default, skip_serializing_if = "Option::is_none")] pub migrate: Option, } impl InstanceEnsureResponse { pub fn builder() -> builder::InstanceEnsureResponse { builder::InstanceEnsureResponse::default() } } #[derive(Clone, Debug, Deserialize, JsonSchema, Serialize)] pub struct InstanceGetResponse { pub instance: Instance, } impl InstanceGetResponse { pub fn builder() -> builder::InstanceGetResponse { builder::InstanceGetResponse::default() } } #[derive(Clone, Debug, Deserialize, JsonSchema, Serialize)] pub struct InstanceMigrateInitiateRequest { pub migration_id: uuid::Uuid, pub src_addr: String, pub src_uuid: uuid::Uuid, } impl InstanceMigrateInitiateRequest { pub fn builder() -> builder::InstanceMigrateInitiateRequest { builder::InstanceMigrateInitiateRequest::default() } } #[derive(Clone, Debug, Deserialize, JsonSchema, Serialize)] pub struct InstanceMigrateInitiateResponse { pub migration_id: uuid::Uuid, } impl InstanceMigrateInitiateResponse { pub fn builder() -> builder::InstanceMigrateInitiateResponse { builder::InstanceMigrateInitiateResponse::default() } } #[derive(Clone, Debug, Deserialize, JsonSchema, Serialize)] pub struct InstanceMigrateStatusRequest { pub migration_id: uuid::Uuid, } impl InstanceMigrateStatusRequest { pub fn builder() -> builder::InstanceMigrateStatusRequest { builder::InstanceMigrateStatusRequest::default() } } #[derive(Clone, Debug, Deserialize, JsonSchema, Serialize)] pub struct InstanceMigrateStatusResponse { pub state: MigrationState, } impl InstanceMigrateStatusResponse { pub fn builder() -> builder::InstanceMigrateStatusResponse { builder::InstanceMigrateStatusResponse::default() } } #[derive(Clone, Debug, Deserialize, JsonSchema, Serialize)] pub struct InstanceProperties { ///ID of the bootrom used to initialize this Instance. pub bootrom_id: uuid::Uuid, ///Free-form text description of an Instance. pub description: String, ///Unique identifier for this Instance. pub id: uuid::Uuid, ///ID of the image used to initialize this Instance. pub image_id: uuid::Uuid, ///Size of memory allocated to the Instance, in MiB. pub memory: u64, ///Human-readable name of the Instance. pub name: String, ///Number of vCPUs to be allocated to the Instance. pub vcpus: u8, } impl InstanceProperties { pub fn builder() -> builder::InstanceProperties { builder::InstanceProperties::default() } } ///Current state of an Instance. #[derive( Clone, Copy, Debug, Deserialize, Eq, Hash, JsonSchema, Ord, PartialEq, PartialOrd, Serialize, )] pub enum InstanceState { Creating, Starting, Running, Stopping, Stopped, Rebooting, Migrating, Repairing, Failed, Destroyed, } impl ToString for InstanceState { fn to_string(&self) -> String { match *self { Self::Creating => "Creating".to_string(), Self::Starting => "Starting".to_string(), Self::Running => "Running".to_string(), Self::Stopping => "Stopping".to_string(), Self::Stopped => "Stopped".to_string(), Self::Rebooting => "Rebooting".to_string(), Self::Migrating => "Migrating".to_string(), Self::Repairing => "Repairing".to_string(), Self::Failed => "Failed".to_string(), Self::Destroyed => "Destroyed".to_string(), } } } impl std::str::FromStr for InstanceState { type Err = &'static str; fn from_str(value: &str) -> Result { match value { "Creating" => Ok(Self::Creating), "Starting" => Ok(Self::Starting), "Running" => Ok(Self::Running), "Stopping" => Ok(Self::Stopping), "Stopped" => Ok(Self::Stopped), "Rebooting" => Ok(Self::Rebooting), "Migrating" => Ok(Self::Migrating), "Repairing" => Ok(Self::Repairing), "Failed" => Ok(Self::Failed), "Destroyed" => Ok(Self::Destroyed), _ => Err("invalid value"), } } } #[derive(Clone, Debug, Deserialize, JsonSchema, Serialize)] pub struct InstanceStateMonitorRequest { pub gen: u64, } impl InstanceStateMonitorRequest { pub fn builder() -> builder::InstanceStateMonitorRequest { builder::InstanceStateMonitorRequest::default() } } #[derive(Clone, Debug, Deserialize, JsonSchema, Serialize)] pub struct InstanceStateMonitorResponse { pub gen: u64, pub state: InstanceState, } impl InstanceStateMonitorResponse { pub fn builder() -> builder::InstanceStateMonitorResponse { builder::InstanceStateMonitorResponse::default() } } #[derive( Clone, Copy, Debug, Deserialize, Eq, Hash, JsonSchema, Ord, PartialEq, PartialOrd, Serialize, )] pub enum InstanceStateRequested { Run, Stop, Reboot, MigrateStart, } impl ToString for InstanceStateRequested { fn to_string(&self) -> String { match *self { Self::Run => "Run".to_string(), Self::Stop => "Stop".to_string(), Self::Reboot => "Reboot".to_string(), Self::MigrateStart => "MigrateStart".to_string(), } } } impl std::str::FromStr for InstanceStateRequested { type Err = &'static str; fn from_str(value: &str) -> Result { match value { "Run" => Ok(Self::Run), "Stop" => Ok(Self::Stop), "Reboot" => Ok(Self::Reboot), "MigrateStart" => Ok(Self::MigrateStart), _ => Err("invalid value"), } } } #[derive( Clone, Copy, Debug, Deserialize, Eq, Hash, JsonSchema, Ord, PartialEq, PartialOrd, Serialize, )] pub enum MigrationState { Sync, RamPush, Pause, RamPushDirty, Device, Arch, Resume, RamPull, Finish, Error, } impl ToString for MigrationState { fn to_string(&self) -> String { match *self { Self::Sync => "Sync".to_string(), Self::RamPush => "RamPush".to_string(), Self::Pause => "Pause".to_string(), Self::RamPushDirty => "RamPushDirty".to_string(), Self::Device => "Device".to_string(), Self::Arch => "Arch".to_string(), Self::Resume => "Resume".to_string(), Self::RamPull => "RamPull".to_string(), Self::Finish => "Finish".to_string(), Self::Error => "Error".to_string(), } } } impl std::str::FromStr for MigrationState { type Err = &'static str; fn from_str(value: &str) -> Result { match value { "Sync" => Ok(Self::Sync), "RamPush" => Ok(Self::RamPush), "Pause" => Ok(Self::Pause), "RamPushDirty" => Ok(Self::RamPushDirty), "Device" => Ok(Self::Device), "Arch" => Ok(Self::Arch), "Resume" => Ok(Self::Resume), "RamPull" => Ok(Self::RamPull), "Finish" => Ok(Self::Finish), "Error" => Ok(Self::Error), _ => Err("invalid value"), } } } #[derive(Clone, Debug, Deserialize, JsonSchema, Serialize)] pub struct NetworkInterface { pub attachment: NetworkInterfaceAttachmentState, pub name: String, } impl NetworkInterface { pub fn builder() -> builder::NetworkInterface { builder::NetworkInterface::default() } } #[derive(Clone, Debug, Deserialize, JsonSchema, Serialize)] pub enum NetworkInterfaceAttachmentState { Detached, Faulted, Attached(Slot), } #[derive(Clone, Debug, Deserialize, JsonSchema, Serialize)] pub struct NetworkInterfaceRequest { pub name: String, pub slot: Slot, } impl NetworkInterfaceRequest { pub fn builder() -> builder::NetworkInterfaceRequest { builder::NetworkInterfaceRequest::default() } } ///A stable index which is translated by Propolis into a PCI BDF, visible /// to the guest. #[derive(Clone, Debug, Deserialize, JsonSchema, Serialize)] pub struct Slot(pub u8); impl std::ops::Deref for Slot { type Target = u8; fn deref(&self) -> &Self::Target { &self.0 } } #[derive(Clone, Debug, Deserialize, JsonSchema, Serialize)] #[serde(tag = "type")] pub enum VolumeConstructionRequest { #[serde(rename = "volume")] Volume { block_size: u64, id: uuid::Uuid, #[serde(default, skip_serializing_if = "Option::is_none")] read_only_parent: Option>, sub_volumes: Vec, }, #[serde(rename = "url")] Url { block_size: u64, id: uuid::Uuid, url: String, }, #[serde(rename = "region")] Region { block_size: u64, gen: u64, opts: CrucibleOpts, }, #[serde(rename = "file")] File { block_size: u64, id: uuid::Uuid, path: String, }, } mod builder { pub struct CrucibleOpts { cert_pem: Result, String>, control: Result, String>, flush_timeout: Result, String>, id: Result, key: Result, String>, key_pem: Result, String>, lossy: Result, read_only: Result, root_cert_pem: Result, String>, target: Result, String>, } impl Default for CrucibleOpts { fn default() -> Self { Self { cert_pem: Ok(Default::default()), control: Ok(Default::default()), flush_timeout: Ok(Default::default()), id: Err("no value supplied for id".to_string()), key: Ok(Default::default()), key_pem: Ok(Default::default()), lossy: Err("no value supplied for lossy".to_string()), read_only: Err("no value supplied for read_only".to_string()), root_cert_pem: Ok(Default::default()), target: Err("no value supplied for target".to_string()), } } } impl CrucibleOpts { pub fn cert_pem(mut self, value: T) -> Self where T: std::convert::TryInto>, T::Error: std::fmt::Display, { self.cert_pem = value .try_into() .map_err(|e| format!("error converting supplied value for cert_pem: {}", e)); self } pub fn control(mut self, value: T) -> Self where T: std::convert::TryInto>, T::Error: std::fmt::Display, { self.control = value .try_into() .map_err(|e| format!("error converting supplied value for control: {}", e)); self } pub fn flush_timeout(mut self, value: T) -> Self where T: std::convert::TryInto>, T::Error: std::fmt::Display, { self.flush_timeout = value.try_into().map_err(|e| { format!("error converting supplied value for flush_timeout: {}", e) }); self } pub fn id(mut self, value: T) -> Self where T: std::convert::TryInto, T::Error: std::fmt::Display, { self.id = value .try_into() .map_err(|e| format!("error converting supplied value for id: {}", e)); self } pub fn key(mut self, value: T) -> Self where T: std::convert::TryInto>, T::Error: std::fmt::Display, { self.key = value .try_into() .map_err(|e| format!("error converting supplied value for key: {}", e)); self } pub fn key_pem(mut self, value: T) -> Self where T: std::convert::TryInto>, T::Error: std::fmt::Display, { self.key_pem = value .try_into() .map_err(|e| format!("error converting supplied value for key_pem: {}", e)); self } pub fn lossy(mut self, value: T) -> Self where T: std::convert::TryInto, T::Error: std::fmt::Display, { self.lossy = value .try_into() .map_err(|e| format!("error converting supplied value for lossy: {}", e)); self } pub fn read_only(mut self, value: T) -> Self where T: std::convert::TryInto, T::Error: std::fmt::Display, { self.read_only = value .try_into() .map_err(|e| format!("error converting supplied value for read_only: {}", e)); self } pub fn root_cert_pem(mut self, value: T) -> Self where T: std::convert::TryInto>, T::Error: std::fmt::Display, { self.root_cert_pem = value.try_into().map_err(|e| { format!("error converting supplied value for root_cert_pem: {}", e) }); self } pub fn target(mut self, value: T) -> Self where T: std::convert::TryInto>, T::Error: std::fmt::Display, { self.target = value .try_into() .map_err(|e| format!("error converting supplied value for target: {}", e)); self } } impl std::convert::TryFrom for super::CrucibleOpts { type Error = String; fn try_from(value: CrucibleOpts) -> Result { Ok(Self { cert_pem: value.cert_pem?, control: value.control?, flush_timeout: value.flush_timeout?, id: value.id?, key: value.key?, key_pem: value.key_pem?, lossy: value.lossy?, read_only: value.read_only?, root_cert_pem: value.root_cert_pem?, target: value.target?, }) } } pub struct DiskAttachment { disk_id: Result, generation_id: Result, state: Result, } impl Default for DiskAttachment { fn default() -> Self { Self { disk_id: Err("no value supplied for disk_id".to_string()), generation_id: Err("no value supplied for generation_id".to_string()), state: Err("no value supplied for state".to_string()), } } } impl DiskAttachment { pub fn disk_id(mut self, value: T) -> Self where T: std::convert::TryInto, T::Error: std::fmt::Display, { self.disk_id = value .try_into() .map_err(|e| format!("error converting supplied value for disk_id: {}", e)); self } pub fn generation_id(mut self, value: T) -> Self where T: std::convert::TryInto, T::Error: std::fmt::Display, { self.generation_id = value.try_into().map_err(|e| { format!("error converting supplied value for generation_id: {}", e) }); self } pub fn state(mut self, value: T) -> Self where T: std::convert::TryInto, T::Error: std::fmt::Display, { self.state = value .try_into() .map_err(|e| format!("error converting supplied value for state: {}", e)); self } } impl std::convert::TryFrom for super::DiskAttachment { type Error = String; fn try_from(value: DiskAttachment) -> Result { Ok(Self { disk_id: value.disk_id?, generation_id: value.generation_id?, state: value.state?, }) } } pub struct DiskRequest { device: Result, gen: Result, name: Result, read_only: Result, slot: Result, volume_construction_request: Result, } impl Default for DiskRequest { fn default() -> Self { Self { device: Err("no value supplied for device".to_string()), gen: Err("no value supplied for gen".to_string()), name: Err("no value supplied for name".to_string()), read_only: Err("no value supplied for read_only".to_string()), slot: Err("no value supplied for slot".to_string()), volume_construction_request: Err( "no value supplied for volume_construction_request".to_string(), ), } } } impl DiskRequest { pub fn device(mut self, value: T) -> Self where T: std::convert::TryInto, T::Error: std::fmt::Display, { self.device = value .try_into() .map_err(|e| format!("error converting supplied value for device: {}", e)); self } pub fn gen(mut self, value: T) -> Self where T: std::convert::TryInto, T::Error: std::fmt::Display, { self.gen = value .try_into() .map_err(|e| format!("error converting supplied value for gen: {}", e)); self } pub fn name(mut self, value: T) -> Self where T: std::convert::TryInto, T::Error: std::fmt::Display, { self.name = value .try_into() .map_err(|e| format!("error converting supplied value for name: {}", e)); self } pub fn read_only(mut self, value: T) -> Self where T: std::convert::TryInto, T::Error: std::fmt::Display, { self.read_only = value .try_into() .map_err(|e| format!("error converting supplied value for read_only: {}", e)); self } pub fn slot(mut self, value: T) -> Self where T: std::convert::TryInto, T::Error: std::fmt::Display, { self.slot = value .try_into() .map_err(|e| format!("error converting supplied value for slot: {}", e)); self } pub fn volume_construction_request(mut self, value: T) -> Self where T: std::convert::TryInto, T::Error: std::fmt::Display, { self.volume_construction_request = value.try_into().map_err(|e| { format!( "error converting supplied value for volume_construction_request: {}", e ) }); self } } impl std::convert::TryFrom for super::DiskRequest { type Error = String; fn try_from(value: DiskRequest) -> Result { Ok(Self { device: value.device?, gen: value.gen?, name: value.name?, read_only: value.read_only?, slot: value.slot?, volume_construction_request: value.volume_construction_request?, }) } } pub struct Error { error_code: Result, String>, message: Result, request_id: Result, } impl Default for Error { fn default() -> Self { Self { error_code: Ok(Default::default()), message: Err("no value supplied for message".to_string()), request_id: Err("no value supplied for request_id".to_string()), } } } impl Error { pub fn error_code(mut self, value: T) -> Self where T: std::convert::TryInto>, T::Error: std::fmt::Display, { self.error_code = value .try_into() .map_err(|e| format!("error converting supplied value for error_code: {}", e)); self } pub fn message(mut self, value: T) -> Self where T: std::convert::TryInto, T::Error: std::fmt::Display, { self.message = value .try_into() .map_err(|e| format!("error converting supplied value for message: {}", e)); self } pub fn request_id(mut self, value: T) -> Self where T: std::convert::TryInto, T::Error: std::fmt::Display, { self.request_id = value .try_into() .map_err(|e| format!("error converting supplied value for request_id: {}", e)); self } } impl std::convert::TryFrom for super::Error { type Error = String; fn try_from(value: Error) -> Result { Ok(Self { error_code: value.error_code?, message: value.message?, request_id: value.request_id?, }) } } pub struct Instance { disks: Result, String>, nics: Result, String>, properties: Result, state: Result, } impl Default for Instance { fn default() -> Self { Self { disks: Err("no value supplied for disks".to_string()), nics: Err("no value supplied for nics".to_string()), properties: Err("no value supplied for properties".to_string()), state: Err("no value supplied for state".to_string()), } } } impl Instance { pub fn disks(mut self, value: T) -> Self where T: std::convert::TryInto>, T::Error: std::fmt::Display, { self.disks = value .try_into() .map_err(|e| format!("error converting supplied value for disks: {}", e)); self } pub fn nics(mut self, value: T) -> Self where T: std::convert::TryInto>, T::Error: std::fmt::Display, { self.nics = value .try_into() .map_err(|e| format!("error converting supplied value for nics: {}", e)); self } pub fn properties(mut self, value: T) -> Self where T: std::convert::TryInto, T::Error: std::fmt::Display, { self.properties = value .try_into() .map_err(|e| format!("error converting supplied value for properties: {}", e)); self } pub fn state(mut self, value: T) -> Self where T: std::convert::TryInto, T::Error: std::fmt::Display, { self.state = value .try_into() .map_err(|e| format!("error converting supplied value for state: {}", e)); self } } impl std::convert::TryFrom for super::Instance { type Error = String; fn try_from(value: Instance) -> Result { Ok(Self { disks: value.disks?, nics: value.nics?, properties: value.properties?, state: value.state?, }) } } pub struct InstanceEnsureRequest { cloud_init_bytes: Result, String>, disks: Result, String>, migrate: Result, String>, nics: Result, String>, properties: Result, } impl Default for InstanceEnsureRequest { fn default() -> Self { Self { cloud_init_bytes: Ok(Default::default()), disks: Ok(Default::default()), migrate: Ok(Default::default()), nics: Ok(Default::default()), properties: Err("no value supplied for properties".to_string()), } } } impl InstanceEnsureRequest { pub fn cloud_init_bytes(mut self, value: T) -> Self where T: std::convert::TryInto>, T::Error: std::fmt::Display, { self.cloud_init_bytes = value.try_into().map_err(|e| { format!( "error converting supplied value for cloud_init_bytes: {}", e ) }); self } pub fn disks(mut self, value: T) -> Self where T: std::convert::TryInto>, T::Error: std::fmt::Display, { self.disks = value .try_into() .map_err(|e| format!("error converting supplied value for disks: {}", e)); self } pub fn migrate(mut self, value: T) -> Self where T: std::convert::TryInto>, T::Error: std::fmt::Display, { self.migrate = value .try_into() .map_err(|e| format!("error converting supplied value for migrate: {}", e)); self } pub fn nics(mut self, value: T) -> Self where T: std::convert::TryInto>, T::Error: std::fmt::Display, { self.nics = value .try_into() .map_err(|e| format!("error converting supplied value for nics: {}", e)); self } pub fn properties(mut self, value: T) -> Self where T: std::convert::TryInto, T::Error: std::fmt::Display, { self.properties = value .try_into() .map_err(|e| format!("error converting supplied value for properties: {}", e)); self } } impl std::convert::TryFrom for super::InstanceEnsureRequest { type Error = String; fn try_from(value: InstanceEnsureRequest) -> Result { Ok(Self { cloud_init_bytes: value.cloud_init_bytes?, disks: value.disks?, migrate: value.migrate?, nics: value.nics?, properties: value.properties?, }) } } pub struct InstanceEnsureResponse { migrate: Result, String>, } impl Default for InstanceEnsureResponse { fn default() -> Self { Self { migrate: Ok(Default::default()), } } } impl InstanceEnsureResponse { pub fn migrate(mut self, value: T) -> Self where T: std::convert::TryInto>, T::Error: std::fmt::Display, { self.migrate = value .try_into() .map_err(|e| format!("error converting supplied value for migrate: {}", e)); self } } impl std::convert::TryFrom for super::InstanceEnsureResponse { type Error = String; fn try_from(value: InstanceEnsureResponse) -> Result { Ok(Self { migrate: value.migrate?, }) } } pub struct InstanceGetResponse { instance: Result, } impl Default for InstanceGetResponse { fn default() -> Self { Self { instance: Err("no value supplied for instance".to_string()), } } } impl InstanceGetResponse { pub fn instance(mut self, value: T) -> Self where T: std::convert::TryInto, T::Error: std::fmt::Display, { self.instance = value .try_into() .map_err(|e| format!("error converting supplied value for instance: {}", e)); self } } impl std::convert::TryFrom for super::InstanceGetResponse { type Error = String; fn try_from(value: InstanceGetResponse) -> Result { Ok(Self { instance: value.instance?, }) } } pub struct InstanceMigrateInitiateRequest { migration_id: Result, src_addr: Result, src_uuid: Result, } impl Default for InstanceMigrateInitiateRequest { fn default() -> Self { Self { migration_id: Err("no value supplied for migration_id".to_string()), src_addr: Err("no value supplied for src_addr".to_string()), src_uuid: Err("no value supplied for src_uuid".to_string()), } } } impl InstanceMigrateInitiateRequest { pub fn migration_id(mut self, value: T) -> Self where T: std::convert::TryInto, T::Error: std::fmt::Display, { self.migration_id = value.try_into().map_err(|e| { format!("error converting supplied value for migration_id: {}", e) }); self } pub fn src_addr(mut self, value: T) -> Self where T: std::convert::TryInto, T::Error: std::fmt::Display, { self.src_addr = value .try_into() .map_err(|e| format!("error converting supplied value for src_addr: {}", e)); self } pub fn src_uuid(mut self, value: T) -> Self where T: std::convert::TryInto, T::Error: std::fmt::Display, { self.src_uuid = value .try_into() .map_err(|e| format!("error converting supplied value for src_uuid: {}", e)); self } } impl std::convert::TryFrom for super::InstanceMigrateInitiateRequest { type Error = String; fn try_from(value: InstanceMigrateInitiateRequest) -> Result { Ok(Self { migration_id: value.migration_id?, src_addr: value.src_addr?, src_uuid: value.src_uuid?, }) } } pub struct InstanceMigrateInitiateResponse { migration_id: Result, } impl Default for InstanceMigrateInitiateResponse { fn default() -> Self { Self { migration_id: Err("no value supplied for migration_id".to_string()), } } } impl InstanceMigrateInitiateResponse { pub fn migration_id(mut self, value: T) -> Self where T: std::convert::TryInto, T::Error: std::fmt::Display, { self.migration_id = value.try_into().map_err(|e| { format!("error converting supplied value for migration_id: {}", e) }); self } } impl std::convert::TryFrom for super::InstanceMigrateInitiateResponse { type Error = String; fn try_from(value: InstanceMigrateInitiateResponse) -> Result { Ok(Self { migration_id: value.migration_id?, }) } } pub struct InstanceMigrateStatusRequest { migration_id: Result, } impl Default for InstanceMigrateStatusRequest { fn default() -> Self { Self { migration_id: Err("no value supplied for migration_id".to_string()), } } } impl InstanceMigrateStatusRequest { pub fn migration_id(mut self, value: T) -> Self where T: std::convert::TryInto, T::Error: std::fmt::Display, { self.migration_id = value.try_into().map_err(|e| { format!("error converting supplied value for migration_id: {}", e) }); self } } impl std::convert::TryFrom for super::InstanceMigrateStatusRequest { type Error = String; fn try_from(value: InstanceMigrateStatusRequest) -> Result { Ok(Self { migration_id: value.migration_id?, }) } } pub struct InstanceMigrateStatusResponse { state: Result, } impl Default for InstanceMigrateStatusResponse { fn default() -> Self { Self { state: Err("no value supplied for state".to_string()), } } } impl InstanceMigrateStatusResponse { pub fn state(mut self, value: T) -> Self where T: std::convert::TryInto, T::Error: std::fmt::Display, { self.state = value .try_into() .map_err(|e| format!("error converting supplied value for state: {}", e)); self } } impl std::convert::TryFrom for super::InstanceMigrateStatusResponse { type Error = String; fn try_from(value: InstanceMigrateStatusResponse) -> Result { Ok(Self { state: value.state?, }) } } pub struct InstanceProperties { bootrom_id: Result, description: Result, id: Result, image_id: Result, memory: Result, name: Result, vcpus: Result, } impl Default for InstanceProperties { fn default() -> Self { Self { bootrom_id: Err("no value supplied for bootrom_id".to_string()), description: Err("no value supplied for description".to_string()), id: Err("no value supplied for id".to_string()), image_id: Err("no value supplied for image_id".to_string()), memory: Err("no value supplied for memory".to_string()), name: Err("no value supplied for name".to_string()), vcpus: Err("no value supplied for vcpus".to_string()), } } } impl InstanceProperties { pub fn bootrom_id(mut self, value: T) -> Self where T: std::convert::TryInto, T::Error: std::fmt::Display, { self.bootrom_id = value .try_into() .map_err(|e| format!("error converting supplied value for bootrom_id: {}", e)); self } pub fn description(mut self, value: T) -> Self where T: std::convert::TryInto, T::Error: std::fmt::Display, { self.description = value .try_into() .map_err(|e| format!("error converting supplied value for description: {}", e)); self } pub fn id(mut self, value: T) -> Self where T: std::convert::TryInto, T::Error: std::fmt::Display, { self.id = value .try_into() .map_err(|e| format!("error converting supplied value for id: {}", e)); self } pub fn image_id(mut self, value: T) -> Self where T: std::convert::TryInto, T::Error: std::fmt::Display, { self.image_id = value .try_into() .map_err(|e| format!("error converting supplied value for image_id: {}", e)); self } pub fn memory(mut self, value: T) -> Self where T: std::convert::TryInto, T::Error: std::fmt::Display, { self.memory = value .try_into() .map_err(|e| format!("error converting supplied value for memory: {}", e)); self } pub fn name(mut self, value: T) -> Self where T: std::convert::TryInto, T::Error: std::fmt::Display, { self.name = value .try_into() .map_err(|e| format!("error converting supplied value for name: {}", e)); self } pub fn vcpus(mut self, value: T) -> Self where T: std::convert::TryInto, T::Error: std::fmt::Display, { self.vcpus = value .try_into() .map_err(|e| format!("error converting supplied value for vcpus: {}", e)); self } } impl std::convert::TryFrom for super::InstanceProperties { type Error = String; fn try_from(value: InstanceProperties) -> Result { Ok(Self { bootrom_id: value.bootrom_id?, description: value.description?, id: value.id?, image_id: value.image_id?, memory: value.memory?, name: value.name?, vcpus: value.vcpus?, }) } } pub struct InstanceStateMonitorRequest { gen: Result, } impl Default for InstanceStateMonitorRequest { fn default() -> Self { Self { gen: Err("no value supplied for gen".to_string()), } } } impl InstanceStateMonitorRequest { pub fn gen(mut self, value: T) -> Self where T: std::convert::TryInto, T::Error: std::fmt::Display, { self.gen = value .try_into() .map_err(|e| format!("error converting supplied value for gen: {}", e)); self } } impl std::convert::TryFrom for super::InstanceStateMonitorRequest { type Error = String; fn try_from(value: InstanceStateMonitorRequest) -> Result { Ok(Self { gen: value.gen? }) } } pub struct InstanceStateMonitorResponse { gen: Result, state: Result, } impl Default for InstanceStateMonitorResponse { fn default() -> Self { Self { gen: Err("no value supplied for gen".to_string()), state: Err("no value supplied for state".to_string()), } } } impl InstanceStateMonitorResponse { pub fn gen(mut self, value: T) -> Self where T: std::convert::TryInto, T::Error: std::fmt::Display, { self.gen = value .try_into() .map_err(|e| format!("error converting supplied value for gen: {}", e)); self } pub fn state(mut self, value: T) -> Self where T: std::convert::TryInto, T::Error: std::fmt::Display, { self.state = value .try_into() .map_err(|e| format!("error converting supplied value for state: {}", e)); self } } impl std::convert::TryFrom for super::InstanceStateMonitorResponse { type Error = String; fn try_from(value: InstanceStateMonitorResponse) -> Result { Ok(Self { gen: value.gen?, state: value.state?, }) } } pub struct NetworkInterface { attachment: Result, name: Result, } impl Default for NetworkInterface { fn default() -> Self { Self { attachment: Err("no value supplied for attachment".to_string()), name: Err("no value supplied for name".to_string()), } } } impl NetworkInterface { pub fn attachment(mut self, value: T) -> Self where T: std::convert::TryInto, T::Error: std::fmt::Display, { self.attachment = value .try_into() .map_err(|e| format!("error converting supplied value for attachment: {}", e)); self } pub fn name(mut self, value: T) -> Self where T: std::convert::TryInto, T::Error: std::fmt::Display, { self.name = value .try_into() .map_err(|e| format!("error converting supplied value for name: {}", e)); self } } impl std::convert::TryFrom for super::NetworkInterface { type Error = String; fn try_from(value: NetworkInterface) -> Result { Ok(Self { attachment: value.attachment?, name: value.name?, }) } } pub struct NetworkInterfaceRequest { name: Result, slot: Result, } impl Default for NetworkInterfaceRequest { fn default() -> Self { Self { name: Err("no value supplied for name".to_string()), slot: Err("no value supplied for slot".to_string()), } } } impl NetworkInterfaceRequest { pub fn name(mut self, value: T) -> Self where T: std::convert::TryInto, T::Error: std::fmt::Display, { self.name = value .try_into() .map_err(|e| format!("error converting supplied value for name: {}", e)); self } pub fn slot(mut self, value: T) -> Self where T: std::convert::TryInto, T::Error: std::fmt::Display, { self.slot = value .try_into() .map_err(|e| format!("error converting supplied value for slot: {}", e)); self } } impl std::convert::TryFrom for super::NetworkInterfaceRequest { type Error = String; fn try_from(value: NetworkInterfaceRequest) -> Result { Ok(Self { name: value.name?, slot: value.slot?, }) } } } } #[derive(Clone, Debug)] ///Client for Oxide Propolis Server API /// ///API for interacting with the Propolis hypervisor frontend. pub struct Client { pub(crate) baseurl: String, pub(crate) client: reqwest::Client, } impl Client { /// Create a new client. /// /// `baseurl` is the base URL provided to the internal /// `reqwest::Client`, and should include a scheme and hostname, /// as well as port and a path stem if applicable. pub fn new(baseurl: &str) -> Self { let dur = std::time::Duration::from_secs(15); let client = reqwest::ClientBuilder::new() .connect_timeout(dur) .timeout(dur) .build() .unwrap(); Self::new_with_client(baseurl, client) } /// Construct a new client with an existing `reqwest::Client`, /// allowing more control over its configuration. /// /// `baseurl` is the base URL provided to the internal /// `reqwest::Client`, and should include a scheme and hostname, /// as well as port and a path stem if applicable. pub fn new_with_client(baseurl: &str, client: reqwest::Client) -> Self { Self { baseurl: baseurl.to_string(), client, } } /// Return the base URL to which requests are made. pub fn baseurl(&self) -> &String { &self.baseurl } /// Return the internal `reqwest::Client` used to make requests. pub fn client(&self) -> &reqwest::Client { &self.client } } impl Client { ///Sends a `GET` request to `/instance` /// ///```ignore /// let response = client.instance_get() /// .send() /// .await; /// ``` pub fn instance_get(&self) -> builder::InstanceGet { builder::InstanceGet::new(self) } ///Sends a `PUT` request to `/instance` /// ///```ignore /// let response = client.instance_ensure() /// .body(body) /// .send() /// .await; /// ``` pub fn instance_ensure(&self) -> builder::InstanceEnsure { builder::InstanceEnsure::new(self) } ///Issue a snapshot request to a crucible backend /// ///Sends a `POST` request to `/instance/disk/{id}/snapshot/{snapshot_id}` /// ///```ignore /// let response = client.instance_issue_crucible_snapshot_request() /// .id(id) /// .snapshot_id(snapshot_id) /// .send() /// .await; /// ``` pub fn instance_issue_crucible_snapshot_request( &self, ) -> builder::InstanceIssueCrucibleSnapshotRequest { builder::InstanceIssueCrucibleSnapshotRequest::new(self) } ///Sends a `GET` request to `/instance/migrate/status` /// ///```ignore /// let response = client.instance_migrate_status() /// .body(body) /// .send() /// .await; /// ``` pub fn instance_migrate_status(&self) -> builder::InstanceMigrateStatus { builder::InstanceMigrateStatus::new(self) } ///Sends a `GET` request to `/instance/serial` /// ///```ignore /// let response = client.instance_serial() /// .send() /// .await; /// ``` pub fn instance_serial(&self) -> builder::InstanceSerial { builder::InstanceSerial::new(self) } ///Sends a `PUT` request to `/instance/state` /// ///```ignore /// let response = client.instance_state_put() /// .body(body) /// .send() /// .await; /// ``` pub fn instance_state_put(&self) -> builder::InstanceStatePut { builder::InstanceStatePut::new(self) } ///Sends a `GET` request to `/instance/state-monitor` /// ///```ignore /// let response = client.instance_state_monitor() /// .body(body) /// .send() /// .await; /// ``` pub fn instance_state_monitor(&self) -> builder::InstanceStateMonitor { builder::InstanceStateMonitor::new(self) } } pub mod builder { use super::types; #[allow(unused_imports)] use super::{ encode_path, ByteStream, Error, HeaderMap, HeaderValue, RequestBuilderExt, ResponseValue, }; ///Builder for [`Client::instance_get`] /// ///[`Client::instance_get`]: super::Client::instance_get #[derive(Debug, Clone)] pub struct InstanceGet<'a> { client: &'a super::Client, } impl<'a> InstanceGet<'a> { pub fn new(client: &'a super::Client) -> Self { Self { client } } ///Sends a `GET` request to `/instance` pub async fn send( self, ) -> Result, Error> { let Self { client } = self; let url = format!("{}/instance", client.baseurl,); let request = client.client.get(url).build()?; let result = client.client.execute(request).await; let response = result?; match response.status().as_u16() { 200u16 => ResponseValue::from_response(response).await, 400u16..=499u16 => Err(Error::ErrorResponse( ResponseValue::from_response(response).await?, )), 500u16..=599u16 => Err(Error::ErrorResponse( ResponseValue::from_response(response).await?, )), _ => Err(Error::UnexpectedResponse(response)), } } } ///Builder for [`Client::instance_ensure`] /// ///[`Client::instance_ensure`]: super::Client::instance_ensure #[derive(Debug, Clone)] pub struct InstanceEnsure<'a> { client: &'a super::Client, body: Result, } impl<'a> InstanceEnsure<'a> { pub fn new(client: &'a super::Client) -> Self { Self { client, body: Err("body was not initialized".to_string()), } } pub fn body(mut self, value: V) -> Self where V: std::convert::TryInto, { self.body = value .try_into() .map_err(|_| "conversion to `InstanceEnsureRequest` for body failed".to_string()); self } ///Sends a `PUT` request to `/instance` pub async fn send( self, ) -> Result, Error> { let Self { client, body } = self; let body = body.map_err(Error::InvalidRequest)?; let url = format!("{}/instance", client.baseurl,); let request = client.client.put(url).json(&body).build()?; let result = client.client.execute(request).await; let response = result?; match response.status().as_u16() { 201u16 => ResponseValue::from_response(response).await, 400u16..=499u16 => Err(Error::ErrorResponse( ResponseValue::from_response(response).await?, )), 500u16..=599u16 => Err(Error::ErrorResponse( ResponseValue::from_response(response).await?, )), _ => Err(Error::UnexpectedResponse(response)), } } } ///Builder for [`Client::instance_issue_crucible_snapshot_request`] /// ///[`Client::instance_issue_crucible_snapshot_request`]: super::Client::instance_issue_crucible_snapshot_request #[derive(Debug, Clone)] pub struct InstanceIssueCrucibleSnapshotRequest<'a> { client: &'a super::Client, id: Result, snapshot_id: Result, } impl<'a> InstanceIssueCrucibleSnapshotRequest<'a> { pub fn new(client: &'a super::Client) -> Self { Self { client, id: Err("id was not initialized".to_string()), snapshot_id: Err("snapshot_id was not initialized".to_string()), } } pub fn id(mut self, value: V) -> Self where V: std::convert::TryInto, { self.id = value .try_into() .map_err(|_| "conversion to `uuid :: Uuid` for id failed".to_string()); self } pub fn snapshot_id(mut self, value: V) -> Self where V: std::convert::TryInto, { self.snapshot_id = value .try_into() .map_err(|_| "conversion to `uuid :: Uuid` for snapshot_id failed".to_string()); self } ///Sends a `POST` request to /// `/instance/disk/{id}/snapshot/{snapshot_id}` pub async fn send(self) -> Result, Error> { let Self { client, id, snapshot_id, } = self; let id = id.map_err(Error::InvalidRequest)?; let snapshot_id = snapshot_id.map_err(Error::InvalidRequest)?; let url = format!( "{}/instance/disk/{}/snapshot/{}", client.baseurl, encode_path(&id.to_string()), encode_path(&snapshot_id.to_string()), ); let request = client.client.post(url).build()?; let result = client.client.execute(request).await; let response = result?; match response.status().as_u16() { 200u16 => ResponseValue::from_response(response).await, 400u16..=499u16 => Err(Error::ErrorResponse( ResponseValue::from_response(response).await?, )), 500u16..=599u16 => Err(Error::ErrorResponse( ResponseValue::from_response(response).await?, )), _ => Err(Error::UnexpectedResponse(response)), } } } ///Builder for [`Client::instance_migrate_status`] /// ///[`Client::instance_migrate_status`]: super::Client::instance_migrate_status #[derive(Debug, Clone)] pub struct InstanceMigrateStatus<'a> { client: &'a super::Client, body: Result, } impl<'a> InstanceMigrateStatus<'a> { pub fn new(client: &'a super::Client) -> Self { Self { client, body: Err("body was not initialized".to_string()), } } pub fn body(mut self, value: V) -> Self where V: std::convert::TryInto, { self.body = value.try_into().map_err(|_| { "conversion to `InstanceMigrateStatusRequest` for body failed".to_string() }); self } ///Sends a `GET` request to `/instance/migrate/status` pub async fn send( self, ) -> Result, Error> { let Self { client, body } = self; let body = body.map_err(Error::InvalidRequest)?; let url = format!("{}/instance/migrate/status", client.baseurl,); let request = client.client.get(url).json(&body).build()?; let result = client.client.execute(request).await; let response = result?; match response.status().as_u16() { 200u16 => ResponseValue::from_response(response).await, 400u16..=499u16 => Err(Error::ErrorResponse( ResponseValue::from_response(response).await?, )), 500u16..=599u16 => Err(Error::ErrorResponse( ResponseValue::from_response(response).await?, )), _ => Err(Error::UnexpectedResponse(response)), } } } ///Builder for [`Client::instance_serial`] /// ///[`Client::instance_serial`]: super::Client::instance_serial #[derive(Debug, Clone)] pub struct InstanceSerial<'a> { client: &'a super::Client, } impl<'a> InstanceSerial<'a> { pub fn new(client: &'a super::Client) -> Self { Self { client } } ///Sends a `GET` request to `/instance/serial` pub async fn send( self, ) -> Result, Error> { let Self { client } = self; let url = format!("{}/instance/serial", client.baseurl,); let request = client .client .get(url) .header(reqwest::header::CONNECTION, "Upgrade") .header(reqwest::header::UPGRADE, "websocket") .header(reqwest::header::SEC_WEBSOCKET_VERSION, "13") .header( reqwest::header::SEC_WEBSOCKET_KEY, base64::Engine::encode( &base64::engine::general_purpose::STANDARD, rand::random::<[u8; 16]>(), ), ) .build()?; let result = client.client.execute(request).await; let response = result?; match response.status().as_u16() { 101u16 => ResponseValue::upgrade(response).await, 200..=299 => ResponseValue::upgrade(response).await, _ => Err(Error::UnexpectedResponse(response)), } } } ///Builder for [`Client::instance_state_put`] /// ///[`Client::instance_state_put`]: super::Client::instance_state_put #[derive(Debug, Clone)] pub struct InstanceStatePut<'a> { client: &'a super::Client, body: Result, } impl<'a> InstanceStatePut<'a> { pub fn new(client: &'a super::Client) -> Self { Self { client, body: Err("body was not initialized".to_string()), } } pub fn body(mut self, value: V) -> Self where V: std::convert::TryInto, { self.body = value .try_into() .map_err(|_| "conversion to `InstanceStateRequested` for body failed".to_string()); self } ///Sends a `PUT` request to `/instance/state` pub async fn send(self) -> Result, Error> { let Self { client, body } = self; let body = body.map_err(Error::InvalidRequest)?; let url = format!("{}/instance/state", client.baseurl,); let request = client.client.put(url).json(&body).build()?; let result = client.client.execute(request).await; let response = result?; match response.status().as_u16() { 204u16 => Ok(ResponseValue::empty(response)), 400u16..=499u16 => Err(Error::ErrorResponse( ResponseValue::from_response(response).await?, )), 500u16..=599u16 => Err(Error::ErrorResponse( ResponseValue::from_response(response).await?, )), _ => Err(Error::UnexpectedResponse(response)), } } } ///Builder for [`Client::instance_state_monitor`] /// ///[`Client::instance_state_monitor`]: super::Client::instance_state_monitor #[derive(Debug, Clone)] pub struct InstanceStateMonitor<'a> { client: &'a super::Client, body: Result, } impl<'a> InstanceStateMonitor<'a> { pub fn new(client: &'a super::Client) -> Self { Self { client, body: Err("body was not initialized".to_string()), } } pub fn body(mut self, value: V) -> Self where V: std::convert::TryInto, { self.body = value.try_into().map_err(|_| { "conversion to `InstanceStateMonitorRequest` for body failed".to_string() }); self } ///Sends a `GET` request to `/instance/state-monitor` pub async fn send( self, ) -> Result, Error> { let Self { client, body } = self; let body = body.map_err(Error::InvalidRequest)?; let url = format!("{}/instance/state-monitor", client.baseurl,); let request = client.client.get(url).json(&body).build()?; let result = client.client.execute(request).await; let response = result?; match response.status().as_u16() { 200u16 => ResponseValue::from_response(response).await, 400u16..=499u16 => Err(Error::ErrorResponse( ResponseValue::from_response(response).await?, )), 500u16..=599u16 => Err(Error::ErrorResponse( ResponseValue::from_response(response).await?, )), _ => Err(Error::UnexpectedResponse(response)), } } } } pub mod prelude { pub use self::super::Client; }