-
Notifications
You must be signed in to change notification settings - Fork 66
Open
Description
The code for deleting external subnets looks like this:
omicron/nexus/db-queries/src/db/datastore/external_subnet.rs
Lines 544 to 565 in 16c22eb
| pub async fn delete_external_subnet( | |
| &self, | |
| opctx: &OpContext, | |
| authz_subnet: &authz::ExternalSubnet, | |
| ) -> DeleteResult { | |
| opctx.authorize(authz::Action::Delete, authz_subnet).await?; | |
| let id = authz_subnet.id().into_untyped_uuid(); | |
| delete_external_subnet_query(&id) | |
| .execute_async(&*self.pool_connection_authorized(opctx).await?) | |
| .await | |
| .map_err(decode_delete_external_subnet_error) | |
| .and_then(|count| { | |
| if count == 0 { | |
| Err(Error::not_found_by_id( | |
| ResourceType::ExternalSubnet, | |
| &id, | |
| )) | |
| } else { | |
| Ok(()) | |
| } | |
| }) | |
| } |
That delegates to a custom query, which checks that the subnet isn't attached to an instance before deleting it. This is much more complicated than in needs to be. I forgot about the UpdateAndCheck trait we have for exactly this kind of conditional delete. The code is correct, but we should just use the standard mechanism.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels