Skip to content

Commit 5ef07cf

Browse files
committed
wip
1 parent 041e406 commit 5ef07cf

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

nexus/db-model/src/instance.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,4 +537,9 @@ mod optional_time_delta {
537537
pub struct InstanceUpdate {
538538
#[diesel(column_name = boot_disk_id)]
539539
pub boot_disk_id: Option<Uuid>,
540+
541+
/// The auto-restart policy for this instance. If this is `None`, it will
542+
/// set the instance's auto-restart policy to `NULL`.
543+
#[diesel(column_name = auto_restart_policy)]
544+
pub auto_restart_policy: Option<InstanceAutoRestartPolicy>,
540545
}

nexus/src/app/sagas/instance_create.rs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ pub(crate) struct Params {
4444
pub create_params: params::InstanceCreate,
4545
pub boundary_switches: HashSet<SwitchLocation>,
4646
}
47-
4847
// Several nodes in this saga are wrapped in their own subsaga so that they can
4948
// have a parameter that denotes which node they are (e.g., which NIC or which
5049
// external IP). They also need the outer saga's parameters.
@@ -1077,8 +1076,12 @@ async fn sic_set_boot_disk(
10771076
.await
10781077
.map_err(ActionError::action_failed)?;
10791078

1080-
let initial_configuration =
1081-
nexus_db_model::InstanceUpdate { boot_disk_id: Some(authz_disk.id()) };
1079+
let initial_configuration = nexus_db_model::InstanceUpdate {
1080+
boot_disk_id: Some(authz_disk.id()),
1081+
// If this is `None`, whatever previous value was set when creating the
1082+
// instance will be unset and replaced with `NULL`. So don't do that!
1083+
auto_restart_policy: params.auto_restart_policy(),
1084+
};
10821085

10831086
datastore
10841087
.instance_reconfigure(&opctx, &authz_instance, initial_configuration)
@@ -1109,8 +1112,14 @@ async fn sic_set_boot_disk_undo(
11091112

11101113
// If there was a boot disk, clear it. If there was not a boot disk,
11111114
// this is a no-op.
1112-
let undo_configuration =
1113-
nexus_db_model::InstanceUpdate { boot_disk_id: None };
1115+
let undo_configuration = nexus_db_model::InstanceUpdate {
1116+
boot_disk_id: None,
1117+
// It would probably be fine to leave this as a `None` and clobber
1118+
// whatever's there with a NULL, since we are undoing the instance
1119+
// creation anyway, but it seems more proper to leave it untouched and
1120+
// only undo the boot disk configuration.
1121+
auto_restart_policy: params.auto_restart_policy(),
1122+
};
11141123

11151124
datastore
11161125
.instance_reconfigure(&opctx, &authz_instance, undo_configuration)
@@ -1157,6 +1166,15 @@ async fn sic_move_to_stopped(
11571166
Ok(())
11581167
}
11591168

1169+
impl Params {
1170+
/// Returns the desired auto-restart policy for the created instance, or
1171+
/// `None` if one was not specified.
1172+
fn auto_restart_policy(
1173+
&self,
1174+
) -> Option<db::model::InstanceAutoRestartPolicy> {
1175+
self.create_params.auto_restart_policy.map(Into::into)
1176+
}
1177+
}
11601178
#[cfg(test)]
11611179
pub mod test {
11621180
use crate::{

nexus/types/src/external_api/params.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,6 +1079,11 @@ pub struct InstanceUpdate {
10791079
///
10801080
/// If not provided, unset the instance's boot disk.
10811081
pub boot_disk: Option<NameOrId>,
1082+
1083+
/// The auto-restart policy for this instance.
1084+
///
1085+
/// If not provided, unset the instance's auto-restart policy.
1086+
pub auto_restart_policy: Option<InstanceAutoRestartPolicy>,
10821087
}
10831088

10841089
#[inline]

0 commit comments

Comments
 (0)