Skip to content

Commit

Permalink
Change the shape of update nic to be valid PUT (#1288)
Browse files Browse the repository at this point in the history
* Change the shape of update nic to be valid PUT

* swap make_primary with primary in new datastore
  • Loading branch information
zephraph authored Aug 8, 2022
1 parent 63315ba commit 9d87b92
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 17 deletions.
6 changes: 3 additions & 3 deletions nexus/db-model/src/network_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,17 @@ pub struct NetworkInterfaceUpdate {
pub description: Option<String>,
pub time_modified: DateTime<Utc>,
#[diesel(column_name = is_primary)]
pub make_primary: Option<bool>,
pub primary: Option<bool>,
}

impl From<params::NetworkInterfaceUpdate> 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,
}
}
}
6 changes: 3 additions & 3 deletions nexus/src/db/datastore/network_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -307,7 +307,7 @@ impl DataStore {
type TxnError = TransactionError<NetworkInterfaceUpdateError>;

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;
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion nexus/tests/integration_tests/endpoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ lazy_static! {
name: None,
description: Some(String::from("an updated description")),
},
make_primary: false,
primary: false,
}
};
}
Expand Down
8 changes: 4 additions & 4 deletions nexus/tests/integration_tests/instances.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion nexus/types/src/external_api/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions openapi/nexus.json
Original file line number Diff line number Diff line change
Expand Up @@ -9393,18 +9393,18 @@
"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": [
{
"$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"
}
}
},
Expand Down

0 comments on commit 9d87b92

Please sign in to comment.