From e8981d529e9f3718173e84a141060e18fa24b8b1 Mon Sep 17 00:00:00 2001 From: James MacMahon Date: Mon, 21 Mar 2022 11:37:24 -0400 Subject: [PATCH] mock up saga step for creating disks during instance create --- nexus/src/sagas.rs | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/nexus/src/sagas.rs b/nexus/src/sagas.rs index 1191b6e466..64e5fab77a 100644 --- a/nexus/src/sagas.rs +++ b/nexus/src/sagas.rs @@ -194,6 +194,15 @@ pub fn saga_instance_create() -> SagaTemplate { new_action_noop_undo(sic_create_network_interfaces), ); + template_builder.append( + "create_disks", + "CreateDisksForInstance", + ActionFunc::new_action( + sic_create_disks_for_instance, + sic_create_disks_for_instance_undo, + ), + ); + template_builder.append( "attach_disks", "AttachDisksToInstance", @@ -488,6 +497,38 @@ async fn sic_create_network_interfaces_undo( Ok(()) } +/// Create disks during instance creation, and return a list of disk names +// TODO implement +async fn sic_create_disks_for_instance( + sagactx: ActionContext, +) -> Result, ActionError> { + let saga_params = sagactx.saga_params(); + let saga_disks = &saga_params.create_params.disks; + + for disk in saga_disks { + match disk { + params::InstanceDiskAttachment::Create(_create_params) => { + return Err(ActionError::action_failed( + "Creating disk during instance create unsupported!" + .to_string(), + )); + } + + _ => {} + } + } + + Ok(vec![]) +} + +/// Undo disks created during instance creation +// TODO implement +async fn sic_create_disks_for_instance_undo( + _sagactx: ActionContext, +) -> Result<(), anyhow::Error> { + Ok(()) +} + async fn sic_attach_disks_to_instance( sagactx: ActionContext, ) -> Result<(), ActionError> { @@ -519,7 +560,7 @@ async fn ensure_instance_disk_attach_state( for disk in saga_disks { match disk { params::InstanceDiskAttachment::Create(_) => { - todo!(); + // TODO grab disks created in sic_create_disks_for_instance } params::InstanceDiskAttachment::Attach(instance_disk_attach) => { let disk_name: db::model::Name =