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

[nexus] Add stubs for image APIs #749

Merged
merged 7 commits into from
Apr 4, 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
24 changes: 24 additions & 0 deletions common/src/sql/dbinit.sql
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,30 @@ CREATE INDEX ON omicron.public.disk (
) WHERE
time_deleted IS NULL AND attach_instance_id IS NOT NULL;

CREATE TABLE omicron.public.image (
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RFD 4 mentions the following fields which are not yet stored here (nor a part of the API):

  • version
  • digest
  • status

/* Identity metadata (resource) */
id UUID PRIMARY KEY,
name STRING(63) NOT NULL,
description STRING(512) NOT NULL,
time_created TIMESTAMPTZ NOT NULL,
time_modified TIMESTAMPTZ NOT NULL,
/* Indicates that the object has been deleted */
time_deleted TIMESTAMPTZ,

/* Optional project UUID: Images may or may not be global */
project_id UUID,
/* Optional volume ID: Images may exist without backing volumes */
volume_id UUID,
/* Optional URL: Images may be backed by either a URL or a volume */
url STRING(8192),
size_bytes INT NOT NULL
);

CREATE UNIQUE INDEX on omicron.public.image (
project_id,
name
) WHERE
time_deleted is NULL;

CREATE TABLE omicron.public.snapshot (
/* Identity metadata (resource) */
Expand Down
35 changes: 34 additions & 1 deletion nexus/src/db/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use crate::db::collection_insert::DatastoreCollection;
use crate::db::identity::{Asset, Resource};
use crate::db::schema::{
console_session, dataset, disk, instance, metric_producer,
console_session, dataset, disk, image, instance, metric_producer,
network_interface, organization, oximeter, project, rack, region,
role_assignment_builtin, role_builtin, router_route, silo, silo_user, sled,
snapshot, update_available_artifact, user_builtin, volume, vpc,
Expand Down Expand Up @@ -1505,6 +1505,39 @@ impl Into<external::DiskState> for DiskState {
}
}

#[derive(
Queryable,
Insertable,
Selectable,
Clone,
Debug,
Resource,
Serialize,
Deserialize,
)]
#[table_name = "image"]
pub struct Image {
#[diesel(embed)]
identity: ImageIdentity,

project_id: Option<Uuid>,
volume_id: Option<Uuid>,
url: Option<String>,
#[column_name = "size_bytes"]
size: ByteCount,
}

impl From<Image> for views::Image {
fn from(image: Image) -> Self {
Self {
identity: image.identity(),
project_id: image.project_id,
url: image.url,
size: image.size.into(),
}
}
}

#[derive(
Queryable,
Insertable,
Expand Down
15 changes: 15 additions & 0 deletions nexus/src/db/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,21 @@ table! {
}
}

table! {
image (id) {
id -> Uuid,
name -> Text,
description -> Text,
time_created -> Timestamptz,
time_modified -> Timestamptz,
time_deleted -> Nullable<Timestamptz>,
project_id -> Nullable<Uuid>,
volume_id -> Uuid,
url -> Text,
size_bytes -> Int8,
}
}

table! {
snapshot (id) {
id -> Uuid,
Expand Down
Loading