From 9d87b9227aef91dd061d55455514de05c4acdbb7 Mon Sep 17 00:00:00 2001 From: Justin Bennett Date: Mon, 8 Aug 2022 15:17:42 -0400 Subject: [PATCH] Change the shape of update nic to be valid PUT (#1288) * Change the shape of update nic to be valid PUT * swap make_primary with primary in new datastore --- nexus/db-model/src/network_interface.rs | 6 +++--- nexus/src/db/datastore/network_interface.rs | 6 +++--- nexus/tests/integration_tests/endpoints.rs | 2 +- nexus/tests/integration_tests/instances.rs | 8 ++++---- nexus/types/src/external_api/params.rs | 2 +- openapi/nexus.json | 10 +++++----- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/nexus/db-model/src/network_interface.rs b/nexus/db-model/src/network_interface.rs index 5a135ccdf9..0538f00f85 100644 --- a/nexus/db-model/src/network_interface.rs +++ b/nexus/db-model/src/network_interface.rs @@ -85,17 +85,17 @@ pub struct NetworkInterfaceUpdate { pub description: Option, pub time_modified: DateTime, #[diesel(column_name = is_primary)] - pub make_primary: Option, + pub primary: Option, } impl From for NetworkInterfaceUpdate { fn from(params: params::NetworkInterfaceUpdate) -> Self { - let make_primary = if params.make_primary { Some(true) } else { None }; + let primary = if params.primary { Some(true) } else { None }; Self { name: params.identity.name.map(|n| n.into()), description: params.identity.description, time_modified: Utc::now(), - make_primary, + primary, } } } diff --git a/nexus/src/db/datastore/network_interface.rs b/nexus/src/db/datastore/network_interface.rs index e9cab811ba..b341cb612f 100644 --- a/nexus/src/db/datastore/network_interface.rs +++ b/nexus/src/db/datastore/network_interface.rs @@ -291,7 +291,7 @@ impl DataStore { db::model::InstanceState::new(external::InstanceState::Stopped); // This is the actual query to update the target interface. - let make_primary = matches!(updates.make_primary, Some(true)); + let primary = matches!(updates.primary, Some(true)); let update_target_query = diesel::update(dsl::network_interface) .filter(dsl::id.eq(interface_id)) .filter(dsl::time_deleted.is_null()) @@ -307,7 +307,7 @@ impl DataStore { type TxnError = TransactionError; let pool = self.pool_authorized(opctx).await?; - if make_primary { + if primary { pool.transaction(move |conn| { let instance_state = instance_query.get_result(conn)?.runtime_state.state; @@ -342,7 +342,7 @@ impl DataStore { }) } else { // In this case, we can just directly apply the updates. By - // construction, `updates.make_primary` is `None`, so nothing will + // construction, `updates.primary` is `None`, so nothing will // be done there. The other columns always need to be updated, and // we're only hitting a single row. Note that we still need to // verify the instance is stopped. diff --git a/nexus/tests/integration_tests/endpoints.rs b/nexus/tests/integration_tests/endpoints.rs index 397ead044e..08a2e17100 100644 --- a/nexus/tests/integration_tests/endpoints.rs +++ b/nexus/tests/integration_tests/endpoints.rs @@ -250,7 +250,7 @@ lazy_static! { name: None, description: Some(String::from("an updated description")), }, - make_primary: false, + primary: false, } }; } diff --git a/nexus/tests/integration_tests/instances.rs b/nexus/tests/integration_tests/instances.rs index 79b0ad51ec..d575dd9fb7 100644 --- a/nexus/tests/integration_tests/instances.rs +++ b/nexus/tests/integration_tests/instances.rs @@ -1280,7 +1280,7 @@ async fn test_instance_update_network_interfaces( name: Some(new_name.clone()), description: Some(new_description.clone()), }, - make_primary: false, + primary: false, }; // Verify we fail to update the NIC when the instance is running @@ -1351,13 +1351,13 @@ async fn test_instance_update_network_interfaces( verify_unchanged_attributes(&primary_iface, &updated_primary_iface); // Try with the same request again, but this time only changing - // `make_primary`. This should have no effect. + // `primary`. This should have no effect. let updates = params::NetworkInterfaceUpdate { identity: IdentityMetadataUpdateParams { name: None, description: None, }, - make_primary: true, + primary: true, }; let updated_primary_iface1 = NexusRequest::object_put( client, @@ -1454,7 +1454,7 @@ async fn test_instance_update_network_interfaces( name: None, description: None, }, - make_primary: true, + primary: true, }; let new_primary_iface = NexusRequest::object_put( client, diff --git a/nexus/types/src/external_api/params.rs b/nexus/types/src/external_api/params.rs index 6d8f312e5a..705bb8404e 100644 --- a/nexus/types/src/external_api/params.rs +++ b/nexus/types/src/external_api/params.rs @@ -325,7 +325,7 @@ pub struct NetworkInterfaceUpdate { // change in the primary interface will result in changes to the DNS records // for the instance, though not the name. #[serde(default)] - pub make_primary: bool, + pub primary: bool, } // IP POOLS diff --git a/openapi/nexus.json b/openapi/nexus.json index 39c4b21899..e1c11b0673 100644 --- a/openapi/nexus.json +++ b/openapi/nexus.json @@ -9393,11 +9393,6 @@ "nullable": true, "type": "string" }, - "make_primary": { - "description": "Make a secondary interface the instance's primary interface.\n\nIf applied to a secondary interface, that interface will become the primary on the next reboot of the instance. Note that this may have implications for routing between instances, as the new primary interface will be on a distinct subnet from the previous primary interface.\n\nNote that this can only be used to select a new primary interface for an instance. Requests to change the primary interface into a secondary will return an error.", - "default": false, - "type": "boolean" - }, "name": { "nullable": true, "allOf": [ @@ -9405,6 +9400,11 @@ "$ref": "#/components/schemas/Name" } ] + }, + "primary": { + "description": "Make a secondary interface the instance's primary interface.\n\nIf applied to a secondary interface, that interface will become the primary on the next reboot of the instance. Note that this may have implications for routing between instances, as the new primary interface will be on a distinct subnet from the previous primary interface.\n\nNote that this can only be used to select a new primary interface for an instance. Requests to change the primary interface into a secondary will return an error.", + "default": false, + "type": "boolean" } } },