Skip to content

Commit c52827d

Browse files
authored
[nexus] allow reconfiguring auto-restart policies (#6743)
This commit extends the `instance-reconfigure` API endpoint added in #6585 to also allow setting instance auto-restart policies (as added in #6503). I've also added the actual auto-restart policy to the external API instance view, along with the boolean `auto_restart_enabled` added in #6503. This way, it's possible to change just the boot disk by providing the current auto-restart policy in an instance POST.
1 parent aa7b087 commit c52827d

File tree

10 files changed

+490
-231
lines changed

10 files changed

+490
-231
lines changed

common/src/api/external/mod.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1215,6 +1215,20 @@ pub struct InstanceAutoRestartStatus {
12151215
#[serde(rename = "auto_restart_enabled")]
12161216
pub enabled: bool,
12171217

1218+
/// The auto-restart policy configured for this instance, or `None` if no
1219+
/// explicit policy is configured.
1220+
///
1221+
/// If this is not present, then this instance uses the default auto-restart
1222+
/// policy, which may or may not allow it to be restarted. The
1223+
/// `auto_restart_enabled` field indicates whether the instance will be
1224+
/// automatically restarted.
1225+
//
1226+
// Rename this field, as the struct is `#[serde(flatten)]`ed into the
1227+
// `Instance` type, and we would like the field to be prefixed with
1228+
// `auto_restart`.
1229+
#[serde(rename = "auto_restart_policy")]
1230+
pub policy: Option<InstanceAutoRestartPolicy>,
1231+
12181232
/// The time at which the auto-restart cooldown period for this instance
12191233
/// completes, permitting it to be automatically restarted again. If the
12201234
/// instance enters the `Failed` state, it will not be restarted until after
@@ -1233,7 +1247,9 @@ pub struct InstanceAutoRestartStatus {
12331247

12341248
/// A policy determining when an instance should be automatically restarted by
12351249
/// the control plane.
1236-
#[derive(Copy, Clone, Debug, Deserialize, Serialize, JsonSchema)]
1250+
#[derive(
1251+
Copy, Clone, Debug, Deserialize, Serialize, JsonSchema, Eq, PartialEq,
1252+
)]
12371253
#[serde(rename_all = "snake_case")]
12381254
pub enum InstanceAutoRestartPolicy {
12391255
/// The instance should not be automatically restarted by the control plane

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
}

0 commit comments

Comments
 (0)