Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkw committed Oct 1, 2024
1 parent f14b561 commit c90f617
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
5 changes: 5 additions & 0 deletions nexus/db-model/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -534,4 +534,9 @@ mod optional_time_delta {
pub struct InstanceUpdate {
#[diesel(column_name = boot_disk_id)]
pub boot_disk_id: Option<Uuid>,

/// The auto-restart policy for this instance. If this is `None`, it will
/// set the instance's auto-restart policy to `NULL`.
#[diesel(column_name = auto_restart_policy)]
pub auto_restart_policy: Option<InstanceAutoRestartPolicy>,
}
28 changes: 23 additions & 5 deletions nexus/src/app/sagas/instance_create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ pub(crate) struct Params {
pub create_params: params::InstanceCreate,
pub boundary_switches: HashSet<SwitchLocation>,
}

// Several nodes in this saga are wrapped in their own subsaga so that they can
// have a parameter that denotes which node they are (e.g., which NIC or which
// external IP). They also need the outer saga's parameters.
Expand Down Expand Up @@ -1077,8 +1076,12 @@ 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::InstanceUpdate {
boot_disk_id: Some(authz_disk.id()),
// If this is `None`, whatever previous value was set when creating the
// instance will be unset and replaced with `NULL`. So don't do that!
auto_restart_policy: params.auto_restart_policy(),
};

datastore
.instance_reconfigure(&opctx, &authz_instance, initial_configuration)
Expand Down Expand Up @@ -1109,8 +1112,14 @@ 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.
let undo_configuration =
nexus_db_model::InstanceUpdate { boot_disk_id: None };
let undo_configuration = nexus_db_model::InstanceUpdate {
boot_disk_id: None,
// It would probably be fine to leave this as a `None` and clobber
// whatever's there with a NULL, since we are undoing the instance
// creation anyway, but it seems more proper to leave it untouched and
// only undo the boot disk configuration.
auto_restart_policy: params.auto_restart_policy(),
};

datastore
.instance_reconfigure(&opctx, &authz_instance, undo_configuration)
Expand Down Expand Up @@ -1157,6 +1166,15 @@ async fn sic_move_to_stopped(
Ok(())
}

impl Params {
/// Returns the desired auto-restart policy for the created instance, or
/// `None` if one was not specified.
fn auto_restart_policy(
&self,
) -> Option<db::model::InstanceAutoRestartPolicy> {
self.create_params.auto_restart_policy.map(Into::into)
}
}
#[cfg(test)]
pub mod test {
use crate::{
Expand Down
5 changes: 5 additions & 0 deletions nexus/types/src/external_api/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,11 @@ pub struct InstanceUpdate {
///
/// If not provided, unset the instance's boot disk.
pub boot_disk: Option<NameOrId>,

/// The auto-restart policy for this instance.
///
/// If not provided, unset the instance's auto-restart policy.
pub auto_restart_policy: Option<InstanceAutoRestartPolicy>,
}

#[inline]
Expand Down

0 comments on commit c90f617

Please sign in to comment.