-
Notifications
You must be signed in to change notification settings - Fork 62
RFD-322 -- /v1/ Disks API
#2008
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
Changes from all commits
233dc6d
0be1778
6e3210f
a2681b9
18bc9cf
07ec450
5b2f217
8631e9f
41672aa
954ffdb
c8d191b
6708bac
26b5651
f70f84f
e6374fe
cdaa977
d0a19c6
f439f59
b4e818a
7bdfeb0
cf5f540
8c7ce21
87f4d25
1596ed2
393283d
ae73d95
3d69694
57549c7
2a87558
0b227b0
8f64dd7
df8f5bf
548a4d0
78962c2
ce7da01
2092012
96165f5
e616c03
3c13edc
67ebcd8
f26c18a
12bc365
9b75d90
c94d0d9
31cc6b1
a59c346
39fcf37
9a4c6da
9187fcc
9c74e88
ff14b9b
afbda07
eb9335d
1784353
69c7dcb
1033683
9dbfed6
8d51dbb
129011e
c29c67d
599e6eb
114d39a
6ae7da3
63eddd7
8db8fa2
c14cf71
3a68689
143b1b7
33f09b5
bd1fafe
f949c6c
bd033a0
b1e1cde
8eb8fca
ae4ddcd
69ac008
1176211
81d58ae
4065a3a
3e88bbc
d5e6c42
30f83fd
e02cd60
ded1119
4e602d2
8f79dc6
2f75756
5c2366d
8ca6b35
898002d
072c389
7f608d1
2b9369a
f357742
178e86c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ use crate::authn; | |
| use crate::authz; | ||
| use crate::context::OpContext; | ||
| use crate::db; | ||
| use crate::db::lookup; | ||
| use crate::db::lookup::LookupPath; | ||
| use crate::db::model::Name; | ||
| use crate::external_api::params; | ||
|
|
@@ -20,26 +21,58 @@ use omicron_common::api::external::Error; | |
| use omicron_common::api::external::InternalContext; | ||
| use omicron_common::api::external::ListResultVec; | ||
| use omicron_common::api::external::LookupResult; | ||
| use omicron_common::api::external::NameOrId; | ||
| use omicron_common::api::internal::nexus::DiskRuntimeState; | ||
| use ref_cast::RefCast; | ||
| use sled_agent_client::Client as SledAgentClient; | ||
| use std::sync::Arc; | ||
| use uuid::Uuid; | ||
|
|
||
| impl super::Nexus { | ||
| // Disks | ||
| pub fn disk_lookup<'a>( | ||
| &'a self, | ||
| opctx: &'a OpContext, | ||
| disk_selector: &'a params::DiskSelector, | ||
| ) -> LookupResult<lookup::Disk<'a>> { | ||
| match disk_selector { | ||
| params::DiskSelector { | ||
| disk: NameOrId::Id(id), | ||
| project_selector: None, | ||
| } => { | ||
| let disk = | ||
| LookupPath::new(opctx, &self.db_datastore).disk_id(*id); | ||
| Ok(disk) | ||
| } | ||
| params::DiskSelector { | ||
| disk: NameOrId::Name(name), | ||
| project_selector: Some(project_selector), | ||
| } => { | ||
| let disk = self | ||
| .project_lookup(opctx, project_selector)? | ||
| .disk_name(Name::ref_cast(name)); | ||
| Ok(disk) | ||
| } | ||
| params::DiskSelector { | ||
| disk: NameOrId::Id(_), | ||
| project_selector: Some(_), | ||
| } => Err(Error::invalid_request( | ||
| "when providing disk as an ID, project should not be specified", | ||
| )), | ||
| _ => Err(Error::invalid_request( | ||
| "disk should either be UUID or project should be specified", | ||
| )), | ||
| } | ||
| } | ||
|
|
||
| pub async fn project_create_disk( | ||
| self: &Arc<Self>, | ||
| opctx: &OpContext, | ||
| organization_name: &Name, | ||
| project_name: &Name, | ||
| project_lookup: &lookup::Project<'_>, | ||
| params: ¶ms::DiskCreate, | ||
| ) -> CreateResult<db::model::Disk> { | ||
| let (.., authz_project) = LookupPath::new(opctx, &self.db_datastore) | ||
| .organization_name(organization_name) | ||
| .project_name(project_name) | ||
| .lookup_for(authz::Action::CreateChild) | ||
| .await?; | ||
| let (.., authz_project) = | ||
| project_lookup.lookup_for(authz::Action::CreateChild).await?; | ||
|
|
||
| match ¶ms.disk_source { | ||
| params::DiskSource::Blank { block_size } => { | ||
|
|
@@ -225,49 +258,30 @@ impl super::Nexus { | |
| Ok(disk_created) | ||
| } | ||
|
|
||
| pub async fn project_list_disks( | ||
| pub async fn project_list_disks_by_id( | ||
| &self, | ||
| opctx: &OpContext, | ||
| organization_name: &Name, | ||
| project_name: &Name, | ||
| pagparams: &DataPageParams<'_, Name>, | ||
| project_lookup: &lookup::Project<'_>, | ||
| pagparams: &DataPageParams<'_, Uuid>, | ||
| ) -> ListResultVec<db::model::Disk> { | ||
| let (.., authz_project) = LookupPath::new(opctx, &self.db_datastore) | ||
| .organization_name(organization_name) | ||
| .project_name(project_name) | ||
| .lookup_for(authz::Action::ListChildren) | ||
| .await?; | ||
| let (.., authz_project) = | ||
| project_lookup.lookup_for(authz::Action::ListChildren).await?; | ||
| self.db_datastore | ||
| .project_list_disks(opctx, &authz_project, pagparams) | ||
| .project_list_disks_by_id(opctx, &authz_project, pagparams) | ||
| .await | ||
| } | ||
|
|
||
| pub async fn disk_fetch( | ||
| &self, | ||
| opctx: &OpContext, | ||
| organization_name: &Name, | ||
| project_name: &Name, | ||
| disk_name: &Name, | ||
| ) -> LookupResult<db::model::Disk> { | ||
| let (.., db_disk) = LookupPath::new(opctx, &self.db_datastore) | ||
| .organization_name(organization_name) | ||
| .project_name(project_name) | ||
| .disk_name(disk_name) | ||
| .fetch() | ||
| .await?; | ||
| Ok(db_disk) | ||
| } | ||
|
|
||
| pub async fn disk_fetch_by_id( | ||
| pub async fn project_list_disks_by_name( | ||
| &self, | ||
| opctx: &OpContext, | ||
| disk_id: &Uuid, | ||
| ) -> LookupResult<db::model::Disk> { | ||
| let (.., db_disk) = LookupPath::new(opctx, &self.db_datastore) | ||
| .disk_id(*disk_id) | ||
| .fetch() | ||
| .await?; | ||
| Ok(db_disk) | ||
| project_lookup: &lookup::Project<'_>, | ||
| pagparams: &DataPageParams<'_, Name>, | ||
| ) -> ListResultVec<db::model::Disk> { | ||
| let (.., authz_project) = | ||
| project_lookup.lookup_for(authz::Action::ListChildren).await?; | ||
| self.db_datastore | ||
| .project_list_disks_by_name(opctx, &authz_project, pagparams) | ||
| .await | ||
| } | ||
|
|
||
| /// Modifies the runtime state of the Disk as requested. This generally | ||
|
|
@@ -372,17 +386,10 @@ impl super::Nexus { | |
|
|
||
| pub async fn project_delete_disk( | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit and kind of a general comment: these used to be called
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've added a note in the parent issue to tackle this as a follow up. |
||
| self: &Arc<Self>, | ||
| opctx: &OpContext, | ||
| organization_name: &Name, | ||
| project_name: &Name, | ||
| disk_name: &Name, | ||
| disk_lookup: &lookup::Disk<'_>, | ||
| ) -> DeleteResult { | ||
| let (.., authz_disk) = LookupPath::new(opctx, &self.db_datastore) | ||
| .organization_name(organization_name) | ||
| .project_name(project_name) | ||
| .disk_name(disk_name) | ||
| .lookup_for(authz::Action::Delete) | ||
| .await?; | ||
| let (.., authz_disk) = | ||
| disk_lookup.lookup_for(authz::Action::Delete).await?; | ||
|
|
||
| let saga_params = | ||
| sagas::disk_delete::Params { disk_id: authz_disk.id() }; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just wondering, how much work will be involved to change
project_lookupto work without organizations?Should the implementation change much? If so, how much effort would including organization in the lookup now and removing it almost immediately after take?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It shouldn't be too much work. It's fairly formulaic.