Skip to content

Commit

Permalink
Internal cleanup for boot disk/instance update
Browse files Browse the repository at this point in the history
Greg and Eliza were both right in comments on #6585, but since these are
both fully internal I didn't want to add another CI round trip there :)
  • Loading branch information
iximeow committed Oct 1, 2024
1 parent f14b561 commit 265068b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
11 changes: 10 additions & 1 deletion nexus/db-model/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -529,9 +529,18 @@ mod optional_time_delta {
}

/// The parts of an Instance that can be directly updated after creation.
///
/// The model's name `InstanceReconfigure` is in contrast to the external
/// [`params::InstanceUpdate`]: `reconfigure` is the internal name of changing
/// an instance's configuration in places it might conflict with the phrase
/// "instance update". If we rename `instance update` (see
/// https://github.com/oxidecomputer/omicron/issues/6631), then this could
/// reasonably be renamed `InstanceUpdate` like other update models, with its
/// user `instance_reconfigure` also renamed to `instance_update` like other
/// update queries.
#[derive(Clone, Debug, AsChangeset, Serialize, Deserialize)]
#[diesel(table_name = instance, treat_none_as_null = true)]
pub struct InstanceUpdate {
pub struct InstanceReconfigure {
#[diesel(column_name = boot_disk_id)]
pub boot_disk_id: Option<Uuid>,
}
4 changes: 2 additions & 2 deletions nexus/db-queries/src/db/datastore/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ use crate::db::model::Generation;
use crate::db::model::Instance;
use crate::db::model::InstanceAutoRestart;
use crate::db::model::InstanceAutoRestartPolicy;
use crate::db::model::InstanceReconfigure;
use crate::db::model::InstanceRuntimeState;
use crate::db::model::InstanceState;
use crate::db::model::InstanceUpdate;
use crate::db::model::Migration;
use crate::db::model::MigrationState;
use crate::db::model::Name;
Expand Down Expand Up @@ -1009,7 +1009,7 @@ impl DataStore {
&self,
opctx: &OpContext,
authz_instance: &authz::Instance,
update: InstanceUpdate,
update: InstanceReconfigure,
) -> Result<InstanceAndActiveVmm, Error> {
opctx.authorize(authz::Action::Modify, authz_instance).await?;

Expand Down
4 changes: 2 additions & 2 deletions nexus/src/app/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::external_api::params;
use cancel_safe_futures::prelude::*;
use futures::future::Fuse;
use futures::{FutureExt, SinkExt, StreamExt};
use nexus_db_model::InstanceUpdate;
use nexus_db_model::InstanceReconfigure;
use nexus_db_model::IpAttachState;
use nexus_db_model::IpKind;
use nexus_db_model::Vmm as DbVmm;
Expand Down Expand Up @@ -330,7 +330,7 @@ impl super::Nexus {
None => None,
};

let update = InstanceUpdate { boot_disk_id };
let update = InstanceReconfigure { boot_disk_id };
self.datastore()
.instance_reconfigure(opctx, &authz_instance, update)
.await
Expand Down
11 changes: 8 additions & 3 deletions nexus/src/app/sagas/instance_create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1077,8 +1077,9 @@ async fn sic_set_boot_disk(
.await
.map_err(ActionError::action_failed)?;

let initial_configuration =
nexus_db_model::InstanceUpdate { boot_disk_id: Some(authz_disk.id()) };
let initial_configuration = nexus_db_model::InstanceReconfigure {
boot_disk_id: Some(authz_disk.id()),
};

datastore
.instance_reconfigure(&opctx, &authz_instance, initial_configuration)
Expand Down Expand Up @@ -1109,8 +1110,12 @@ async fn sic_set_boot_disk_undo(

// If there was a boot disk, clear it. If there was not a boot disk,
// this is a no-op.
if params.create_params.boot_disk.is_none() {
return Ok(());
}

let undo_configuration =
nexus_db_model::InstanceUpdate { boot_disk_id: None };
nexus_db_model::InstanceReconfigure { boot_disk_id: None };

datastore
.instance_reconfigure(&opctx, &authz_instance, undo_configuration)
Expand Down

0 comments on commit 265068b

Please sign in to comment.