Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

supply real volume data to propolis #771

Merged
merged 18 commits into from
Mar 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
289 changes: 258 additions & 31 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions common/src/api/external/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,12 @@ impl<T: ClientError> From<progenitor::progenitor_client::Error<T>> for Error {
}
}

impl From<serde_json::Error> for Error {
fn from(e: serde_json::Error) -> Self {
Error::internal_error(&e.to_string())
}
}

/// Like [`assert!`], except that instead of panicking, this function returns an
/// `Err(Error::InternalError)` with an appropriate message if the given
/// condition is not true.
Expand Down
3 changes: 2 additions & 1 deletion nexus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ path = "../rpaths"
anyhow = "1.0"
async-bb8-diesel = { git = "https://github.com/oxidecomputer/async-bb8-diesel", rev = "c849b717be" }
async-trait = "0.1.51"
base64 = "0.13.0"
bb8 = "0.7.1"
cookie = "0.16"
crucible-agent-client = { git = "https://github.com/oxidecomputer/crucible", rev = "3e7e49eeb88fa8ad74375b0642aabd4224b1f2cb" }
crucible-agent-client = { git = "https://github.com/oxidecomputer/crucible", rev = "945daedb88cefa790f1d994b3a038b8fa9ac514a" }
# Tracking pending 2.0 version.
diesel = { git = "https://github.com/diesel-rs/diesel", rev = "ce77c382", features = ["postgres", "r2d2", "chrono", "serde_json", "network-address", "uuid"] }
futures = "0.3.21"
Expand Down
40 changes: 38 additions & 2 deletions nexus/src/db/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,11 @@ impl Sled {

pub fn address(&self) -> SocketAddr {
// TODO: avoid this unwrap
SocketAddr::new(self.ip.ip(), u16::try_from(self.port).unwrap())
self.address_with_port(u16::try_from(self.port).unwrap())
}

pub fn address_with_port(&self, port: u16) -> SocketAddr {
SocketAddr::new(self.ip.ip(), port)
}
}

Expand Down Expand Up @@ -787,7 +791,11 @@ impl Dataset {

pub fn address(&self) -> SocketAddr {
// TODO: avoid this unwrap
SocketAddr::new(self.ip.ip(), u16::try_from(self.port).unwrap())
self.address_with_port(u16::try_from(self.port).unwrap())
}

pub fn address_with_port(&self, port: u16) -> SocketAddr {
SocketAddr::new(self.ip.ip(), port)
}
}

Expand Down Expand Up @@ -905,6 +913,10 @@ impl Volume {
data,
}
}

pub fn data(&self) -> &str {
&self.data
}
}

/// Describes an organization within the database.
Expand Down Expand Up @@ -1266,6 +1278,10 @@ impl Disk {
pub fn runtime(&self) -> DiskRuntimeState {
self.runtime_state.clone()
}

pub fn id(&self) -> Uuid {
self.identity.id
}
}

/// Conversion to the external API type.
Expand Down Expand Up @@ -1319,6 +1335,17 @@ impl DiskRuntimeState {
}
}

pub fn attach(self, instance_id: Uuid) -> Self {
Self {
disk_state: external::DiskState::Attached(instance_id)
.label()
.to_string(),
attach_instance_id: Some(instance_id),
gen: self.gen.next().into(),
time_updated: Utc::now(),
}
}

pub fn detach(self) -> Self {
Self {
disk_state: external::DiskState::Detached.label().to_string(),
Expand All @@ -1339,6 +1366,15 @@ impl DiskRuntimeState {
.unwrap(),
)
}

pub fn faulted(self) -> Self {
Self {
disk_state: external::DiskState::Faulted.label().to_string(),
attach_instance_id: None,
gen: self.gen.next().into(),
time_updated: Utc::now(),
}
}
}

/// Conversion from the internal API type.
Expand Down
21 changes: 21 additions & 0 deletions nexus/src/external_api/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,23 @@ impl Default for InstanceNetworkInterfaceAttachment {
}
}

/// Describe the instance's disks at creation time
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum InstanceDiskAttachment {
/// During instance creation, create and attach disks
Create(DiskCreate),

/// During instance creation, attach this disk
Attach(InstanceDiskAttach),
}

#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
pub struct InstanceDiskAttach {
/// A disk name to attach
pub disk: Name,
}

/// Create-time parameters for an [`Instance`](omicron_common::api::external::Instance)
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
pub struct InstanceCreate {
Expand All @@ -117,6 +134,10 @@ pub struct InstanceCreate {
/// The network interfaces to be created for this instance.
#[serde(default)]
pub network_interfaces: InstanceNetworkInterfaceAttachment,

/// The disks to be created or attached for this instance.
#[serde(default)]
pub disks: Vec<InstanceDiskAttachment>,
}

/// Migration parameters for an [`Instance`](omicron_common::api::external::Instance)
Expand Down
1 change: 1 addition & 0 deletions nexus/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
#![feature(async_closure)]

//! Library interface to the Nexus, the heart of the control plane

Expand Down
Loading