Skip to content

Commit 549f8ce

Browse files
committed
add disk create or attach params to InstanceCreate
1 parent 0f8c2ae commit 549f8ce

File tree

6 files changed

+101
-0
lines changed

6 files changed

+101
-0
lines changed

nexus/src/external_api/params.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,22 @@ impl Default for InstanceNetworkInterfaceAttachment {
125125
}
126126
}
127127

128+
/// Describe the instance's disks at creation time
129+
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
130+
#[serde(tag = "type")]
131+
pub enum InstanceDiskAttachment {
132+
/// During instance creation, create and attach disks
133+
Create(DiskCreate),
134+
135+
/// During instance creation, attach this disk
136+
Attach(InstanceDiskAttach),
137+
}
138+
139+
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema, Default)]
140+
pub struct InstanceDiskAttach {
141+
disks: Vec<Uuid>,
142+
}
143+
128144
/**
129145
* Create-time parameters for an [`Instance`](omicron_common::api::external::Instance)
130146
*/
@@ -139,6 +155,10 @@ pub struct InstanceCreate {
139155
/// The network interfaces to be created for this instance.
140156
#[serde(default)]
141157
pub network_interfaces: InstanceNetworkInterfaceAttachment,
158+
159+
/// The disks to be created or attached for this instance.
160+
#[serde(default)]
161+
pub disks: Vec<InstanceDiskAttachment>,
142162
}
143163

144164
/**

nexus/test-utils/src/resource_helpers.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ pub async fn create_instance(
143143
hostname: String::from("the_host"),
144144
network_interfaces:
145145
params::InstanceNetworkInterfaceAttachment::Default,
146+
disks: vec![],
146147
},
147148
)
148149
.await

nexus/tests/integration_tests/instances.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ async fn test_instances_create_reboot_halt(
146146
hostname: instance.hostname.clone(),
147147
network_interfaces:
148148
params::InstanceNetworkInterfaceAttachment::Default,
149+
disks: vec![],
149150
}))
150151
.expect_status(Some(StatusCode::BAD_REQUEST)),
151152
)
@@ -577,6 +578,7 @@ async fn test_instance_with_single_explicit_ip_address(
577578
memory: ByteCount::from_mebibytes_u32(4),
578579
hostname: String::from("nic-test"),
579580
network_interfaces: interface_params,
581+
disks: vec![],
580582
};
581583
let response =
582584
NexusRequest::objects_post(client, &url_instances, &instance_params)
@@ -692,6 +694,7 @@ async fn test_instance_with_new_custom_network_interfaces(
692694
memory: ByteCount::from_mebibytes_u32(4),
693695
hostname: String::from("nic-test"),
694696
network_interfaces: interface_params,
697+
disks: vec![],
695698
};
696699
let response =
697700
NexusRequest::objects_post(client, &url_instances, &instance_params)
@@ -784,6 +787,7 @@ async fn test_instance_create_delete_network_interface(
784787
memory: ByteCount::from_mebibytes_u32(4),
785788
hostname: String::from("nic-test"),
786789
network_interfaces: params::InstanceNetworkInterfaceAttachment::None,
790+
disks: vec![],
787791
};
788792
let response =
789793
NexusRequest::objects_post(client, &url_instances, &instance_params)
@@ -966,6 +970,7 @@ async fn test_instance_with_multiple_nics_unwinds_completely(
966970
memory: ByteCount::from_mebibytes_u32(4),
967971
hostname: String::from("nic-test"),
968972
network_interfaces: interface_params,
973+
disks: vec![],
969974
};
970975
let builder =
971976
RequestBuilder::new(client, http::Method::POST, &url_instances)

nexus/tests/integration_tests/subnet_allocation.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ async fn create_instance_expect_failure(
4242
memory: ByteCount::from_mebibytes_u32(256),
4343
hostname: name.to_string(),
4444
network_interfaces: params::InstanceNetworkInterfaceAttachment::Default,
45+
disks: vec![],
4546
};
4647

4748
NexusRequest::new(

nexus/tests/integration_tests/unauthorized.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ lazy_static! {
234234
memory: ByteCount::from_gibibytes_u32(16),
235235
hostname: String::from("demo-instance"),
236236
network_interfaces: params::InstanceNetworkInterfaceAttachment::Default,
237+
disks: vec![],
237238
};
238239
}
239240

openapi/nexus.json

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4333,6 +4333,13 @@
43334333
"description": {
43344334
"type": "string"
43354335
},
4336+
"disks": {
4337+
"description": "The disks to be created or attached for this instance.",
4338+
"type": "array",
4339+
"items": {
4340+
"$ref": "#/components/schemas/InstanceDiskAttachment"
4341+
}
4342+
},
43364343
"hostname": {
43374344
"type": "string"
43384345
},
@@ -4362,6 +4369,72 @@
43624369
"ncpus"
43634370
]
43644371
},
4372+
"InstanceDiskAttachment": {
4373+
"description": "Describe the instance's disks at creation time",
4374+
"oneOf": [
4375+
{
4376+
"description": "During instance creation, create and attach disks",
4377+
"type": "object",
4378+
"properties": {
4379+
"description": {
4380+
"type": "string"
4381+
},
4382+
"name": {
4383+
"$ref": "#/components/schemas/Name"
4384+
},
4385+
"size": {
4386+
"description": "size of the Disk",
4387+
"allOf": [
4388+
{
4389+
"$ref": "#/components/schemas/ByteCount"
4390+
}
4391+
]
4392+
},
4393+
"snapshot_id": {
4394+
"nullable": true,
4395+
"description": "id for snapshot from which the Disk should be created, if any",
4396+
"type": "string",
4397+
"format": "uuid"
4398+
},
4399+
"type": {
4400+
"type": "string",
4401+
"enum": [
4402+
"Create"
4403+
]
4404+
}
4405+
},
4406+
"required": [
4407+
"description",
4408+
"name",
4409+
"size",
4410+
"type"
4411+
]
4412+
},
4413+
{
4414+
"description": "During instance creation, attach this disk",
4415+
"type": "object",
4416+
"properties": {
4417+
"disks": {
4418+
"type": "array",
4419+
"items": {
4420+
"type": "string",
4421+
"format": "uuid"
4422+
}
4423+
},
4424+
"type": {
4425+
"type": "string",
4426+
"enum": [
4427+
"Attach"
4428+
]
4429+
}
4430+
},
4431+
"required": [
4432+
"disks",
4433+
"type"
4434+
]
4435+
}
4436+
]
4437+
},
43654438
"InstanceMigrate": {
43664439
"description": "Migration parameters for an [`Instance`](omicron_common::api::external::Instance)",
43674440
"type": "object",

0 commit comments

Comments
 (0)