diff --git a/omicron-bootstrap-agent/src/bin/bootstrap-agent.rs b/omicron-bootstrap-agent/src/bin/bootstrap-agent.rs index 506a67efa3d..19ab27e26ee 100644 --- a/omicron-bootstrap-agent/src/bin/bootstrap-agent.rs +++ b/omicron-bootstrap-agent/src/bin/bootstrap-agent.rs @@ -15,7 +15,7 @@ use uuid::Uuid; #[derive(Debug, StructOpt)] #[structopt( - name = "boostrap_agent", + name = "bootstrap_agent", about = "See README.adoc for more information" )] enum Args { diff --git a/omicron-bootstrap-agent/src/bootstrap_agent.rs b/omicron-bootstrap-agent/src/bootstrap_agent.rs index bf75de509ce..3e0b1b2cecf 100644 --- a/omicron-bootstrap-agent/src/bootstrap_agent.rs +++ b/omicron-bootstrap-agent/src/bootstrap_agent.rs @@ -1,6 +1,6 @@ use crate::bootstrap_agent_client::Client as BootstrapClient; -use omicron_common::api::BootstrapAgentShareResponse; -use omicron_common::api::Error; +use omicron_common::api::external::Error; +use omicron_common::api::internal::bootstrap_agent::ShareResponse; use omicron_common::packaging::sha256_digest; use slog::Logger; @@ -49,14 +49,14 @@ impl BootstrapAgent { pub async fn request_share( &self, identity: Vec, - ) -> Result { + ) -> Result { // TODO-correctness: Validate identity, return whatever // information is necessary to establish trust quorum. // // This current implementation is a placeholder. info!(&self.log, "request_share, received identity: {:x?}", identity); - Ok(BootstrapAgentShareResponse { shared_secret: vec![] }) + Ok(ShareResponse { shared_secret: vec![] }) } /// Performs device initialization: diff --git a/omicron-bootstrap-agent/src/bootstrap_agent_client.rs b/omicron-bootstrap-agent/src/bootstrap_agent_client.rs index 28ebafae77a..10d58889a3a 100644 --- a/omicron-bootstrap-agent/src/bootstrap_agent_client.rs +++ b/omicron-bootstrap-agent/src/bootstrap_agent_client.rs @@ -5,9 +5,9 @@ * generated by the server. */ -use omicron_common::api::BootstrapAgentShareRequest; -use omicron_common::api::BootstrapAgentShareResponse; -use omicron_common::api::Error; +use omicron_common::api::external::Error; +use omicron_common::api::internal::bootstrap_agent::ShareRequest; +use omicron_common::api::internal::bootstrap_agent::ShareResponse; use omicron_common::http_client::HttpClient; use http::Method; @@ -38,18 +38,17 @@ impl Client { pub async fn request_share( &self, identity: Vec, - ) -> Result { + ) -> Result { let path = "/request_share"; let body = Body::from( - serde_json::to_string(&BootstrapAgentShareRequest { identity }) - .unwrap(), + serde_json::to_string(&ShareRequest { identity }).unwrap(), ); let mut response = self.client.request(Method::GET, path, body).await?; /* TODO-robustness handle 300-level? */ assert!(response.status().is_success()); let value = self .client - .read_json::( + .read_json::( &self.client.error_message_base(&Method::GET, path), &mut response, ) diff --git a/omicron-bootstrap-agent/src/http_entrypoints.rs b/omicron-bootstrap-agent/src/http_entrypoints.rs index 2c2cfe638d2..c157e3bf29c 100644 --- a/omicron-bootstrap-agent/src/http_entrypoints.rs +++ b/omicron-bootstrap-agent/src/http_entrypoints.rs @@ -8,8 +8,8 @@ use dropshot::HttpError; use dropshot::HttpResponseOk; use dropshot::RequestContext; use dropshot::TypedBody; -use omicron_common::api::{ - BootstrapAgentShareRequest, BootstrapAgentShareResponse, +use omicron_common::api::internal::bootstrap_agent::{ + ShareRequest, ShareResponse, }; use std::sync::Arc; @@ -39,8 +39,8 @@ pub fn ba_api() -> ApiDescription> { }] async fn api_request_share( rqctx: Arc>>, - request: TypedBody, -) -> Result, HttpError> { + request: TypedBody, +) -> Result, HttpError> { let bootstrap_agent = rqctx.context(); let request = request.into_inner(); diff --git a/omicron-common/src/api/error.rs b/omicron-common/src/api/external/error.rs similarity index 98% rename from omicron-common/src/api/error.rs rename to omicron-common/src/api/external/error.rs index 4344747e5b7..ae4e7b99b85 100644 --- a/omicron-common/src/api/error.rs +++ b/omicron-common/src/api/external/error.rs @@ -4,8 +4,8 @@ * For HTTP-level error handling, see Dropshot. */ -use crate::api::Name; -use crate::api::ResourceType; +use crate::api::external::Name; +use crate::api::external::ResourceType; use dropshot::HttpError; use dropshot::HttpErrorResponseBody; use serde::Deserialize; @@ -243,7 +243,7 @@ macro_rules! bail_unless { }; ($cond:expr, $($arg:tt)+) => { if !$cond { - return Err($crate::api::Error::internal_error(&format!( + return Err($crate::api::external::Error::internal_error(&format!( $($arg)*))) } }; diff --git a/omicron-common/src/api/http_pagination.rs b/omicron-common/src/api/external/http_pagination.rs similarity index 99% rename from omicron-common/src/api/http_pagination.rs rename to omicron-common/src/api/external/http_pagination.rs index 83d0d252690..d6d70d6f64f 100644 --- a/omicron-common/src/api/http_pagination.rs +++ b/omicron-common/src/api/external/http_pagination.rs @@ -38,10 +38,10 @@ * each resource paginated that way). Where possible, we should share code. */ -use crate::api::DataPageParams; -use crate::api::Name; -use crate::api::ObjectIdentity; -use crate::api::PaginationOrder; +use crate::api::external::DataPageParams; +use crate::api::external::Name; +use crate::api::external::ObjectIdentity; +use crate::api::external::PaginationOrder; use dropshot::HttpError; use dropshot::PaginationParams; use dropshot::RequestContext; @@ -505,9 +505,8 @@ mod test { use super::ScanByName; use super::ScanByNameOrId; use super::ScanParams; - use crate::api::IdentityMetadata; - use crate::api::ObjectIdentity; - use api_identity::ObjectIdentity; + use crate::api::external::IdentityMetadata; + use crate::api::external::ObjectIdentity; use chrono::Utc; use dropshot::PaginationOrder; use dropshot::PaginationParams; diff --git a/omicron-common/src/api/model.rs b/omicron-common/src/api/external/mod.rs similarity index 79% rename from omicron-common/src/api/model.rs rename to omicron-common/src/api/external/mod.rs index 874d6c692a2..56bbc6a373c 100644 --- a/omicron-common/src/api/model.rs +++ b/omicron-common/src/api/external/mod.rs @@ -5,7 +5,10 @@ * internal APIs. The contents here are all HTTP-agnostic. */ -use crate::api::Error; +mod error; +pub mod http_pagination; +pub use error::*; + use anyhow::anyhow; use anyhow::Context; use api_identity::ObjectIdentity; @@ -26,7 +29,6 @@ use std::fmt::Formatter; use std::fmt::Result as FormatResult; use std::net::{IpAddr, SocketAddr}; use std::num::NonZeroU32; -use std::time::Duration; use uuid::Uuid; /* @@ -453,56 +455,14 @@ impl Display for ResourceType { } } -/** - * Object represents a resource in the API and is implemented by concrete - * types representing specific API resources. - * - * Consider a Project, which is about as simple a resource as we have. The - * `Project` struct represents a project as understood by the API. It - * contains all the fields necessary to implement a Project. It has several - * related types: - * - * * `ProjectView` is what gets emitted by the API when a user asks for a - * Project - * * `ProjectCreateParams` is what must be provided to the API when a user - * wants to create a new project - * * `ProjectUpdateParams` is what must be provided to the API when a user - * wants to update a project. - * - * We also have Instances, Disks, Racks, Sleds, and many related types, and we - * expect to add many more types like images, networking abstractions, - * organizations, teams, users, system components, and the like. See RFD 4 for - * details. Some resources may not have analogs for all these types because - * they're immutable (e.g., the `Rack` resource doesn't define a - * "CreateParams" type). - * - * The only thing guaranteed by the `Object` trait is that the type can be - * converted to a View, which is something that can be serialized. - */ -/* - * TODO-coverage: each type could have unit tests for various invalid input - * types? - */ -pub trait Object { - type View: Serialize + Clone + Debug; - fn to_view(&self) -> Self::View; -} - -/** - * Given an `ObjectStream` (for some specific `Object` type), - * return a vector of the objects' views. Any failures are ignored. - */ -/* - * TODO-hardening: Consider how to better deal with these failures. We should - * probably at least log something. - */ -pub async fn to_view_list( - object_stream: ObjectStream, -) -> Vec { +pub async fn to_list(object_stream: ObjectStream) -> Vec +where + U: From, +{ object_stream .filter(|maybe_object| ready(maybe_object.is_ok())) - .map(|maybe_object| maybe_object.unwrap().to_view()) - .collect::>() + .map(|maybe_object| maybe_object.unwrap().into()) + .collect::>() .await } @@ -556,21 +516,6 @@ pub struct IdentityMetadataUpdateParams { * PROJECTS */ -/** - * A Project in the external API - */ -pub struct Project { - /** common identifying metadata */ - pub identity: IdentityMetadata, -} - -impl Object for Project { - type View = ProjectView; - fn to_view(&self) -> ProjectView { - ProjectView { identity: self.identity.clone() } - } -} - /** * Client view of an [`Project`] */ @@ -585,6 +530,12 @@ pub struct ProjectView { pub identity: IdentityMetadata, } +impl From for ProjectView { + fn from(project: crate::api::internal::nexus::Project) -> Self { + ProjectView { identity: project.identity } + } +} + /** * Create-time parameters for an [`Project`] */ @@ -712,62 +663,6 @@ impl InstanceState { } } -/** - * Requestable running state of an Instance. - * - * A subset of [`InstanceState`]. - */ -#[derive( - Copy, - Clone, - Debug, - Deserialize, - Eq, - Ord, - PartialEq, - PartialOrd, - Serialize, - JsonSchema, -)] -#[serde(rename_all = "lowercase")] -pub enum InstanceStateRequested { - Running, - Stopped, - // Issues a reset command to the instance, such that it should - // stop and then immediately become running. - Reboot, - Destroyed, -} - -impl Display for InstanceStateRequested { - fn fmt(&self, f: &mut Formatter) -> FormatResult { - write!(f, "{}", self.label()) - } -} - -impl InstanceStateRequested { - fn label(&self) -> &str { - match self { - InstanceStateRequested::Running => "running", - InstanceStateRequested::Stopped => "stopped", - InstanceStateRequested::Reboot => "reboot", - InstanceStateRequested::Destroyed => "destroyed", - } - } - - /** - * Returns true if the state represents a stopped Instance. - */ - pub fn is_stopped(&self) -> bool { - match self { - InstanceStateRequested::Running => false, - InstanceStateRequested::Stopped => true, - InstanceStateRequested::Reboot => false, - InstanceStateRequested::Destroyed => true, - } - } -} - /** The number of CPUs in an Instance */ #[derive(Copy, Clone, Debug, Deserialize, Serialize, JsonSchema)] pub struct InstanceCpuCount(pub u16); @@ -786,72 +681,6 @@ impl From<&InstanceCpuCount> for i64 { } } -/** - * An Instance (VM) in the external API - */ -#[derive(Clone, Debug)] -pub struct Instance { - /** common identifying metadata */ - pub identity: IdentityMetadata, - - /** id for the project containing this Instance */ - pub project_id: Uuid, - - /** number of CPUs allocated for this Instance */ - pub ncpus: InstanceCpuCount, - /** memory allocated for this Instance */ - pub memory: ByteCount, - /** RFC1035-compliant hostname for the Instance. */ - pub hostname: String, /* TODO-cleanup different type? */ - - /** state owned by the data plane */ - pub runtime: InstanceRuntimeState, - /* TODO-completeness: add disks, network, tags, metrics */ -} - -impl Object for Instance { - type View = InstanceView; - fn to_view(&self) -> InstanceView { - InstanceView { - identity: self.identity.clone(), - project_id: self.project_id, - ncpus: self.ncpus, - memory: self.memory, - hostname: self.hostname.clone(), - runtime: self.runtime.to_view(), - } - } -} - -/** - * Runtime state of the Instance, including the actual running state and minimal - * metadata - * - * This state is owned by the sled agent running that Instance. - */ -#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)] -pub struct InstanceRuntimeState { - /** runtime state of the Instance */ - pub run_state: InstanceState, - /** which sled is running this Instance */ - pub sled_uuid: Uuid, - /** generation number for this state */ - pub gen: Generation, - /** timestamp for this information */ - pub time_updated: DateTime, -} - -/** - * Used to request an Instance state change from a sled agent - * - * Right now, it's only the run state that can be changed, though we might want - * to support changing properties like "ncpus" here. - */ -#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)] -pub struct InstanceRuntimeStateRequested { - pub run_state: InstanceStateRequested, -} - /** * Client view of an [`InstanceRuntimeState`] */ @@ -862,12 +691,13 @@ pub struct InstanceRuntimeStateView { pub time_run_state_updated: DateTime, } -impl Object for InstanceRuntimeState { - type View = InstanceRuntimeStateView; - fn to_view(&self) -> InstanceRuntimeStateView { +impl From + for InstanceRuntimeStateView +{ + fn from(state: crate::api::internal::nexus::InstanceRuntimeState) -> Self { InstanceRuntimeStateView { - run_state: self.run_state, - time_run_state_updated: self.time_updated, + run_state: state.run_state, + time_run_state_updated: state.time_updated, } } } @@ -896,6 +726,19 @@ pub struct InstanceView { pub runtime: InstanceRuntimeStateView, } +impl From for InstanceView { + fn from(instance: crate::api::internal::nexus::Instance) -> Self { + InstanceView { + identity: instance.identity.clone(), + project_id: instance.project_id, + ncpus: instance.ncpus, + memory: instance.memory, + hostname: instance.hostname.clone(), + runtime: instance.runtime.into(), + } + } +} + /** * Create-time parameters for an [`Instance`] */ @@ -928,26 +771,6 @@ pub struct InstanceUpdateParams { * DISKS */ -/** - * A Disk (network block device) in the external API - */ -#[derive(Clone, Debug)] -pub struct Disk { - /** common identifying metadata */ - pub identity: IdentityMetadata, - /** id for the project containing this Disk */ - pub project_id: Uuid, - /** - * id for the snapshot from which this Disk was created (None means a blank - * disk) - */ - pub create_snapshot_id: Option, - /** size of the Disk */ - pub size: ByteCount, - /** runtime state of the Disk */ - pub runtime: DiskRuntimeState, -} - /** * Client view of an [`Disk`] */ @@ -963,20 +786,19 @@ pub struct DiskView { pub device_path: String, } -impl Object for Disk { - type View = DiskView; - fn to_view(&self) -> DiskView { +impl From for DiskView { + fn from(disk: crate::api::internal::nexus::Disk) -> Self { /* * TODO-correctness: can the name always be used as a path like this * or might it need to be sanitized? */ - let device_path = format!("/mnt/{}", self.identity.name.as_str()); + let device_path = format!("/mnt/{}", disk.identity.name.as_str()); DiskView { - identity: self.identity.clone(), - project_id: self.project_id, - snapshot_id: self.create_snapshot_id, - size: self.size, - state: self.runtime.disk_state.clone(), + identity: disk.identity.clone(), + project_id: disk.project_id, + snapshot_id: disk.create_snapshot_id, + size: disk.size, + state: disk.runtime.disk_state, device_path, } } @@ -1084,20 +906,6 @@ impl DiskState { } } -/** - * Runtime state of the Disk, which includes its attach state and some minimal - * metadata - */ -#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)] -pub struct DiskRuntimeState { - /** runtime state of the Disk */ - pub disk_state: DiskState, - /** generation number for this state */ - pub gen: Generation, - /** timestamp for this information */ - pub time_updated: DateTime, -} - /** * Create-time parameters for an [`Disk`] */ @@ -1125,58 +933,10 @@ pub struct DiskAttachment { pub disk_state: DiskState, } -impl Object for DiskAttachment { - type View = Self; - fn to_view(&self) -> Self::View { - self.clone() - } -} - -/** - * Used to request a Disk state change - */ -#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize, JsonSchema)] -#[serde(rename_all = "lowercase")] -pub enum DiskStateRequested { - Detached, - Attached(Uuid), - Destroyed, - Faulted, -} - -impl DiskStateRequested { - /** - * Returns whether the requested state is attached to an Instance or not. - */ - pub fn is_attached(&self) -> bool { - match self { - DiskStateRequested::Detached => false, - DiskStateRequested::Destroyed => false, - DiskStateRequested::Faulted => false, - - DiskStateRequested::Attached(_) => true, - } - } -} - /* * RACKS */ -/** - * A Rack in the external API - */ -pub struct Rack { - pub identity: IdentityMetadata, -} - -impl Object for Rack { - type View = RackView; - fn to_view(&self) -> RackView { - RackView { identity: self.identity.clone() } - } -} - /** * Client view of an [`Rack`] */ @@ -1186,28 +946,16 @@ pub struct RackView { pub identity: IdentityMetadata, } +impl From for RackView { + fn from(rack: crate::api::internal::nexus::Rack) -> Self { + RackView { identity: rack.identity } + } +} + /* * SLEDS */ -/** - * A Sled in the external API - */ -pub struct Sled { - pub identity: IdentityMetadata, - pub service_address: SocketAddr, -} - -impl Object for Sled { - type View = SledView; - fn to_view(&self) -> SledView { - SledView { - identity: self.identity.clone(), - service_address: self.service_address, - } - } -} - /** * Client view of an [`Sled`] */ @@ -1219,6 +967,15 @@ pub struct SledView { pub service_address: SocketAddr, } +impl From for SledView { + fn from(sled: crate::api::internal::nexus::Sled) -> Self { + SledView { + identity: sled.identity.clone(), + service_address: sled.service_address, + } + } +} + /* * Sagas * @@ -1252,13 +1009,6 @@ pub struct SagaView { pub identity: IdentityMetadata, } -impl Object for SagaView { - type View = Self; - fn to_view(&self) -> Self::View { - self.clone() - } -} - impl From for SagaView { fn from(s: steno::SagaView) -> Self { SagaView { @@ -1527,116 +1277,11 @@ pub struct NetworkInterface { pub ip: IpAddr, } -/* - * Internal Control Plane API objects - */ - -/** - * Sent by a sled agent on startup to Nexus to request further instruction - */ -#[derive(Serialize, Deserialize, JsonSchema)] -pub struct SledAgentStartupInfo { - /** the address of the sled agent's API endpoint */ - pub sa_address: SocketAddr, -} - -/** - * Sent from Nexus to a sled agent to establish the runtime state of an Instance - */ -#[derive(Serialize, Deserialize, JsonSchema)] -pub struct InstanceEnsureBody { - /** - * Last runtime state of the Instance known to Nexus (used if the agent - * has never seen this Instance before). - */ - pub initial_runtime: InstanceRuntimeState, - /** requested runtime state of the Instance */ - pub target: InstanceRuntimeStateRequested, -} - -/** - * Sent from Nexus to a sled agent to establish the runtime state of a Disk - */ -#[derive(Serialize, Deserialize, JsonSchema)] -pub struct DiskEnsureBody { - /** - * Last runtime state of the Disk known to Nexus (used if the agent has - * never seen this Disk before). - */ - pub initial_runtime: DiskRuntimeState, - /** requested runtime state of the Disk */ - pub target: DiskStateRequested, -} - -/* - * Bootstrap Agent objects - */ - -/** - * Identity signed by local RoT and Oxide certificate chain. - */ -#[derive(Serialize, Deserialize, JsonSchema)] -pub struct BootstrapAgentShareRequest { - // TODO-completeness: format TBD; currently opaque. - pub identity: Vec, -} - -/** - * Sent between bootstrap agents to establish trust quorum. - */ -#[derive(Serialize, Deserialize, JsonSchema)] -pub struct BootstrapAgentShareResponse { - // TODO-completeness: format TBD; currently opaque. - pub shared_secret: Vec, -} - -/* - * Oximeter producer/collector objects. - */ - -/** - * Information announced by a metric server, used so that clients can contact it and collect - * available metric data from it. - */ -#[derive(Debug, Clone, JsonSchema, Serialize, Deserialize)] -pub struct ProducerEndpoint { - pub id: Uuid, - pub address: SocketAddr, - pub base_route: String, - pub interval: Duration, -} - -impl ProducerEndpoint { - /** - * Return the route that can be used to request metric data. - */ - pub fn collection_route(&self) -> String { - format!("{}/{}", &self.base_route, &self.id) - } -} - -/// Message used to notify Nexus that this oximeter instance is up and running. -#[derive(Debug, Clone, Copy, JsonSchema, Serialize, Deserialize)] -pub struct OximeterInfo { - /// The ID for this oximeter instance. - pub collector_id: Uuid, - - /// The address on which this oximeter instance listens for requests - pub address: SocketAddr, -} - -/// An assignment of an Oximeter instance to a metric producer for collection. -#[derive(Debug, Clone, Copy, JsonSchema, Serialize, Deserialize)] -pub struct OximeterAssignment { - pub oximeter_id: Uuid, - pub producer_id: Uuid, -} - #[cfg(test)] mod test { use super::ByteCount; use super::Name; - use crate::api::Error; + use crate::api::external::Error; use std::convert::TryFrom; #[test] diff --git a/omicron-common/src/api/internal/bootstrap_agent.rs b/omicron-common/src/api/internal/bootstrap_agent.rs new file mode 100644 index 00000000000..dbf9c2af7a5 --- /dev/null +++ b/omicron-common/src/api/internal/bootstrap_agent.rs @@ -0,0 +1,18 @@ +//! APIs exposed by the bootstrap agent + +use schemars::JsonSchema; +use serde::{Deserialize, Serialize}; + +/// Identity signed by local RoT and Oxide certificate chain. +#[derive(Serialize, Deserialize, JsonSchema)] +pub struct ShareRequest { + // TODO-completeness: format TBD; currently opaque. + pub identity: Vec, +} + +/// Sent between bootstrap agents to establish trust quorum. +#[derive(Serialize, Deserialize, JsonSchema)] +pub struct ShareResponse { + // TODO-completeness: format TBD; currently opaque. + pub shared_secret: Vec, +} diff --git a/omicron-common/src/api/internal/mod.rs b/omicron-common/src/api/internal/mod.rs new file mode 100644 index 00000000000..72d0ede9af4 --- /dev/null +++ b/omicron-common/src/api/internal/mod.rs @@ -0,0 +1,5 @@ +//! Internally facing APIs. + +pub mod bootstrap_agent; +pub mod nexus; +pub mod sled_agent; diff --git a/omicron-common/src/api/internal/nexus.rs b/omicron-common/src/api/internal/nexus.rs new file mode 100644 index 00000000000..5da89257985 --- /dev/null +++ b/omicron-common/src/api/internal/nexus.rs @@ -0,0 +1,139 @@ +//! APIs exposed by Nexus. + +use crate::api::external::{ + ByteCount, DiskState, Generation, IdentityMetadata, InstanceCpuCount, + InstanceState, +}; +use chrono::{DateTime, Utc}; +use schemars::JsonSchema; +use serde::{Deserialize, Serialize}; +use std::net::SocketAddr; +use std::time::Duration; +use uuid::Uuid; + +pub struct Rack { + pub identity: IdentityMetadata, +} + +pub struct Sled { + pub identity: IdentityMetadata, + pub service_address: SocketAddr, +} + +/// A collection of associated resources. +pub struct Project { + /// common identifying metadata. + pub identity: IdentityMetadata, +} + +/// A Disk (network block device). +#[derive(Clone, Debug)] +pub struct Disk { + /// common identifying metadata. + pub identity: IdentityMetadata, + /// id for the project containing this Disk + pub project_id: Uuid, + /// id for the snapshot from which this Disk was created (None means a blank + /// disk) + pub create_snapshot_id: Option, + /// size of the Disk + pub size: ByteCount, + /// runtime state of the Disk + pub runtime: DiskRuntimeState, +} + +/// Runtime state of the Disk, which includes its attach state and some minimal +/// metadata +#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)] +pub struct DiskRuntimeState { + /// runtime state of the Disk + pub disk_state: DiskState, + /// generation number for this state + pub gen: Generation, + /// timestamp for this information + pub time_updated: DateTime, +} + +/// An Instance (VM). +#[derive(Clone, Debug)] +pub struct Instance { + /// common identifying metadata + pub identity: IdentityMetadata, + + /// id for the project containing this Instance + pub project_id: Uuid, + + /// number of CPUs allocated for this Instance + pub ncpus: InstanceCpuCount, + /// memory allocated for this Instance + pub memory: ByteCount, + /// RFC1035-compliant hostname for the Instance. + // TODO-cleanup different type? + pub hostname: String, + + /// state owned by the data plane + pub runtime: InstanceRuntimeState, + // TODO-completeness: add disks, network, tags, metrics +} + +/// Runtime state of the Instance, including the actual running state and minimal +/// metadata +/// +/// This state is owned by the sled agent running that Instance. +#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)] +pub struct InstanceRuntimeState { + /// runtime state of the Instance + pub run_state: InstanceState, + /// which sled is running this Instance + pub sled_uuid: Uuid, + /// generation number for this state + pub gen: Generation, + /// timestamp for this information + pub time_updated: DateTime, +} + +/// Sent by a sled agent on startup to Nexus to request further instruction +#[derive(Serialize, Deserialize, JsonSchema)] +pub struct SledAgentStartupInfo { + /// the address of the sled agent's API endpoint + pub sa_address: SocketAddr, +} + +// Oximeter producer/collector objects. + +/// Information announced by a metric server, used so that clients can contact it and collect +/// available metric data from it. +#[derive(Debug, Clone, JsonSchema, Serialize, Deserialize)] +pub struct ProducerEndpoint { + pub id: Uuid, + pub address: SocketAddr, + pub base_route: String, + pub interval: Duration, +} + +impl ProducerEndpoint { + /** + * Return the route that can be used to request metric data. + */ + pub fn collection_route(&self) -> String { + format!("{}/{}", &self.base_route, &self.id) + } +} + +/// Message used to notify Nexus that this oximeter instance is up and running. +#[derive(Debug, Clone, Copy, JsonSchema, Serialize, Deserialize)] +pub struct OximeterInfo { + /// The ID for this oximeter instance. + pub collector_id: Uuid, + + /// The address on which this oximeter instance listens for requests + pub address: SocketAddr, +} + +/// An assignment of an Oximeter instance to a metric producer for collection. +// TODO: Goes to storage +#[derive(Debug, Clone, Copy, JsonSchema, Serialize, Deserialize)] +pub struct OximeterAssignment { + pub oximeter_id: Uuid, + pub producer_id: Uuid, +} diff --git a/omicron-common/src/api/internal/sled_agent.rs b/omicron-common/src/api/internal/sled_agent.rs new file mode 100644 index 00000000000..69fd9f6bc97 --- /dev/null +++ b/omicron-common/src/api/internal/sled_agent.rs @@ -0,0 +1,111 @@ +//! APIs exposed by Sled Agent. + +use crate::api::internal; +use schemars::JsonSchema; +use serde::{Deserialize, Serialize}; +use std::fmt::{Debug, Display, Formatter, Result as FormatResult}; +use uuid::Uuid; + +/// Sent from to a sled agent to establish the runtime state of a Disk +#[derive(Serialize, Deserialize, JsonSchema)] +pub struct DiskEnsureBody { + /// Last runtime state of the Disk known to Nexus (used if the agent has + /// never seen this Disk before). + pub initial_runtime: internal::nexus::DiskRuntimeState, + /// requested runtime state of the Disk + pub target: DiskStateRequested, +} + +///Used to request a Disk state change +#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize, JsonSchema)] +#[serde(rename_all = "lowercase")] +pub enum DiskStateRequested { + Detached, + Attached(Uuid), + Destroyed, + Faulted, +} + +impl DiskStateRequested { + /// Returns whether the requested state is attached to an Instance or not. + pub fn is_attached(&self) -> bool { + match self { + DiskStateRequested::Detached => false, + DiskStateRequested::Destroyed => false, + DiskStateRequested::Faulted => false, + + DiskStateRequested::Attached(_) => true, + } + } +} + +/// Sent to a sled agent to establish the runtime state of an Instance +#[derive(Serialize, Deserialize, JsonSchema)] +pub struct InstanceEnsureBody { + /// Last runtime state of the Instance known to Nexus (used if the agent + /// has never seen this Instance before). + pub initial_runtime: internal::nexus::InstanceRuntimeState, + /// requested runtime state of the Instance + pub target: InstanceRuntimeStateRequested, +} + +/// Requestable running state of an Instance. +/// +/// A subset of [`InstanceState`]. +#[derive( + Copy, + Clone, + Debug, + Deserialize, + Eq, + Ord, + PartialEq, + PartialOrd, + Serialize, + JsonSchema, +)] +#[serde(rename_all = "lowercase")] +pub enum InstanceStateRequested { + Running, + Stopped, + // Issues a reset command to the instance, such that it should + // stop and then immediately become running. + Reboot, + Destroyed, +} + +impl Display for InstanceStateRequested { + fn fmt(&self, f: &mut Formatter) -> FormatResult { + write!(f, "{}", self.label()) + } +} + +impl InstanceStateRequested { + fn label(&self) -> &str { + match self { + InstanceStateRequested::Running => "running", + InstanceStateRequested::Stopped => "stopped", + InstanceStateRequested::Reboot => "reboot", + InstanceStateRequested::Destroyed => "destroyed", + } + } + + /// Returns true if the state represents a stopped Instance. + pub fn is_stopped(&self) -> bool { + match self { + InstanceStateRequested::Running => false, + InstanceStateRequested::Stopped => true, + InstanceStateRequested::Reboot => false, + InstanceStateRequested::Destroyed => true, + } + } +} + +/// Used to request an Instance state change from a sled agent +/// +/// Right now, it's only the run state that can be changed, though we might want +/// to support changing properties like "ncpus" here. +#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)] +pub struct InstanceRuntimeStateRequested { + pub run_state: InstanceStateRequested, +} diff --git a/omicron-common/src/api/mod.rs b/omicron-common/src/api/mod.rs index 1ce9cf3feac..6eea86d6df9 100644 --- a/omicron-common/src/api/mod.rs +++ b/omicron-common/src/api/mod.rs @@ -1,8 +1,4 @@ -//! Externally facing API +//! APIs, both internal and external. -mod error; -pub mod http_pagination; -mod model; - -pub use error::*; -pub use model::*; +pub mod external; +pub mod internal; diff --git a/omicron-common/src/collection.rs b/omicron-common/src/collection.rs index bdb35619f06..9a46f57456f 100644 --- a/omicron-common/src/collection.rs +++ b/omicron-common/src/collection.rs @@ -2,11 +2,11 @@ * Functions for iterating pages from a collection */ -use crate::api::DataPageParams; -use crate::api::Error; -use crate::api::ListResult; -use crate::api::PaginationOrder::Ascending; -use crate::api::PaginationOrder::Descending; +use crate::api::external::DataPageParams; +use crate::api::external::Error; +use crate::api::external::ListResult; +use crate::api::external::PaginationOrder::Ascending; +use crate::api::external::PaginationOrder::Descending; use futures::StreamExt; use std::collections::BTreeMap; use std::convert::TryFrom; diff --git a/omicron-common/src/db.rs b/omicron-common/src/db.rs index 5b4e8d8c682..c5ddc13946c 100644 --- a/omicron-common/src/db.rs +++ b/omicron-common/src/db.rs @@ -5,7 +5,7 @@ * here is used by the model conversions, which have to live in this crate. */ -use crate::api::Error; +use crate::api::external::Error; use std::fmt; use thiserror::Error; use tokio_postgres::types::FromSql; diff --git a/omicron-common/src/http_client.rs b/omicron-common/src/http_client.rs index 07ef5f572ef..e30d4e35b02 100644 --- a/omicron-common/src/http_client.rs +++ b/omicron-common/src/http_client.rs @@ -2,7 +2,7 @@ * HTTP client used for internal control plane interfaces */ -use crate::api::Error; +use crate::api::external::Error; use dropshot::HttpErrorResponseBody; use http::Method; use hyper::client::HttpConnector; diff --git a/omicron-common/src/model_db.rs b/omicron-common/src/model_db.rs index 638630a2f75..398f63b317f 100644 --- a/omicron-common/src/model_db.rs +++ b/omicron-common/src/model_db.rs @@ -53,28 +53,28 @@ use std::net::{IpAddr, SocketAddr}; use std::time::Duration; use super::db::sql_row_value; -use crate::api::ByteCount; -use crate::api::Disk; -use crate::api::DiskAttachment; -use crate::api::DiskRuntimeState; -use crate::api::DiskState; -use crate::api::Error; -use crate::api::Generation; -use crate::api::IdentityMetadata; -use crate::api::Instance; -use crate::api::InstanceCpuCount; -use crate::api::InstanceRuntimeState; -use crate::api::InstanceState; -use crate::api::MacAddr; -use crate::api::Name; -use crate::api::NetworkInterface; -use crate::api::OximeterAssignment; -use crate::api::OximeterInfo; -use crate::api::ProducerEndpoint; -use crate::api::Project; -use crate::api::VPCSubnet; -use crate::api::VPC; -use crate::api::{Ipv4Net, Ipv6Net}; +use crate::api::external::ByteCount; +use crate::api::external::DiskAttachment; +use crate::api::external::DiskState; +use crate::api::external::Error; +use crate::api::external::Generation; +use crate::api::external::IdentityMetadata; +use crate::api::external::InstanceCpuCount; +use crate::api::external::InstanceState; +use crate::api::external::MacAddr; +use crate::api::external::Name; +use crate::api::external::NetworkInterface; +use crate::api::external::VPCSubnet; +use crate::api::external::VPC; +use crate::api::external::{Ipv4Net, Ipv6Net}; +use crate::api::internal::nexus::Disk; +use crate::api::internal::nexus::DiskRuntimeState; +use crate::api::internal::nexus::Instance; +use crate::api::internal::nexus::InstanceRuntimeState; +use crate::api::internal::nexus::OximeterAssignment; +use crate::api::internal::nexus::OximeterInfo; +use crate::api::internal::nexus::ProducerEndpoint; +use crate::api::internal::nexus::Project; use crate::bail_unless; use chrono::DateTime; use chrono::Utc; diff --git a/omicron-common/src/nexus_client.rs b/omicron-common/src/nexus_client.rs index 31b3d657209..1ca7327c71c 100644 --- a/omicron-common/src/nexus_client.rs +++ b/omicron-common/src/nexus_client.rs @@ -6,10 +6,10 @@ * generated by the server. */ -use crate::api::DiskRuntimeState; -use crate::api::Error; -use crate::api::InstanceRuntimeState; -use crate::api::SledAgentStartupInfo; +use crate::api::external::Error; +use crate::api::internal::nexus::DiskRuntimeState; +use crate::api::internal::nexus::InstanceRuntimeState; +use crate::api::internal::nexus::SledAgentStartupInfo; use crate::http_client::HttpClient; use http::Method; use hyper::Body; diff --git a/omicron-common/src/oximeter_client.rs b/omicron-common/src/oximeter_client.rs index f2ee254f5f4..befa53afe0d 100644 --- a/omicron-common/src/oximeter_client.rs +++ b/omicron-common/src/oximeter_client.rs @@ -8,8 +8,8 @@ use hyper::Body; use slog::Logger; use uuid::Uuid; -use crate::api::Error; -use crate::api::ProducerEndpoint; +use crate::api::external::Error; +use crate::api::internal::nexus::ProducerEndpoint; use crate::http_client::HttpClient; /// Client of an oximeter server diff --git a/omicron-common/src/sled_agent_client.rs b/omicron-common/src/sled_agent_client.rs index f262f9c6d3d..d2a7cb1a2e0 100644 --- a/omicron-common/src/sled_agent_client.rs +++ b/omicron-common/src/sled_agent_client.rs @@ -5,13 +5,13 @@ * generated by the server. */ -use crate::api::DiskEnsureBody; -use crate::api::DiskRuntimeState; -use crate::api::DiskStateRequested; -use crate::api::Error; -use crate::api::InstanceEnsureBody; -use crate::api::InstanceRuntimeState; -use crate::api::InstanceRuntimeStateRequested; +use crate::api::external::Error; +use crate::api::internal::nexus::DiskRuntimeState; +use crate::api::internal::nexus::InstanceRuntimeState; +use crate::api::internal::sled_agent::DiskEnsureBody; +use crate::api::internal::sled_agent::DiskStateRequested; +use crate::api::internal::sled_agent::InstanceEnsureBody; +use crate::api::internal::sled_agent::InstanceRuntimeStateRequested; use crate::http_client::HttpClient; use async_trait::async_trait; use http::Method; diff --git a/omicron-nexus/src/db/conversions.rs b/omicron-nexus/src/db/conversions.rs index 4f1759df478..b49bca1c40a 100644 --- a/omicron-nexus/src/db/conversions.rs +++ b/omicron-nexus/src/db/conversions.rs @@ -6,17 +6,17 @@ use chrono::DateTime; use chrono::Utc; -use omicron_common::api::DiskCreateParams; -use omicron_common::api::DiskRuntimeState; -use omicron_common::api::DiskState; -use omicron_common::api::IdentityMetadataCreateParams; -use omicron_common::api::InstanceCreateParams; -use omicron_common::api::InstanceRuntimeState; -use omicron_common::api::InstanceState; -use omicron_common::api::OximeterAssignment; -use omicron_common::api::OximeterInfo; -use omicron_common::api::ProducerEndpoint; -use omicron_common::api::ProjectCreateParams; +use omicron_common::api::external::DiskCreateParams; +use omicron_common::api::external::DiskState; +use omicron_common::api::external::IdentityMetadataCreateParams; +use omicron_common::api::external::InstanceCreateParams; +use omicron_common::api::external::InstanceState; +use omicron_common::api::external::ProjectCreateParams; +use omicron_common::api::internal::nexus::DiskRuntimeState; +use omicron_common::api::internal::nexus::InstanceRuntimeState; +use omicron_common::api::internal::nexus::OximeterAssignment; +use omicron_common::api::internal::nexus::OximeterInfo; +use omicron_common::api::internal::nexus::ProducerEndpoint; use super::sql::SqlSerialize; use super::sql::SqlValueSet; diff --git a/omicron-nexus/src/db/datastore.rs b/omicron-nexus/src/db/datastore.rs index df66f45cb4c..e57e5719f54 100644 --- a/omicron-nexus/src/db/datastore.rs +++ b/omicron-nexus/src/db/datastore.rs @@ -21,19 +21,19 @@ use super::Pool; use chrono::Utc; use omicron_common::api; -use omicron_common::api::CreateResult; -use omicron_common::api::DataPageParams; -use omicron_common::api::DeleteResult; -use omicron_common::api::Error; -use omicron_common::api::Generation; -use omicron_common::api::ListResult; -use omicron_common::api::LookupResult; -use omicron_common::api::Name; -use omicron_common::api::OximeterAssignment; -use omicron_common::api::OximeterInfo; -use omicron_common::api::ProducerEndpoint; -use omicron_common::api::ResourceType; -use omicron_common::api::UpdateResult; +use omicron_common::api::external::CreateResult; +use omicron_common::api::external::DataPageParams; +use omicron_common::api::external::DeleteResult; +use omicron_common::api::external::Error; +use omicron_common::api::external::Generation; +use omicron_common::api::external::ListResult; +use omicron_common::api::external::LookupResult; +use omicron_common::api::external::Name; +use omicron_common::api::external::ResourceType; +use omicron_common::api::external::UpdateResult; +use omicron_common::api::internal::nexus::OximeterAssignment; +use omicron_common::api::internal::nexus::OximeterInfo; +use omicron_common::api::internal::nexus::ProducerEndpoint; use omicron_common::bail_unless; use omicron_common::db::sql_row_value; use std::convert::TryFrom; @@ -78,8 +78,8 @@ impl DataStore { pub async fn project_create_with_id( &self, new_id: &Uuid, - new_project: &api::ProjectCreateParams, - ) -> CreateResult { + new_project: &api::external::ProjectCreateParams, + ) -> CreateResult { let client = self.pool.acquire().await?; let now = Utc::now(); let mut values = SqlValueSet::new(); @@ -99,7 +99,7 @@ impl DataStore { pub async fn project_fetch( &self, project_name: &Name, - ) -> LookupResult { + ) -> LookupResult { let client = self.pool.acquire().await?; sql_fetch_row_by::( &client, @@ -154,7 +154,7 @@ impl DataStore { pub async fn projects_list_by_id( &self, pagparams: &DataPageParams<'_, Uuid>, - ) -> ListResult { + ) -> ListResult { let client = self.pool.acquire().await?; sql_fetch_page_from_table::( &client, @@ -168,7 +168,7 @@ impl DataStore { pub async fn projects_list_by_name( &self, pagparams: &DataPageParams<'_, Name>, - ) -> ListResult { + ) -> ListResult { let client = self.pool.acquire().await?; sql_fetch_page_by::< LookupByUniqueName, @@ -182,8 +182,8 @@ impl DataStore { pub async fn project_update( &self, project_name: &Name, - update_params: &api::ProjectUpdateParams, - ) -> UpdateResult { + update_params: &api::external::ProjectUpdateParams, + ) -> UpdateResult { let client = self.pool.acquire().await?; let now = Utc::now(); @@ -212,7 +212,7 @@ impl DataStore { Error::not_found_by_name(ResourceType::Project, project_name) }) .await?; - Ok(api::Project::try_from(&row)?) + Ok(api::internal::nexus::Project::try_from(&row)?) } /* @@ -248,9 +248,9 @@ impl DataStore { &self, instance_id: &Uuid, project_id: &Uuid, - params: &api::InstanceCreateParams, - runtime_initial: &api::InstanceRuntimeState, - ) -> CreateResult { + params: &api::external::InstanceCreateParams, + runtime_initial: &api::internal::nexus::InstanceRuntimeState, + ) -> CreateResult { let client = self.pool.acquire().await?; let now = runtime_initial.time_updated; let mut values = SqlValueSet::new(); @@ -274,7 +274,8 @@ impl DataStore { .await?; bail_unless!( - instance.runtime.run_state == api::InstanceState::Creating, + instance.runtime.run_state + == api::external::InstanceState::Creating, "newly-created Instance has unexpected state: {:?}", instance.runtime.run_state ); @@ -290,7 +291,7 @@ impl DataStore { &self, project_id: &Uuid, pagparams: &DataPageParams<'_, Name>, - ) -> ListResult { + ) -> ListResult { let client = self.pool.acquire().await?; sql_fetch_page_by::< LookupByUniqueNameInProject, @@ -303,7 +304,7 @@ impl DataStore { pub async fn instance_fetch( &self, instance_id: &Uuid, - ) -> LookupResult { + ) -> LookupResult { let client = self.pool.acquire().await?; sql_fetch_row_by::(&client, (), instance_id) .await @@ -313,7 +314,7 @@ impl DataStore { &self, project_id: &Uuid, instance_name: &Name, - ) -> LookupResult { + ) -> LookupResult { let client = self.pool.acquire().await?; sql_fetch_row_by::( &client, @@ -335,7 +336,7 @@ impl DataStore { pub async fn instance_update_runtime( &self, instance_id: &Uuid, - new_runtime: &api::InstanceRuntimeState, + new_runtime: &api::internal::nexus::InstanceRuntimeState, ) -> Result { let client = self.pool.acquire().await?; @@ -378,14 +379,14 @@ impl DataStore { let now = Utc::now(); let mut values = SqlValueSet::new(); - api::InstanceState::Destroyed.sql_serialize(&mut values); + api::external::InstanceState::Destroyed.sql_serialize(&mut values); values.set("time_deleted", &now); let mut cond_sql = SqlString::new(); - let stopped = api::InstanceState::Stopped.to_string(); + let stopped = api::external::InstanceState::Stopped.to_string(); let p1 = cond_sql.next_param(&stopped); - let failed = api::InstanceState::Failed.to_string(); + let failed = api::external::InstanceState::Failed.to_string(); let p2 = cond_sql.next_param(&failed); cond_sql.push_str(&format!("instance_state in ({}, {})", p1, p2)); @@ -402,7 +403,7 @@ impl DataStore { let row = &update.found_state; let found_id: Uuid = sql_row_value(&row, "found_id")?; let variant: &str = sql_row_value(&row, "found_instance_state")?; - let instance_state = api::InstanceState::try_from(variant) + let instance_state = api::external::InstanceState::try_from(variant) .map_err(|e| Error::internal_error(&e))?; bail_unless!(found_id == *instance_id); @@ -429,9 +430,13 @@ impl DataStore { &self, instance_id: &Uuid, pagparams: &DataPageParams<'_, Name>, - ) -> ListResult { + ) -> ListResult { let client = self.pool.acquire().await?; - sql_fetch_page_by::( + sql_fetch_page_by::< + LookupByAttachedInstance, + Disk, + api::external::DiskAttachment, + >( &client, (instance_id,), pagparams, @@ -444,9 +449,9 @@ impl DataStore { &self, disk_id: &Uuid, project_id: &Uuid, - params: &api::DiskCreateParams, - runtime_initial: &api::DiskRuntimeState, - ) -> CreateResult { + params: &api::external::DiskCreateParams, + runtime_initial: &api::internal::nexus::DiskRuntimeState, + ) -> CreateResult { /* * See project_create_instance() for a discussion of how this function * works. The pattern here is nearly identical. @@ -461,7 +466,7 @@ impl DataStore { params.sql_serialize(&mut values); runtime_initial.sql_serialize(&mut values); - let disk = + let disk: api::internal::nexus::Disk = sql_insert_unique_idempotent_and_fetch::( &client, &mut values, @@ -473,7 +478,7 @@ impl DataStore { .await?; bail_unless!( - disk.runtime.disk_state == api::DiskState::Creating, + disk.runtime.disk_state == api::external::DiskState::Creating, "newly-created Disk has unexpected state: {:?}", disk.runtime.disk_state ); @@ -489,7 +494,7 @@ impl DataStore { &self, project_id: &Uuid, pagparams: &DataPageParams<'_, Name>, - ) -> ListResult { + ) -> ListResult { let client = self.pool.acquire().await?; sql_fetch_page_by::< LookupByUniqueNameInProject, @@ -502,7 +507,7 @@ impl DataStore { pub async fn disk_update_runtime( &self, disk_id: &Uuid, - new_runtime: &api::DiskRuntimeState, + new_runtime: &api::internal::nexus::DiskRuntimeState, ) -> Result { let client = self.pool.acquire().await?; @@ -528,7 +533,10 @@ impl DataStore { Ok(update.updated) } - pub async fn disk_fetch(&self, disk_id: &Uuid) -> LookupResult { + pub async fn disk_fetch( + &self, + disk_id: &Uuid, + ) -> LookupResult { let client = self.pool.acquire().await?; sql_fetch_row_by::(&client, (), disk_id).await } @@ -537,7 +545,7 @@ impl DataStore { &self, project_id: &Uuid, disk_name: &Name, - ) -> LookupResult { + ) -> LookupResult { let client = self.pool.acquire().await?; sql_fetch_row_by::( &client, @@ -553,12 +561,13 @@ impl DataStore { let mut values = SqlValueSet::new(); values.set("time_deleted", &now); - api::DiskState::Destroyed.sql_serialize(&mut values); + api::external::DiskState::Destroyed.sql_serialize(&mut values); let mut cond_sql = SqlString::new(); - let disk_state_detached = api::DiskState::Detached.to_string(); + let disk_state_detached = + api::external::DiskState::Detached.to_string(); let p1 = cond_sql.next_param(&disk_state_detached); - let disk_state_faulted = api::DiskState::Faulted.to_string(); + let disk_state_faulted = api::external::DiskState::Faulted.to_string(); let p2 = cond_sql.next_param(&disk_state_faulted); cond_sql.push_str(&format!("disk_state in ({}, {})", p1, p2)); @@ -577,14 +586,16 @@ impl DataStore { bail_unless!(found_id == *disk_id); // TODO-cleanup It would be nice to use - // api::DiskState::try_from(&tokio_postgres::Row), but the column names + // api::external::DiskState::try_from(&tokio_postgres::Row), but the column names // are different here. let disk_state_str: &str = sql_row_value(&row, "found_disk_state")?; let attach_instance_id: Option = sql_row_value(&row, "found_attach_instance_id")?; - let found_disk_state = - api::DiskState::try_from((disk_state_str, attach_instance_id)) - .map_err(|e| Error::internal_error(&e))?; + let found_disk_state = api::external::DiskState::try_from(( + disk_state_str, + attach_instance_id, + )) + .map_err(|e| Error::internal_error(&e))?; if update.updated { Ok(()) diff --git a/omicron-nexus/src/db/operations.rs b/omicron-nexus/src/db/operations.rs index 5d3db1e8567..14cc7a8cebb 100644 --- a/omicron-nexus/src/db/operations.rs +++ b/omicron-nexus/src/db/operations.rs @@ -3,7 +3,7 @@ * and extract values */ -use omicron_common::api::Error; +use omicron_common::api::external::Error; use omicron_common::db::sql_error_generic; use omicron_common::db::DbError; use std::convert::TryFrom; diff --git a/omicron-nexus/src/db/pool.rs b/omicron-nexus/src/db/pool.rs index c71543f44f8..f66ac5fb185 100644 --- a/omicron-nexus/src/db/pool.rs +++ b/omicron-nexus/src/db/pool.rs @@ -26,7 +26,7 @@ use super::Config as DbConfig; use bb8_postgres::PostgresConnectionManager; -use omicron_common::api::Error; +use omicron_common::api::external::Error; use std::ops::Deref; #[derive(Debug)] diff --git a/omicron-nexus/src/db/saga_recovery.rs b/omicron-nexus/src/db/saga_recovery.rs index 5f1a98bdb31..862c84751bd 100644 --- a/omicron-nexus/src/db/saga_recovery.rs +++ b/omicron-nexus/src/db/saga_recovery.rs @@ -6,7 +6,7 @@ use crate::db; use crate::db::schema; use crate::db::sql::Table; use crate::db::sql_operations::sql_paginate; -use omicron_common::api::Error; +use omicron_common::api::external::Error; use omicron_common::backoff::internal_service_policy; use omicron_common::backoff::retry_notify; use omicron_common::backoff::BackoffError; diff --git a/omicron-nexus/src/db/saga_types.rs b/omicron-nexus/src/db/saga_types.rs index add148ea87a..0a3be7dd983 100644 --- a/omicron-nexus/src/db/saga_types.rs +++ b/omicron-nexus/src/db/saga_types.rs @@ -11,8 +11,8 @@ */ use crate::db; -use omicron_common::api::Error; -use omicron_common::api::Generation; +use omicron_common::api::external::Error; +use omicron_common::api::external::Generation; use omicron_common::db::sql_row_value; use omicron_common::impl_sql_wrapping; use std::convert::TryFrom; diff --git a/omicron-nexus/src/db/schema.rs b/omicron-nexus/src/db/schema.rs index 79fba192cac..ab86dbcb8e7 100644 --- a/omicron-nexus/src/db/schema.rs +++ b/omicron-nexus/src/db/schema.rs @@ -6,10 +6,9 @@ */ use omicron_common::api; -use omicron_common::api::Error; -use omicron_common::api::Name; -use omicron_common::api::ResourceType; -use omicron_common::api::{OximeterInfo, ProducerEndpoint}; +use omicron_common::api::external::Error; +use omicron_common::api::external::Name; +use omicron_common::api::external::ResourceType; use uuid::Uuid; use super::sql::LookupKey; @@ -20,7 +19,7 @@ use crate::db; /** Describes the "Project" table */ pub struct Project; impl Table for Project { - type ModelType = api::Project; + type ModelType = api::internal::nexus::Project; const TABLE_NAME: &'static str = "Project"; const ALL_COLUMNS: &'static [&'static str] = &[ "id", @@ -39,7 +38,7 @@ impl ResourceTable for Project { /** Describes the "Instance" table */ pub struct Instance; impl Table for Instance { - type ModelType = api::Instance; + type ModelType = api::internal::nexus::Instance; const TABLE_NAME: &'static str = "Instance"; const ALL_COLUMNS: &'static [&'static str] = &[ "id", @@ -66,7 +65,7 @@ impl ResourceTable for Instance { /** Describes the "Disk" table */ pub struct Disk; impl Table for Disk { - type ModelType = api::Disk; + type ModelType = api::internal::nexus::Disk; const TABLE_NAME: &'static str = "Disk"; const ALL_COLUMNS: &'static [&'static str] = &[ "id", @@ -121,7 +120,7 @@ impl Table for SagaNodeEvent { /** Describes the "Oximeter" table */ pub struct Oximeter; impl Table for Oximeter { - type ModelType = OximeterInfo; + type ModelType = api::internal::nexus::OximeterInfo; const TABLE_NAME: &'static str = "Oximeter"; const ALL_COLUMNS: &'static [&'static str] = &["id", "time_created", "time_modified", "ip", "port"]; @@ -130,7 +129,7 @@ impl Table for Oximeter { /** Describes the "MetricProducer" table */ pub struct MetricProducer; impl Table for MetricProducer { - type ModelType = ProducerEndpoint; + type ModelType = api::internal::nexus::ProducerEndpoint; const TABLE_NAME: &'static str = "MetricProducer"; const ALL_COLUMNS: &'static [&'static str] = &[ "id", @@ -146,7 +145,7 @@ impl Table for MetricProducer { /** Describes the "OximeterAssignment" table */ pub struct OximeterAssignment; impl Table for OximeterAssignment { - type ModelType = omicron_common::api::OximeterAssignment; + type ModelType = api::internal::nexus::OximeterAssignment; const TABLE_NAME: &'static str = "OximeterAssignment"; const ALL_COLUMNS: &'static [&'static str] = &["oximeter_id", "producer_id", "time_created"]; @@ -155,7 +154,7 @@ impl Table for OximeterAssignment { /** Describes the "VPC" table */ pub struct VPC; impl Table for VPC { - type ModelType = api::VPC; + type ModelType = api::external::VPC; const TABLE_NAME: &'static str = "VPC"; const ALL_COLUMNS: &'static [&'static str] = &[ "id", @@ -171,7 +170,7 @@ impl Table for VPC { /** Describes the "VPCSubnet" table */ pub struct VPCSubnet; impl Table for VPCSubnet { - type ModelType = api::VPCSubnet; + type ModelType = api::external::VPCSubnet; const TABLE_NAME: &'static str = "VPCSubnet"; const ALL_COLUMNS: &'static [&'static str] = &[ "id", @@ -189,7 +188,7 @@ impl Table for VPCSubnet { /** Describes the "NetworkInterface" table */ pub struct NetworkInterface; impl Table for NetworkInterface { - type ModelType = api::NetworkInterface; + type ModelType = api::external::NetworkInterface; const TABLE_NAME: &'static str = "NetworkInterface"; const ALL_COLUMNS: &'static [&'static str] = &[ "id", diff --git a/omicron-nexus/src/db/sec_store.rs b/omicron-nexus/src/db/sec_store.rs index 1fac0579f71..aa829a85d4a 100644 --- a/omicron-nexus/src/db/sec_store.rs +++ b/omicron-nexus/src/db/sec_store.rs @@ -5,7 +5,7 @@ use crate::db; use anyhow::Context; use async_trait::async_trait; -use omicron_common::api::Generation; +use omicron_common::api::external::Generation; use slog::Logger; use std::fmt; use std::sync::Arc; diff --git a/omicron-nexus/src/db/sql.rs b/omicron-nexus/src/db/sql.rs index 56d08d5bbc1..000cf50f22a 100644 --- a/omicron-nexus/src/db/sql.rs +++ b/omicron-nexus/src/db/sql.rs @@ -5,9 +5,9 @@ * agnostic to the control plane. There is a bit of leakage in a few places. */ -use omicron_common::api::DataPageParams; -use omicron_common::api::Error; -use omicron_common::api::ResourceType; +use omicron_common::api::external::DataPageParams; +use omicron_common::api::external::Error; +use omicron_common::api::external::ResourceType; use std::collections::BTreeSet; use std::convert::TryFrom; use tokio_postgres::types::FromSql; diff --git a/omicron-nexus/src/db/sql_operations.rs b/omicron-nexus/src/db/sql_operations.rs index 9e1a7eaf510..70fd5e3bcee 100644 --- a/omicron-nexus/src/db/sql_operations.rs +++ b/omicron-nexus/src/db/sql_operations.rs @@ -3,11 +3,11 @@ */ use futures::StreamExt; -use omicron_common::api::DataPageParams; -use omicron_common::api::Error; -use omicron_common::api::ListResult; -use omicron_common::api::LookupResult; -use omicron_common::api::ResourceType; +use omicron_common::api::external::DataPageParams; +use omicron_common::api::external::Error; +use omicron_common::api::external::ListResult; +use omicron_common::api::external::LookupResult; +use omicron_common::api::external::ResourceType; use omicron_common::db::sql_error_generic; use omicron_common::db::sql_row_value; use omicron_common::db::DbError; diff --git a/omicron-nexus/src/http_entrypoints_external.rs b/omicron-nexus/src/http_entrypoints_external.rs index 92cf7ff733d..83e232bc441 100644 --- a/omicron-nexus/src/http_entrypoints_external.rs +++ b/omicron-nexus/src/http_entrypoints_external.rs @@ -16,34 +16,34 @@ use dropshot::Query; use dropshot::RequestContext; use dropshot::ResultsPage; use dropshot::TypedBody; -use omicron_common::api::http_pagination::data_page_params_for; -use omicron_common::api::http_pagination::data_page_params_nameid_id; -use omicron_common::api::http_pagination::data_page_params_nameid_name; -use omicron_common::api::http_pagination::pagination_field_for_scan_params; -use omicron_common::api::http_pagination::PagField; -use omicron_common::api::http_pagination::PaginatedById; -use omicron_common::api::http_pagination::PaginatedByName; -use omicron_common::api::http_pagination::PaginatedByNameOrId; -use omicron_common::api::http_pagination::ScanById; -use omicron_common::api::http_pagination::ScanByName; -use omicron_common::api::http_pagination::ScanByNameOrId; -use omicron_common::api::http_pagination::ScanParams; -use omicron_common::api::to_view_list; -use omicron_common::api::DataPageParams; -use omicron_common::api::DiskAttachment; -use omicron_common::api::DiskCreateParams; -use omicron_common::api::DiskView; -use omicron_common::api::InstanceCreateParams; -use omicron_common::api::InstanceView; -use omicron_common::api::Name; -use omicron_common::api::Object; -use omicron_common::api::PaginationOrder; -use omicron_common::api::ProjectCreateParams; -use omicron_common::api::ProjectUpdateParams; -use omicron_common::api::ProjectView; -use omicron_common::api::RackView; -use omicron_common::api::SagaView; -use omicron_common::api::SledView; +use omicron_common::api; +use omicron_common::api::external::http_pagination::data_page_params_for; +use omicron_common::api::external::http_pagination::data_page_params_nameid_id; +use omicron_common::api::external::http_pagination::data_page_params_nameid_name; +use omicron_common::api::external::http_pagination::pagination_field_for_scan_params; +use omicron_common::api::external::http_pagination::PagField; +use omicron_common::api::external::http_pagination::PaginatedById; +use omicron_common::api::external::http_pagination::PaginatedByName; +use omicron_common::api::external::http_pagination::PaginatedByNameOrId; +use omicron_common::api::external::http_pagination::ScanById; +use omicron_common::api::external::http_pagination::ScanByName; +use omicron_common::api::external::http_pagination::ScanByNameOrId; +use omicron_common::api::external::http_pagination::ScanParams; +use omicron_common::api::external::to_list; +use omicron_common::api::external::DataPageParams; +use omicron_common::api::external::DiskAttachment; +use omicron_common::api::external::DiskCreateParams; +use omicron_common::api::external::DiskView; +use omicron_common::api::external::InstanceCreateParams; +use omicron_common::api::external::InstanceView; +use omicron_common::api::external::Name; +use omicron_common::api::external::PaginationOrder; +use omicron_common::api::external::ProjectCreateParams; +use omicron_common::api::external::ProjectUpdateParams; +use omicron_common::api::external::ProjectView; +use omicron_common::api::external::RackView; +use omicron_common::api::external::SagaView; +use omicron_common::api::external::SledView; use schemars::JsonSchema; use serde::Deserialize; use std::num::NonZeroU32; @@ -166,7 +166,9 @@ async fn projects_get( } }; - let view_list = to_view_list(project_stream).await; + let view_list = + to_list::(project_stream) + .await; Ok(HttpResponseOk(ScanByNameOrId::results_page(&query, view_list)?)) } @@ -184,7 +186,7 @@ async fn projects_post( let apictx = rqctx.context(); let nexus = &apictx.nexus; let project = nexus.project_create(&new_project.into_inner()).await?; - Ok(HttpResponseCreated(project.to_view())) + Ok(HttpResponseCreated(project.into())) } /** @@ -212,7 +214,7 @@ async fn projects_get_project( let path = path_params.into_inner(); let project_name = &path.project_name; let project = nexus.project_fetch(&project_name).await?; - Ok(HttpResponseOk(project.to_view())) + Ok(HttpResponseOk(project.into())) } /** @@ -259,7 +261,7 @@ async fn projects_put_project( let newproject = nexus .project_update(&project_name, &updated_project.into_inner()) .await?; - Ok(HttpResponseOk(newproject.to_view())) + Ok(HttpResponseOk(newproject.into())) } /* @@ -289,8 +291,10 @@ async fn project_disks_get( &data_page_params_for(&rqctx, &query)?, ) .await?; - let view_list = to_view_list(disk_stream).await; - Ok(HttpResponseOk(ScanByName::results_page(&query, view_list)?)) + + let disk_list = + to_list::(disk_stream).await; + Ok(HttpResponseOk(ScanByName::results_page(&query, disk_list)?)) } /** @@ -314,7 +318,7 @@ async fn project_disks_post( let new_disk_params = &new_disk.into_inner(); let disk = nexus.project_create_disk(&project_name, &new_disk_params).await?; - Ok(HttpResponseCreated(disk.to_view())) + Ok(HttpResponseCreated(disk.into())) } /** @@ -343,7 +347,7 @@ async fn project_disks_get_disk( let project_name = &path.project_name; let disk_name = &path.disk_name; let disk = nexus.project_lookup_disk(&project_name, &disk_name).await?; - Ok(HttpResponseOk(disk.to_view())) + Ok(HttpResponseOk(disk.into())) } /** @@ -393,7 +397,10 @@ async fn project_instances_get( &data_page_params_for(&rqctx, &query)?, ) .await?; - let view_list = to_view_list(instance_stream).await; + let view_list = to_list::( + instance_stream, + ) + .await; Ok(HttpResponseOk(ScanByName::results_page(&query, view_list)?)) } @@ -425,7 +432,7 @@ async fn project_instances_post( let instance = nexus .project_create_instance(&project_name, &new_instance_params) .await?; - Ok(HttpResponseCreated(instance.to_view())) + Ok(HttpResponseCreated(instance.into())) } /** @@ -455,7 +462,7 @@ async fn project_instances_get_instance( let instance_name = &path.instance_name; let instance = nexus.project_lookup_instance(&project_name, &instance_name).await?; - Ok(HttpResponseOk(instance.to_view())) + Ok(HttpResponseOk(instance.into())) } /** @@ -495,7 +502,7 @@ async fn project_instances_instance_reboot( let project_name = &path.project_name; let instance_name = &path.instance_name; let instance = nexus.instance_reboot(&project_name, &instance_name).await?; - Ok(HttpResponseAccepted(instance.to_view())) + Ok(HttpResponseAccepted(instance.into())) } /** @@ -515,7 +522,7 @@ async fn project_instances_instance_start( let project_name = &path.project_name; let instance_name = &path.instance_name; let instance = nexus.instance_start(&project_name, &instance_name).await?; - Ok(HttpResponseAccepted(instance.to_view())) + Ok(HttpResponseAccepted(instance.into())) } /** @@ -536,7 +543,7 @@ async fn project_instances_instance_stop( let project_name = &path.project_name; let instance_name = &path.instance_name; let instance = nexus.instance_stop(&project_name, &instance_name).await?; - Ok(HttpResponseAccepted(instance.to_view())) + Ok(HttpResponseAccepted(instance.into())) } /** @@ -564,7 +571,7 @@ async fn instance_disks_get( let disk_list = nexus .instance_list_disks(&project_name, &instance_name, &fake_query) .await?; - let view_list = to_view_list(disk_list).await; + let view_list = to_list(disk_list).await; Ok(HttpResponseOk(view_list)) } @@ -598,7 +605,7 @@ async fn instance_disks_get_disk( let attachment = nexus .instance_get_disk(&project_name, &instance_name, &disk_name) .await?; - Ok(HttpResponseOk(attachment.to_view())) + Ok(HttpResponseOk(attachment)) } /** @@ -621,7 +628,7 @@ async fn instance_disks_put_disk( let attachment = nexus .instance_attach_disk(&project_name, &instance_name, &disk_name) .await?; - Ok(HttpResponseCreated(attachment.to_view())) + Ok(HttpResponseCreated(attachment)) } /** @@ -667,7 +674,8 @@ async fn hardware_racks_get( let query = query_params.into_inner(); let rack_stream = nexus.racks_list(&data_page_params_for(&rqctx, &query)?).await?; - let view_list = to_view_list(rack_stream).await; + let view_list = + to_list::(rack_stream).await; Ok(HttpResponseOk(ScanById::results_page(&query, view_list)?)) } @@ -695,7 +703,7 @@ async fn hardware_racks_get_rack( let nexus = &apictx.nexus; let path = path_params.into_inner(); let rack_info = nexus.rack_lookup(&path.rack_id).await?; - Ok(HttpResponseOk(rack_info.to_view())) + Ok(HttpResponseOk(rack_info.into())) } /* @@ -718,7 +726,8 @@ async fn hardware_sleds_get( let query = query_params.into_inner(); let sled_stream = nexus.sleds_list(&data_page_params_for(&rqctx, &query)?).await?; - let view_list = to_view_list(sled_stream).await; + let view_list = + to_list::(sled_stream).await; Ok(HttpResponseOk(ScanById::results_page(&query, view_list)?)) } @@ -746,7 +755,7 @@ async fn hardware_sleds_get_sled( let nexus = &apictx.nexus; let path = path_params.into_inner(); let sled_info = nexus.sled_lookup(&path.sled_id).await?; - Ok(HttpResponseOk(sled_info.to_view())) + Ok(HttpResponseOk(sled_info.into())) } /* @@ -769,7 +778,7 @@ async fn sagas_get( let query = query_params.into_inner(); let pagparams = data_page_params_for(&rqctx, &query)?; let saga_stream = nexus.sagas_list(&pagparams).await?; - let view_list = to_view_list(saga_stream).await; + let view_list = to_list(saga_stream).await; Ok(HttpResponseOk(ScanById::results_page(&query, view_list)?)) } diff --git a/omicron-nexus/src/http_entrypoints_internal.rs b/omicron-nexus/src/http_entrypoints_internal.rs index 9dcb8833687..9123b42ca00 100644 --- a/omicron-nexus/src/http_entrypoints_internal.rs +++ b/omicron-nexus/src/http_entrypoints_internal.rs @@ -10,11 +10,11 @@ use dropshot::HttpResponseUpdatedNoContent; use dropshot::Path; use dropshot::RequestContext; use dropshot::TypedBody; -use omicron_common::api::DiskRuntimeState; -use omicron_common::api::InstanceRuntimeState; -use omicron_common::api::OximeterInfo; -use omicron_common::api::ProducerEndpoint; -use omicron_common::api::SledAgentStartupInfo; +use omicron_common::api::internal::nexus::DiskRuntimeState; +use omicron_common::api::internal::nexus::InstanceRuntimeState; +use omicron_common::api::internal::nexus::OximeterInfo; +use omicron_common::api::internal::nexus::ProducerEndpoint; +use omicron_common::api::internal::nexus::SledAgentStartupInfo; use omicron_common::SledAgentClient; use schemars::JsonSchema; use serde::Deserialize; diff --git a/omicron-nexus/src/nexus.rs b/omicron-nexus/src/nexus.rs index f2816ed5619..c6bb6c37ca9 100644 --- a/omicron-nexus/src/nexus.rs +++ b/omicron-nexus/src/nexus.rs @@ -11,37 +11,37 @@ use chrono::Utc; use futures::future::ready; use futures::lock::Mutex; use futures::StreamExt; -use omicron_common::api::CreateResult; -use omicron_common::api::DataPageParams; -use omicron_common::api::DeleteResult; -use omicron_common::api::Disk; -use omicron_common::api::DiskAttachment; -use omicron_common::api::DiskCreateParams; -use omicron_common::api::DiskRuntimeState; -use omicron_common::api::DiskState; -use omicron_common::api::DiskStateRequested; -use omicron_common::api::Error; -use omicron_common::api::Generation; -use omicron_common::api::IdentityMetadata; -use omicron_common::api::Instance; -use omicron_common::api::InstanceCreateParams; -use omicron_common::api::InstanceRuntimeState; -use omicron_common::api::InstanceRuntimeStateRequested; -use omicron_common::api::InstanceState; -use omicron_common::api::InstanceStateRequested; -use omicron_common::api::ListResult; -use omicron_common::api::LookupResult; -use omicron_common::api::Name; -use omicron_common::api::OximeterInfo; -use omicron_common::api::ProducerEndpoint; -use omicron_common::api::Project; -use omicron_common::api::ProjectCreateParams; -use omicron_common::api::ProjectUpdateParams; -use omicron_common::api::Rack; -use omicron_common::api::ResourceType; -use omicron_common::api::SagaView; -use omicron_common::api::Sled; -use omicron_common::api::UpdateResult; +use omicron_common::api::external::CreateResult; +use omicron_common::api::external::DataPageParams; +use omicron_common::api::external::DeleteResult; +use omicron_common::api::external::DiskAttachment; +use omicron_common::api::external::DiskCreateParams; +use omicron_common::api::external::DiskState; +use omicron_common::api::external::Error; +use omicron_common::api::external::Generation; +use omicron_common::api::external::IdentityMetadata; +use omicron_common::api::external::InstanceCreateParams; +use omicron_common::api::external::InstanceState; +use omicron_common::api::external::ListResult; +use omicron_common::api::external::LookupResult; +use omicron_common::api::external::Name; +use omicron_common::api::external::ProjectCreateParams; +use omicron_common::api::external::ProjectUpdateParams; +use omicron_common::api::external::ResourceType; +use omicron_common::api::external::SagaView; +use omicron_common::api::external::UpdateResult; +use omicron_common::api::internal::nexus::Disk; +use omicron_common::api::internal::nexus::DiskRuntimeState; +use omicron_common::api::internal::nexus::Instance; +use omicron_common::api::internal::nexus::InstanceRuntimeState; +use omicron_common::api::internal::nexus::OximeterInfo; +use omicron_common::api::internal::nexus::ProducerEndpoint; +use omicron_common::api::internal::nexus::Project; +use omicron_common::api::internal::nexus::Rack; +use omicron_common::api::internal::nexus::Sled; +use omicron_common::api::internal::sled_agent::DiskStateRequested; +use omicron_common::api::internal::sled_agent::InstanceRuntimeStateRequested; +use omicron_common::api::internal::sled_agent::InstanceStateRequested; use omicron_common::bail_unless; use omicron_common::collection::collection_page; use omicron_common::OximeterClient; diff --git a/omicron-nexus/src/saga_interface.rs b/omicron-nexus/src/saga_interface.rs index a6be04c7ec2..c9231308df7 100644 --- a/omicron-nexus/src/saga_interface.rs +++ b/omicron-nexus/src/saga_interface.rs @@ -4,8 +4,8 @@ use crate::db; use crate::Nexus; -use omicron_common::api::Error; -use omicron_common::api::InstanceCreateParams; +use omicron_common::api::external::Error; +use omicron_common::api::external::InstanceCreateParams; use omicron_common::SledAgentClient; use std::fmt; use std::sync::Arc; diff --git a/omicron-nexus/src/sagas.rs b/omicron-nexus/src/sagas.rs index aba8d055e7a..65604b926b5 100644 --- a/omicron-nexus/src/sagas.rs +++ b/omicron-nexus/src/sagas.rs @@ -12,12 +12,12 @@ use crate::saga_interface::SagaContext; use chrono::Utc; use lazy_static::lazy_static; -use omicron_common::api::Generation; -use omicron_common::api::InstanceCreateParams; -use omicron_common::api::InstanceRuntimeState; -use omicron_common::api::InstanceRuntimeStateRequested; -use omicron_common::api::InstanceState; -use omicron_common::api::InstanceStateRequested; +use omicron_common::api::external::Generation; +use omicron_common::api::external::InstanceCreateParams; +use omicron_common::api::external::InstanceState; +use omicron_common::api::internal::nexus::InstanceRuntimeState; +use omicron_common::api::internal::sled_agent::InstanceRuntimeStateRequested; +use omicron_common::api::internal::sled_agent::InstanceStateRequested; use serde::Deserialize; use serde::Serialize; use std::collections::BTreeMap; diff --git a/omicron-nexus/tests/common/mod.rs b/omicron-nexus/tests/common/mod.rs index 0a51610e163..7e3e1c91113 100644 --- a/omicron-nexus/tests/common/mod.rs +++ b/omicron-nexus/tests/common/mod.rs @@ -7,8 +7,8 @@ use dropshot::test_util::LogContext; use dropshot::ConfigDropshot; use dropshot::ConfigLogging; use dropshot::ConfigLoggingLevel; -use omicron_common::api::IdentityMetadata; -use omicron_common::api::ProducerEndpoint; +use omicron_common::api::external::IdentityMetadata; +use omicron_common::api::internal::nexus::ProducerEndpoint; use omicron_common::dev; use slog::o; use slog::Logger; diff --git a/omicron-nexus/tests/test_basic.rs b/omicron-nexus/tests/test_basic.rs index 9f698bf4264..f1cdf819e5b 100644 --- a/omicron-nexus/tests/test_basic.rs +++ b/omicron-nexus/tests/test_basic.rs @@ -13,13 +13,13 @@ use dropshot::test_util::read_json; use dropshot::test_util::ClientTestContext; use http::method::Method; use http::StatusCode; -use omicron_common::api::IdentityMetadataCreateParams; -use omicron_common::api::IdentityMetadataUpdateParams; -use omicron_common::api::Name; -use omicron_common::api::ProjectCreateParams; -use omicron_common::api::ProjectUpdateParams; -use omicron_common::api::ProjectView; -use omicron_common::api::SledView; +use omicron_common::api::external::IdentityMetadataCreateParams; +use omicron_common::api::external::IdentityMetadataUpdateParams; +use omicron_common::api::external::Name; +use omicron_common::api::external::ProjectCreateParams; +use omicron_common::api::external::ProjectUpdateParams; +use omicron_common::api::external::ProjectView; +use omicron_common::api::external::SledView; use std::convert::TryFrom; use uuid::Uuid; diff --git a/omicron-nexus/tests/test_disks.rs b/omicron-nexus/tests/test_disks.rs index 2b1a5b0503e..bff98a49f54 100644 --- a/omicron-nexus/tests/test_disks.rs +++ b/omicron-nexus/tests/test_disks.rs @@ -4,18 +4,18 @@ use http::method::Method; use http::StatusCode; -use omicron_common::api::ByteCount; -use omicron_common::api::DiskAttachment; -use omicron_common::api::DiskCreateParams; -use omicron_common::api::DiskState; -use omicron_common::api::DiskView; -use omicron_common::api::IdentityMetadataCreateParams; -use omicron_common::api::InstanceCpuCount; -use omicron_common::api::InstanceCreateParams; -use omicron_common::api::InstanceView; -use omicron_common::api::Name; -use omicron_common::api::ProjectCreateParams; -use omicron_common::api::ProjectView; +use omicron_common::api::external::ByteCount; +use omicron_common::api::external::DiskAttachment; +use omicron_common::api::external::DiskCreateParams; +use omicron_common::api::external::DiskState; +use omicron_common::api::external::DiskView; +use omicron_common::api::external::IdentityMetadataCreateParams; +use omicron_common::api::external::InstanceCpuCount; +use omicron_common::api::external::InstanceCreateParams; +use omicron_common::api::external::InstanceView; +use omicron_common::api::external::Name; +use omicron_common::api::external::ProjectCreateParams; +use omicron_common::api::external::ProjectView; use omicron_common::SledAgentTestInterfaces as _; use omicron_nexus::Nexus; use omicron_nexus::TestInterfaces as _; diff --git a/omicron-nexus/tests/test_instances.rs b/omicron-nexus/tests/test_instances.rs index d9998e07cea..42fd893698c 100644 --- a/omicron-nexus/tests/test_instances.rs +++ b/omicron-nexus/tests/test_instances.rs @@ -4,15 +4,15 @@ use http::method::Method; use http::StatusCode; -use omicron_common::api::ByteCount; -use omicron_common::api::IdentityMetadataCreateParams; -use omicron_common::api::InstanceCpuCount; -use omicron_common::api::InstanceCreateParams; -use omicron_common::api::InstanceState; -use omicron_common::api::InstanceView; -use omicron_common::api::Name; -use omicron_common::api::ProjectCreateParams; -use omicron_common::api::ProjectView; +use omicron_common::api::external::ByteCount; +use omicron_common::api::external::IdentityMetadataCreateParams; +use omicron_common::api::external::InstanceCpuCount; +use omicron_common::api::external::InstanceCreateParams; +use omicron_common::api::external::InstanceState; +use omicron_common::api::external::InstanceView; +use omicron_common::api::external::Name; +use omicron_common::api::external::ProjectCreateParams; +use omicron_common::api::external::ProjectView; use omicron_common::SledAgentTestInterfaces as _; use omicron_nexus::Nexus; use omicron_nexus::TestInterfaces as _; diff --git a/omicron-sled-agent/src/common/disk.rs b/omicron-sled-agent/src/common/disk.rs index a97ca9690a1..067aba9fb40 100644 --- a/omicron-sled-agent/src/common/disk.rs +++ b/omicron-sled-agent/src/common/disk.rs @@ -1,10 +1,10 @@ //! Describes the states of network-attached storage. use chrono::Utc; -use omicron_common::api::DiskRuntimeState; -use omicron_common::api::DiskState; -use omicron_common::api::DiskStateRequested; -use omicron_common::api::Error; +use omicron_common::api::external::DiskState; +use omicron_common::api::external::Error; +use omicron_common::api::internal::nexus::DiskRuntimeState; +use omicron_common::api::internal::sled_agent::DiskStateRequested; use propolis_client::api::DiskAttachmentState as PropolisDiskState; use uuid::Uuid; diff --git a/omicron-sled-agent/src/common/instance.rs b/omicron-sled-agent/src/common/instance.rs index 8705efbf0f8..cdd3391928d 100644 --- a/omicron-sled-agent/src/common/instance.rs +++ b/omicron-sled-agent/src/common/instance.rs @@ -1,11 +1,11 @@ //! Describes the states of VM instances. use chrono::Utc; -use omicron_common::api::Error; -use omicron_common::api::InstanceRuntimeState; -use omicron_common::api::InstanceRuntimeStateRequested; -use omicron_common::api::InstanceState; -use omicron_common::api::InstanceStateRequested; +use omicron_common::api::external::Error; +use omicron_common::api::external::InstanceState; +use omicron_common::api::internal::nexus::InstanceRuntimeState; +use omicron_common::api::internal::sled_agent::InstanceRuntimeStateRequested; +use omicron_common::api::internal::sled_agent::InstanceStateRequested; use propolis_client::api::InstanceState as PropolisInstanceState; /// Action to be taken on behalf of state transition. @@ -261,9 +261,10 @@ impl InstanceStates { mod test { use super::{Action, InstanceStates}; use chrono::Utc; - use omicron_common::api::{ - Generation, InstanceRuntimeState, InstanceState as State, - InstanceStateRequested as Requested, + use omicron_common::api::external::{Generation, InstanceState as State}; + use omicron_common::api::internal::{ + nexus::InstanceRuntimeState, + sled_agent::InstanceStateRequested as Requested, }; use propolis_client::api::InstanceState as Observed; diff --git a/omicron-sled-agent/src/http_entrypoints.rs b/omicron-sled-agent/src/http_entrypoints.rs index 837b15a21ce..72ea0c0e5ad 100644 --- a/omicron-sled-agent/src/http_entrypoints.rs +++ b/omicron-sled-agent/src/http_entrypoints.rs @@ -7,10 +7,10 @@ use dropshot::HttpResponseOk; use dropshot::Path; use dropshot::RequestContext; use dropshot::TypedBody; -use omicron_common::api::DiskEnsureBody; -use omicron_common::api::DiskRuntimeState; -use omicron_common::api::InstanceEnsureBody; -use omicron_common::api::InstanceRuntimeState; +use omicron_common::api::internal::nexus::DiskRuntimeState; +use omicron_common::api::internal::nexus::InstanceRuntimeState; +use omicron_common::api::internal::sled_agent::DiskEnsureBody; +use omicron_common::api::internal::sled_agent::InstanceEnsureBody; use schemars::JsonSchema; use serde::Deserialize; use std::sync::Arc; diff --git a/omicron-sled-agent/src/illumos/dladm.rs b/omicron-sled-agent/src/illumos/dladm.rs index 6ca6e0871eb..504d4e8237b 100644 --- a/omicron-sled-agent/src/illumos/dladm.rs +++ b/omicron-sled-agent/src/illumos/dladm.rs @@ -1,7 +1,7 @@ //! Utilities for poking at data links. use crate::illumos::{execute, PFEXEC}; -use omicron_common::api::Error; +use omicron_common::api::external::Error; pub const VNIC_PREFIX: &str = "vnic_propolis"; diff --git a/omicron-sled-agent/src/illumos/mod.rs b/omicron-sled-agent/src/illumos/mod.rs index 7887dcf09b6..ddb0bb43992 100644 --- a/omicron-sled-agent/src/illumos/mod.rs +++ b/omicron-sled-agent/src/illumos/mod.rs @@ -5,7 +5,7 @@ pub mod svc; pub mod zfs; pub mod zone; -use omicron_common::api::Error; +use omicron_common::api::external::Error; const PFEXEC: &str = "/usr/bin/pfexec"; diff --git a/omicron-sled-agent/src/illumos/svc.rs b/omicron-sled-agent/src/illumos/svc.rs index ac2f50f3676..c2e873a3c49 100644 --- a/omicron-sled-agent/src/illumos/svc.rs +++ b/omicron-sled-agent/src/illumos/svc.rs @@ -2,7 +2,7 @@ use cfg_if::cfg_if; -use omicron_common::api::Error; +use omicron_common::api::external::Error; use omicron_common::dev::poll; use std::time::Duration; diff --git a/omicron-sled-agent/src/illumos/zfs.rs b/omicron-sled-agent/src/illumos/zfs.rs index 952569cf41b..8bff22bb8f6 100644 --- a/omicron-sled-agent/src/illumos/zfs.rs +++ b/omicron-sled-agent/src/illumos/zfs.rs @@ -1,7 +1,7 @@ //! Utilities for poking at ZFS. use crate::illumos::{execute, PFEXEC}; -use omicron_common::api::Error; +use omicron_common::api::external::Error; pub const ZONE_ZFS_DATASET_MOUNTPOINT: &str = "/zone"; pub const ZONE_ZFS_DATASET: &str = "rpool/zone"; diff --git a/omicron-sled-agent/src/illumos/zone.rs b/omicron-sled-agent/src/illumos/zone.rs index 4c3473ef5e4..c69dcd5fc7c 100644 --- a/omicron-sled-agent/src/illumos/zone.rs +++ b/omicron-sled-agent/src/illumos/zone.rs @@ -1,7 +1,7 @@ //! API for interacting with Zones running Propolis. use ipnet::IpNet; -use omicron_common::api::Error; +use omicron_common::api::external::Error; use slog::Logger; use std::net::SocketAddr; use uuid::Uuid; diff --git a/omicron-sled-agent/src/instance.rs b/omicron-sled-agent/src/instance.rs index a5f80c3fdda..1ba59646901 100644 --- a/omicron-sled-agent/src/instance.rs +++ b/omicron-sled-agent/src/instance.rs @@ -5,9 +5,9 @@ use crate::illumos::svc::wait_for_service; use crate::illumos::{dladm::VNIC_PREFIX, zone::ZONE_PREFIX}; use crate::instance_manager::InstanceTicket; use futures::lock::Mutex; -use omicron_common::api::Error; -use omicron_common::api::InstanceRuntimeState; -use omicron_common::api::InstanceRuntimeStateRequested; +use omicron_common::api::external::Error; +use omicron_common::api::internal::nexus::InstanceRuntimeState; +use omicron_common::api::internal::sled_agent::InstanceRuntimeStateRequested; use omicron_common::dev::poll; use propolis_client::Client as PropolisClient; use slog::Logger; @@ -477,8 +477,9 @@ mod test { RequestContext, TypedBody, }; use futures::future::FutureExt; - use omicron_common::api::{ - Generation, InstanceRuntimeState, InstanceState, InstanceStateRequested, + use omicron_common::api::external::{Generation, InstanceState}; + use omicron_common::api::internal::{ + nexus::InstanceRuntimeState, sled_agent::InstanceStateRequested, }; use propolis_client::api; use tokio::sync::watch; diff --git a/omicron-sled-agent/src/instance_manager.rs b/omicron-sled-agent/src/instance_manager.rs index 76c45656eaa..77e1f060fe6 100644 --- a/omicron-sled-agent/src/instance_manager.rs +++ b/omicron-sled-agent/src/instance_manager.rs @@ -1,10 +1,9 @@ //! API for controlling multiple instances on a sled. use crate::illumos::zfs::ZONE_ZFS_DATASET; -use omicron_common::api::Error; -use omicron_common::api::{ - InstanceRuntimeState, InstanceRuntimeStateRequested, -}; +use omicron_common::api::external::Error; +use omicron_common::api::internal::nexus::InstanceRuntimeState; +use omicron_common::api::internal::sled_agent::InstanceRuntimeStateRequested; use slog::Logger; use std::collections::BTreeMap; use std::sync::{ @@ -199,8 +198,9 @@ mod test { use crate::instance::MockInstance; use crate::mocks::MockNexusClient; use chrono::Utc; - use omicron_common::api::{ - Generation, InstanceRuntimeState, InstanceState, InstanceStateRequested, + use omicron_common::api::external::{Generation, InstanceState}; + use omicron_common::api::internal::{ + nexus::InstanceRuntimeState, sled_agent::InstanceStateRequested, }; static INST_UUID_STR: &str = "e398c5d5-5059-4e55-beac-3a1071083aaa"; diff --git a/omicron-sled-agent/src/mocks/mod.rs b/omicron-sled-agent/src/mocks/mod.rs index b06e55231c6..580eac58fd9 100644 --- a/omicron-sled-agent/src/mocks/mod.rs +++ b/omicron-sled-agent/src/mocks/mod.rs @@ -1,9 +1,9 @@ //! Mock structures for testing. use mockall::mock; -use omicron_common::api::Error; -use omicron_common::api::InstanceRuntimeState; -use omicron_common::api::SledAgentStartupInfo; +use omicron_common::api::external::Error; +use omicron_common::api::internal::nexus::InstanceRuntimeState; +use omicron_common::api::internal::nexus::SledAgentStartupInfo; use slog::Logger; use std::net::SocketAddr; use uuid::Uuid; diff --git a/omicron-sled-agent/src/server.rs b/omicron-sled-agent/src/server.rs index 24a510b2e23..71ff3949fc0 100644 --- a/omicron-sled-agent/src/server.rs +++ b/omicron-sled-agent/src/server.rs @@ -4,7 +4,7 @@ use super::config::Config; use super::http_entrypoints::api as http_api; use super::sled_agent::SledAgent; -use omicron_common::api::SledAgentStartupInfo; +use omicron_common::api::internal::nexus::SledAgentStartupInfo; use omicron_common::backoff::{ internal_service_policy, retry_notify, BackoffError, }; diff --git a/omicron-sled-agent/src/sim/collection.rs b/omicron-sled-agent/src/sim/collection.rs index 378c8953509..5ce37b3ef5c 100644 --- a/omicron-sled-agent/src/sim/collection.rs +++ b/omicron-sled-agent/src/sim/collection.rs @@ -8,7 +8,7 @@ use futures::channel::mpsc::Receiver; use futures::channel::mpsc::Sender; use futures::lock::Mutex; use futures::stream::StreamExt; -use omicron_common::api::Error; +use omicron_common::api::external::Error; use omicron_common::NexusClient; use slog::Logger; use std::collections::BTreeMap; @@ -336,15 +336,15 @@ mod test { use chrono::Utc; use dropshot::test_util::LogContext; use futures::channel::mpsc::Receiver; - use omicron_common::api::DiskRuntimeState; - use omicron_common::api::DiskState; - use omicron_common::api::DiskStateRequested; - use omicron_common::api::Error; - use omicron_common::api::Generation; - use omicron_common::api::InstanceRuntimeState; - use omicron_common::api::InstanceRuntimeStateRequested; - use omicron_common::api::InstanceState; - use omicron_common::api::InstanceStateRequested; + use omicron_common::api::external::DiskState; + use omicron_common::api::external::Error; + use omicron_common::api::external::Generation; + use omicron_common::api::external::InstanceState; + use omicron_common::api::internal::nexus::DiskRuntimeState; + use omicron_common::api::internal::nexus::InstanceRuntimeState; + use omicron_common::api::internal::sled_agent::DiskStateRequested; + use omicron_common::api::internal::sled_agent::InstanceRuntimeStateRequested; + use omicron_common::api::internal::sled_agent::InstanceStateRequested; use omicron_common::dev::test_setup_log; fn make_instance( diff --git a/omicron-sled-agent/src/sim/disk.rs b/omicron-sled-agent/src/sim/disk.rs index 080cf690baa..4e627a203bc 100644 --- a/omicron-sled-agent/src/sim/disk.rs +++ b/omicron-sled-agent/src/sim/disk.rs @@ -4,11 +4,11 @@ use crate::sim::simulatable::Simulatable; use async_trait::async_trait; -use omicron_common::api::DiskRuntimeState; -use omicron_common::api::DiskState; -use omicron_common::api::DiskStateRequested; -use omicron_common::api::Error; -use omicron_common::api::Generation; +use omicron_common::api::external::DiskState; +use omicron_common::api::external::Error; +use omicron_common::api::external::Generation; +use omicron_common::api::internal::nexus::DiskRuntimeState; +use omicron_common::api::internal::sled_agent::DiskStateRequested; use omicron_common::NexusClient; use propolis_client::api::DiskAttachmentState as PropolisDiskState; use std::sync::Arc; diff --git a/omicron-sled-agent/src/sim/http_entrypoints.rs b/omicron-sled-agent/src/sim/http_entrypoints.rs index adb4172c68b..b553bc7dd21 100644 --- a/omicron-sled-agent/src/sim/http_entrypoints.rs +++ b/omicron-sled-agent/src/sim/http_entrypoints.rs @@ -10,10 +10,10 @@ use dropshot::HttpResponseUpdatedNoContent; use dropshot::Path; use dropshot::RequestContext; use dropshot::TypedBody; -use omicron_common::api::DiskEnsureBody; -use omicron_common::api::DiskRuntimeState; -use omicron_common::api::InstanceEnsureBody; -use omicron_common::api::InstanceRuntimeState; +use omicron_common::api::internal::nexus::DiskRuntimeState; +use omicron_common::api::internal::nexus::InstanceRuntimeState; +use omicron_common::api::internal::sled_agent::DiskEnsureBody; +use omicron_common::api::internal::sled_agent::InstanceEnsureBody; use schemars::JsonSchema; use serde::Deserialize; use std::sync::Arc; diff --git a/omicron-sled-agent/src/sim/instance.rs b/omicron-sled-agent/src/sim/instance.rs index 00de0f7d94b..ebb04f43d62 100644 --- a/omicron-sled-agent/src/sim/instance.rs +++ b/omicron-sled-agent/src/sim/instance.rs @@ -5,12 +5,12 @@ use super::simulatable::Simulatable; use async_trait::async_trait; -use omicron_common::api::Error; -use omicron_common::api::Generation; -use omicron_common::api::InstanceRuntimeState; -use omicron_common::api::InstanceRuntimeStateRequested; -use omicron_common::api::InstanceState; -use omicron_common::api::InstanceStateRequested; +use omicron_common::api::external::Error; +use omicron_common::api::external::Generation; +use omicron_common::api::external::InstanceState; +use omicron_common::api::internal::nexus::InstanceRuntimeState; +use omicron_common::api::internal::sled_agent::InstanceRuntimeStateRequested; +use omicron_common::api::internal::sled_agent::InstanceStateRequested; use omicron_common::NexusClient; use propolis_client::api::InstanceState as PropolisInstanceState; use std::sync::Arc; diff --git a/omicron-sled-agent/src/sim/server.rs b/omicron-sled-agent/src/sim/server.rs index b83de5c81b9..4fdc454a478 100644 --- a/omicron-sled-agent/src/sim/server.rs +++ b/omicron-sled-agent/src/sim/server.rs @@ -6,7 +6,7 @@ use super::config::Config; use super::http_entrypoints::api as http_api; use super::sled_agent::SledAgent; -use omicron_common::api::SledAgentStartupInfo; +use omicron_common::api::internal::nexus::SledAgentStartupInfo; use omicron_common::backoff::{ internal_service_policy, retry_notify, BackoffError, }; diff --git a/omicron-sled-agent/src/sim/simulatable.rs b/omicron-sled-agent/src/sim/simulatable.rs index b4ae48ea6ba..5999cb9d46b 100644 --- a/omicron-sled-agent/src/sim/simulatable.rs +++ b/omicron-sled-agent/src/sim/simulatable.rs @@ -1,6 +1,6 @@ use async_trait::async_trait; -use omicron_common::api::Error; -use omicron_common::api::Generation; +use omicron_common::api::external::Error; +use omicron_common::api::external::Generation; use omicron_common::NexusClient; use std::fmt; use std::sync::Arc; diff --git a/omicron-sled-agent/src/sim/sled_agent.rs b/omicron-sled-agent/src/sim/sled_agent.rs index 3c604f7365f..da2cc48ba50 100644 --- a/omicron-sled-agent/src/sim/sled_agent.rs +++ b/omicron-sled-agent/src/sim/sled_agent.rs @@ -2,11 +2,11 @@ * Simulated sled agent implementation */ -use omicron_common::api::DiskRuntimeState; -use omicron_common::api::DiskStateRequested; -use omicron_common::api::Error; -use omicron_common::api::InstanceRuntimeState; -use omicron_common::api::InstanceRuntimeStateRequested; +use omicron_common::api::external::Error; +use omicron_common::api::internal::nexus::DiskRuntimeState; +use omicron_common::api::internal::nexus::InstanceRuntimeState; +use omicron_common::api::internal::sled_agent::DiskStateRequested; +use omicron_common::api::internal::sled_agent::InstanceRuntimeStateRequested; use omicron_common::NexusClient; use slog::Logger; use std::sync::Arc; diff --git a/omicron-sled-agent/src/sled_agent.rs b/omicron-sled-agent/src/sled_agent.rs index 7f335c7a471..5c5d6d0f12f 100644 --- a/omicron-sled-agent/src/sled_agent.rs +++ b/omicron-sled-agent/src/sled_agent.rs @@ -1,10 +1,12 @@ //! Sled agent implementation -use omicron_common::api::Error; +use omicron_common::api::external::Error; use omicron_common::api::{ - DiskRuntimeState, DiskStateRequested, InstanceRuntimeState, - InstanceRuntimeStateRequested, + internal::nexus::DiskRuntimeState, internal::nexus::InstanceRuntimeState, + internal::sled_agent::DiskStateRequested, + internal::sled_agent::InstanceRuntimeStateRequested, }; + use slog::Logger; use std::sync::Arc; use uuid::Uuid; diff --git a/oximeter/oximeter/examples/producer.rs b/oximeter/oximeter/examples/producer.rs index b4ea73ba7af..2e147ad16e6 100644 --- a/oximeter/oximeter/examples/producer.rs +++ b/oximeter/oximeter/examples/producer.rs @@ -5,7 +5,7 @@ use std::time::Duration; use chrono::{DateTime, Utc}; use dropshot::{ConfigDropshot, ConfigLogging, ConfigLoggingLevel}; -use omicron_common::api::ProducerEndpoint; +use omicron_common::api::internal::nexus::ProducerEndpoint; use oximeter::producer_server::{ ProducerServer, ProducerServerConfig, RegistrationInfo, }; diff --git a/oximeter/oximeter/src/oximeter_server.rs b/oximeter/oximeter/src/oximeter_server.rs index 4f86858d3cd..c51a869a932 100644 --- a/oximeter/oximeter/src/oximeter_server.rs +++ b/oximeter/oximeter/src/oximeter_server.rs @@ -12,7 +12,7 @@ use dropshot::{ HttpResponseUpdatedNoContent, HttpServer, HttpServerStarter, RequestContext, TypedBody, }; -use omicron_common::api::{OximeterInfo, ProducerEndpoint}; +use omicron_common::api::internal::nexus::{OximeterInfo, ProducerEndpoint}; use omicron_common::backoff; use reqwest::Client; use serde::{Deserialize, Serialize}; diff --git a/oximeter/oximeter/src/producer_server.rs b/oximeter/oximeter/src/producer_server.rs index 91561ede4b0..5c50a07827c 100644 --- a/oximeter/oximeter/src/producer_server.rs +++ b/oximeter/oximeter/src/producer_server.rs @@ -9,7 +9,7 @@ use dropshot::{ endpoint, ApiDescription, ConfigDropshot, ConfigLogging, HttpError, HttpResponseOk, HttpServer, HttpServerStarter, Path, RequestContext, }; -use omicron_common::api::ProducerEndpoint; +use omicron_common::api::internal::nexus::ProducerEndpoint; use reqwest::Client; use schemars::JsonSchema; use serde::{Deserialize, Serialize};