openstack_sdk/api/compute/v2/server/create_232.rs
1// Licensed under the Apache License, Version 2.0 (the "License");
2// you may not use this file except in compliance with the License.
3// You may obtain a copy of the License at
4//
5// http://www.apache.org/licenses/LICENSE-2.0
6//
7// Unless required by applicable law or agreed to in writing, software
8// distributed under the License is distributed on an "AS IS" BASIS,
9// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10// See the License for the specific language governing permissions and
11// limitations under the License.
12//
13// SPDX-License-Identifier: Apache-2.0
14//
15// WARNING: This file is automatically generated from OpenAPI schema using
16// `openstack-codegenerator`.
17
18//! Creates a server.
19//!
20//! The progress of this operation depends on the location of the requested
21//! image, network I/O, host load, selected flavor, and other factors.
22//!
23//! To check the progress of the request, make a `GET /servers/{id}` request.
24//! This call returns a progress attribute, which is a percentage value from 0
25//! to 100.
26//!
27//! The `Location` header returns the full URL to the newly created server and
28//! is available as a `self` and `bookmark` link in the server representation.
29//!
30//! When you create a server, the response shows only the server ID, its links,
31//! and the admin password. You can get additional attributes through
32//! subsequent `GET` requests on the server.
33//!
34//! Include the `block_device_mapping_v2` parameter in the create request body
35//! to boot a server from a volume.
36//!
37//! Include the `key_name` parameter in the create request body to add a
38//! keypair to the server when you create it. To create a keypair, make a
39//! [create keypair](https://docs.openstack.org/api-ref/compute/#create-or-import-keypair)
40//! request.
41//!
42//! **Preconditions**
43//!
44//! **Asynchronous postconditions**
45//!
46//! **Troubleshooting**
47//!
48//! Normal response codes: 202
49//!
50//! Error response codes: badRequest(400), unauthorized(401), forbidden(403),
51//! itemNotFound(404), conflict(409)
52//!
53use derive_builder::Builder;
54use http::{HeaderMap, HeaderName, HeaderValue};
55
56use crate::api::rest_endpoint_prelude::*;
57
58use serde::Deserialize;
59use serde::Serialize;
60use serde_json::Value;
61use std::borrow::Cow;
62use std::collections::BTreeMap;
63
64#[derive(Builder, Debug, Deserialize, Clone, Serialize)]
65#[builder(setter(strip_option))]
66pub struct OsSchHntSchedulerHints<'a> {
67 /// Schedule the server on a host in the network specified with this
68 /// parameter and a cidr (`os:scheduler_hints.cidr`). It is available when
69 /// `SimpleCIDRAffinityFilter` is available on cloud side.
70 #[serde(skip_serializing_if = "Option::is_none")]
71 #[builder(default, setter(into))]
72 pub(crate) build_near_host_ip: Option<Cow<'a, str>>,
73
74 /// Schedule the server on a host in the network specified with an IP
75 /// address (`os:scheduler_hints:build_near_host_ip`) and this parameter.
76 /// If `os:scheduler_hints:build_near_host_ip` is specified and this
77 /// parameter is omitted, `/24` is used. It is available when
78 /// `SimpleCIDRAffinityFilter` is available on cloud side.
79 #[serde(skip_serializing_if = "Option::is_none")]
80 #[builder(default, setter(into))]
81 pub(crate) cidr: Option<Cow<'a, str>>,
82
83 /// A list of cell routes or a cell route (string). Schedule the server in
84 /// a cell that is not specified. It is available when
85 /// `DifferentCellFilter` is available on cloud side that is cell v1
86 /// environment.
87 #[serde(skip_serializing_if = "Option::is_none")]
88 #[builder(default, setter(into))]
89 pub(crate) different_cell: Option<Vec<Cow<'a, str>>>,
90
91 /// A list of server UUIDs or a server UUID. Schedule the server on a
92 /// different host from a set of servers. It is available when
93 /// `DifferentHostFilter` is available on cloud side.
94 #[serde(skip_serializing_if = "Option::is_none")]
95 #[builder(default, setter(into))]
96 pub(crate) different_host: Option<Vec<Cow<'a, str>>>,
97
98 /// The server group UUID. Schedule the server according to a policy of the
99 /// server group (`anti-affinity`, `affinity`, `soft-anti-affinity` or
100 /// `soft-affinity`). It is available when `ServerGroupAffinityFilter`,
101 /// `ServerGroupAntiAffinityFilter`, `ServerGroupSoftAntiAffinityWeigher`,
102 /// `ServerGroupSoftAffinityWeigher` are available on cloud side.
103 #[serde(skip_serializing_if = "Option::is_none")]
104 #[builder(default, setter(into))]
105 pub(crate) group: Option<Cow<'a, str>>,
106
107 /// Schedule the server by using a custom filter in JSON format. For
108 /// example:
109 ///
110 /// ```text
111 /// "query": "[\">=\",\"$free_ram_mb\",1024]"
112 /// ```
113 ///
114 /// It is available when `JsonFilter` is available on cloud side.
115 #[serde(skip_serializing_if = "Option::is_none")]
116 #[builder(default, setter(into))]
117 pub(crate) query: Option<Value>,
118
119 /// A list of server UUIDs or a server UUID. Schedule the server on the
120 /// same host as another server in a set of servers. It is available when
121 /// `SameHostFilter` is available on cloud side.
122 #[serde(skip_serializing_if = "Option::is_none")]
123 #[builder(default, setter(into))]
124 pub(crate) same_host: Option<Vec<Cow<'a, str>>>,
125
126 /// A target cell name. Schedule the server in a host in the cell
127 /// specified. It is available when `TargetCellFilter` is available on
128 /// cloud side that is cell v1 environment.
129 #[serde(skip_serializing_if = "Option::is_none")]
130 #[builder(default, setter(into))]
131 pub(crate) target_cell: Option<Cow<'a, str>>,
132
133 #[builder(setter(name = "_properties"), default, private)]
134 #[serde(flatten)]
135 _properties: BTreeMap<Cow<'a, str>, Value>,
136}
137
138impl<'a> OsSchHntSchedulerHintsBuilder<'a> {
139 pub fn properties<I, K, V>(&mut self, iter: I) -> &mut Self
140 where
141 I: Iterator<Item = (K, V)>,
142 K: Into<Cow<'a, str>>,
143 V: Into<Value>,
144 {
145 self._properties
146 .get_or_insert_with(BTreeMap::new)
147 .extend(iter.map(|(k, v)| (k.into(), v.into())));
148 self
149 }
150}
151
152/// The dictionary of data to send to the scheduler. Alternatively, you can
153/// specify `OS-SCH-HNT:scheduler_hints` as the key in the request body.
154///
155/// Note
156///
157/// This is a top-level key in the request body, not part of the server portion
158/// of the request body.
159///
160/// There are a few caveats with scheduler hints:
161///
162/// - The request validation schema is per hint. For example, some require a
163/// single string value, and some accept a list of values.
164/// - Hints are only used based on the cloud scheduler configuration, which
165/// varies per deployment.
166/// - Hints are pluggable per deployment, meaning that a cloud can have custom
167/// hints which may not be available in another cloud.
168///
169/// For these reasons, it is important to consult each cloud’s user
170/// documentation to know what is available for scheduler hints.
171#[derive(Builder, Debug, Deserialize, Clone, Serialize)]
172#[builder(setter(strip_option))]
173pub struct OsSchedulerHints<'a> {
174 /// Schedule the server on a host in the network specified with this
175 /// parameter and a cidr (`os:scheduler_hints.cidr`). It is available when
176 /// `SimpleCIDRAffinityFilter` is available on cloud side.
177 #[serde(skip_serializing_if = "Option::is_none")]
178 #[builder(default, setter(into))]
179 pub(crate) build_near_host_ip: Option<Cow<'a, str>>,
180
181 /// Schedule the server on a host in the network specified with an IP
182 /// address (`os:scheduler_hints:build_near_host_ip`) and this parameter.
183 /// If `os:scheduler_hints:build_near_host_ip` is specified and this
184 /// parameter is omitted, `/24` is used. It is available when
185 /// `SimpleCIDRAffinityFilter` is available on cloud side.
186 #[serde(skip_serializing_if = "Option::is_none")]
187 #[builder(default, setter(into))]
188 pub(crate) cidr: Option<Cow<'a, str>>,
189
190 /// A list of cell routes or a cell route (string). Schedule the server in
191 /// a cell that is not specified. It is available when
192 /// `DifferentCellFilter` is available on cloud side that is cell v1
193 /// environment.
194 #[serde(skip_serializing_if = "Option::is_none")]
195 #[builder(default, setter(into))]
196 pub(crate) different_cell: Option<Vec<Cow<'a, str>>>,
197
198 /// A list of server UUIDs or a server UUID. Schedule the server on a
199 /// different host from a set of servers. It is available when
200 /// `DifferentHostFilter` is available on cloud side.
201 #[serde(skip_serializing_if = "Option::is_none")]
202 #[builder(default, setter(into))]
203 pub(crate) different_host: Option<Vec<Cow<'a, str>>>,
204
205 /// The server group UUID. Schedule the server according to a policy of the
206 /// server group (`anti-affinity`, `affinity`, `soft-anti-affinity` or
207 /// `soft-affinity`). It is available when `ServerGroupAffinityFilter`,
208 /// `ServerGroupAntiAffinityFilter`, `ServerGroupSoftAntiAffinityWeigher`,
209 /// `ServerGroupSoftAffinityWeigher` are available on cloud side.
210 #[serde(skip_serializing_if = "Option::is_none")]
211 #[builder(default, setter(into))]
212 pub(crate) group: Option<Cow<'a, str>>,
213
214 /// Schedule the server by using a custom filter in JSON format. For
215 /// example:
216 ///
217 /// ```text
218 /// "query": "[\">=\",\"$free_ram_mb\",1024]"
219 /// ```
220 ///
221 /// It is available when `JsonFilter` is available on cloud side.
222 #[serde(skip_serializing_if = "Option::is_none")]
223 #[builder(default, setter(into))]
224 pub(crate) query: Option<Value>,
225
226 /// A list of server UUIDs or a server UUID. Schedule the server on the
227 /// same host as another server in a set of servers. It is available when
228 /// `SameHostFilter` is available on cloud side.
229 #[serde(skip_serializing_if = "Option::is_none")]
230 #[builder(default, setter(into))]
231 pub(crate) same_host: Option<Vec<Cow<'a, str>>>,
232
233 /// A target cell name. Schedule the server in a host in the cell
234 /// specified. It is available when `TargetCellFilter` is available on
235 /// cloud side that is cell v1 environment.
236 #[serde(skip_serializing_if = "Option::is_none")]
237 #[builder(default, setter(into))]
238 pub(crate) target_cell: Option<Cow<'a, str>>,
239
240 #[builder(setter(name = "_properties"), default, private)]
241 #[serde(flatten)]
242 _properties: BTreeMap<Cow<'a, str>, Value>,
243}
244
245impl<'a> OsSchedulerHintsBuilder<'a> {
246 pub fn properties<I, K, V>(&mut self, iter: I) -> &mut Self
247 where
248 I: Iterator<Item = (K, V)>,
249 K: Into<Cow<'a, str>>,
250 V: Into<Value>,
251 {
252 self._properties
253 .get_or_insert_with(BTreeMap::new)
254 .extend(iter.map(|(k, v)| (k.into(), v.into())));
255 self
256 }
257}
258
259#[derive(Debug, Deserialize, Clone, Serialize)]
260pub enum OsDcfDiskConfig {
261 #[serde(rename = "AUTO")]
262 Auto,
263 #[serde(rename = "MANUAL")]
264 Manual,
265}
266
267#[derive(Builder, Debug, Deserialize, Clone, Serialize)]
268#[builder(setter(strip_option))]
269pub struct BlockDeviceMapping<'a> {
270 #[serde(skip_serializing_if = "Option::is_none")]
271 #[builder(default, setter(into))]
272 pub(crate) connection_info: Option<Cow<'a, str>>,
273
274 /// Indicates whether a config drive enables metadata injection. The
275 /// config_drive setting provides information about a drive that the
276 /// instance can mount at boot time. The instance reads files from the
277 /// drive to get information that is normally available through the
278 /// metadata service. This metadata is different from the user data. Not
279 /// all cloud providers enable the `config_drive`. Read more in the
280 /// [OpenStack End User Guide](https://docs.openstack.org/nova/latest/user/config-drive.html).
281 #[serde(skip_serializing_if = "Option::is_none")]
282 #[builder(default, setter(into))]
283 pub(crate) delete_on_termination: Option<bool>,
284
285 #[serde(skip_serializing_if = "Option::is_none")]
286 #[builder(default, setter(into))]
287 pub(crate) device_name: Option<Cow<'a, str>>,
288
289 #[serde(skip_serializing_if = "Option::is_none")]
290 #[builder(default, setter(into))]
291 pub(crate) no_device: Option<Value>,
292
293 #[serde(skip_serializing_if = "Option::is_none")]
294 #[builder(default, setter(into))]
295 pub(crate) snapshot_id: Option<Cow<'a, str>>,
296
297 #[serde(skip_serializing_if = "Option::is_none")]
298 #[builder(default, setter(into))]
299 pub(crate) virtual_name: Option<Cow<'a, str>>,
300
301 #[serde(skip_serializing_if = "Option::is_none")]
302 #[builder(default, setter(into))]
303 pub(crate) volume_id: Option<Cow<'a, str>>,
304
305 #[serde(skip_serializing_if = "Option::is_none")]
306 #[builder(default, setter(into))]
307 pub(crate) volume_size: Option<i32>,
308}
309
310#[derive(Debug, Deserialize, Clone, Serialize)]
311pub enum DestinationType {
312 #[serde(rename = "local")]
313 Local,
314 #[serde(rename = "volume")]
315 Volume,
316}
317
318#[derive(Debug, Deserialize, Clone, Serialize)]
319pub enum SourceType {
320 #[serde(rename = "blank")]
321 Blank,
322 #[serde(rename = "image")]
323 Image,
324 #[serde(rename = "snapshot")]
325 Snapshot,
326 #[serde(rename = "volume")]
327 Volume,
328}
329
330#[derive(Builder, Debug, Deserialize, Clone, Serialize)]
331#[builder(setter(strip_option))]
332pub struct BlockDeviceMappingV2<'a> {
333 #[serde(skip_serializing_if = "Option::is_none")]
334 #[builder(default, setter(into))]
335 pub(crate) boot_index: Option<Option<Cow<'a, str>>>,
336
337 #[serde(skip_serializing_if = "Option::is_none")]
338 #[builder(default, setter(into))]
339 pub(crate) connection_info: Option<Cow<'a, str>>,
340
341 #[serde(skip_serializing_if = "Option::is_none")]
342 #[builder(default, setter(into))]
343 pub(crate) delete_on_termination: Option<bool>,
344
345 #[serde(skip_serializing_if = "Option::is_none")]
346 #[builder(default)]
347 pub(crate) destination_type: Option<DestinationType>,
348
349 #[serde(skip_serializing_if = "Option::is_none")]
350 #[builder(default, setter(into))]
351 pub(crate) device_name: Option<Cow<'a, str>>,
352
353 #[serde(skip_serializing_if = "Option::is_none")]
354 #[builder(default, setter(into))]
355 pub(crate) device_type: Option<Cow<'a, str>>,
356
357 #[serde(skip_serializing_if = "Option::is_none")]
358 #[builder(default, setter(into))]
359 pub(crate) disk_bus: Option<Cow<'a, str>>,
360
361 #[serde(skip_serializing_if = "Option::is_none")]
362 #[builder(default, setter(into))]
363 pub(crate) guest_format: Option<Cow<'a, str>>,
364
365 #[serde(skip_serializing_if = "Option::is_none")]
366 #[builder(default, setter(into))]
367 pub(crate) image_id: Option<Cow<'a, str>>,
368
369 #[serde(skip_serializing_if = "Option::is_none")]
370 #[builder(default, setter(into))]
371 pub(crate) no_device: Option<Value>,
372
373 #[serde(skip_serializing_if = "Option::is_none")]
374 #[builder(default, setter(into))]
375 pub(crate) snapshot_id: Option<Cow<'a, str>>,
376
377 #[serde(skip_serializing_if = "Option::is_none")]
378 #[builder(default)]
379 pub(crate) source_type: Option<SourceType>,
380
381 #[serde(skip_serializing_if = "Option::is_none")]
382 #[builder(default, setter(into))]
383 pub(crate) tag: Option<Cow<'a, str>>,
384
385 #[serde(skip_serializing_if = "Option::is_none")]
386 #[builder(default, setter(into))]
387 pub(crate) uuid: Option<Cow<'a, str>>,
388
389 #[serde(skip_serializing_if = "Option::is_none")]
390 #[builder(default, setter(into))]
391 pub(crate) virtual_name: Option<Cow<'a, str>>,
392
393 #[serde(skip_serializing_if = "Option::is_none")]
394 #[builder(default, setter(into))]
395 pub(crate) volume_id: Option<Cow<'a, str>>,
396
397 #[serde(skip_serializing_if = "Option::is_none")]
398 #[builder(default, setter(into))]
399 pub(crate) volume_size: Option<i32>,
400}
401
402#[derive(Builder, Debug, Deserialize, Clone, Serialize)]
403#[builder(setter(strip_option))]
404pub struct Networks<'a> {
405 /// Schedule the server on a host in the network specified with this
406 /// parameter and a cidr (`os:scheduler_hints.cidr`). It is available when
407 /// `SimpleCIDRAffinityFilter` is available on cloud side.
408 #[serde(skip_serializing_if = "Option::is_none")]
409 #[builder(default, setter(into))]
410 pub(crate) fixed_ip: Option<Cow<'a, str>>,
411
412 #[serde(skip_serializing_if = "Option::is_none")]
413 #[builder(default, setter(into))]
414 pub(crate) port: Option<Option<Cow<'a, str>>>,
415
416 #[serde(skip_serializing_if = "Option::is_none")]
417 #[builder(default, setter(into))]
418 pub(crate) tag: Option<Cow<'a, str>>,
419
420 #[serde(skip_serializing_if = "Option::is_none")]
421 #[builder(default, setter(into))]
422 pub(crate) uuid: Option<Cow<'a, str>>,
423}
424
425#[derive(Builder, Debug, Deserialize, Clone, Serialize)]
426#[builder(setter(strip_option))]
427pub struct Personality<'a> {
428 #[serde(skip_serializing_if = "Option::is_none")]
429 #[builder(default, setter(into))]
430 pub(crate) contents: Option<Cow<'a, str>>,
431
432 #[serde(skip_serializing_if = "Option::is_none")]
433 #[builder(default, setter(into))]
434 pub(crate) path: Option<Cow<'a, str>>,
435}
436
437#[derive(Builder, Debug, Deserialize, Clone, Serialize)]
438#[builder(setter(strip_option))]
439pub struct SecurityGroups<'a> {
440 /// A target cell name. Schedule the server in a host in the cell
441 /// specified. It is available when `TargetCellFilter` is available on
442 /// cloud side that is cell v1 environment.
443 #[serde(skip_serializing_if = "Option::is_none")]
444 #[builder(default, setter(into))]
445 pub(crate) name: Option<Cow<'a, str>>,
446}
447
448/// A `server` object.
449#[derive(Builder, Debug, Deserialize, Clone, Serialize)]
450#[builder(setter(strip_option))]
451pub struct Server<'a> {
452 /// IPv4 address that should be used to access this server.
453 #[serde(rename = "accessIPv4", skip_serializing_if = "Option::is_none")]
454 #[builder(default, setter(into))]
455 pub(crate) access_ipv4: Option<Cow<'a, str>>,
456
457 /// IPv6 address that should be used to access this server.
458 #[serde(rename = "accessIPv6", skip_serializing_if = "Option::is_none")]
459 #[builder(default, setter(into))]
460 pub(crate) access_ipv6: Option<Cow<'a, str>>,
461
462 /// The administrative password of the server. If you omit this parameter,
463 /// the operation generates a new password.
464 #[serde(rename = "adminPass", skip_serializing_if = "Option::is_none")]
465 #[builder(default, setter(into))]
466 pub(crate) admin_pass: Option<Cow<'a, str>>,
467
468 /// A target cell name. Schedule the server in a host in the cell
469 /// specified. It is available when `TargetCellFilter` is available on
470 /// cloud side that is cell v1 environment.
471 #[serde(skip_serializing_if = "Option::is_none")]
472 #[builder(default, setter(into))]
473 pub(crate) availability_zone: Option<Cow<'a, str>>,
474
475 #[serde(skip_serializing_if = "Option::is_none")]
476 #[builder(default, setter(into))]
477 pub(crate) block_device_mapping: Option<Vec<BlockDeviceMapping<'a>>>,
478
479 /// Enables fine grained control of the block device mapping for an
480 /// instance. This is typically used for booting servers from volumes. An
481 /// example format would look as follows:
482 ///
483 /// > ```text
484 /// > "block_device_mapping_v2": [{
485 /// > "boot_index": "0",
486 /// > "uuid": "ac408821-c95a-448f-9292-73986c790911",
487 /// > "source_type": "image",
488 /// > "volume_size": "25",
489 /// > "destination_type": "volume",
490 /// > "delete_on_termination": true,
491 /// > "tag": "disk1",
492 /// > "disk_bus": "scsi"}]
493 /// > ```
494 ///
495 /// In microversion 2.32, `tag` is an optional string attribute that can be
496 /// used to assign a tag to the block device. This tag is then exposed to
497 /// the guest in the metadata API and the config drive and is associated to
498 /// hardware metadata for that block device, such as bus (ex: SCSI), bus
499 /// address (ex: 1:0:2:0), and serial.
500 ///
501 /// A bug has caused the `tag` attribute to no longer be accepted starting
502 /// with version 2.33. It has been restored in version 2.42.
503 #[serde(skip_serializing_if = "Option::is_none")]
504 #[builder(default, setter(into))]
505 pub(crate) block_device_mapping_v2: Option<Vec<BlockDeviceMappingV2<'a>>>,
506
507 /// Indicates whether a config drive enables metadata injection. The
508 /// config_drive setting provides information about a drive that the
509 /// instance can mount at boot time. The instance reads files from the
510 /// drive to get information that is normally available through the
511 /// metadata service. This metadata is different from the user data. Not
512 /// all cloud providers enable the `config_drive`. Read more in the
513 /// [OpenStack End User Guide](https://docs.openstack.org/nova/latest/user/config-drive.html).
514 #[serde(skip_serializing_if = "Option::is_none")]
515 #[builder(default, setter(into))]
516 pub(crate) config_drive: Option<bool>,
517
518 /// A free form description of the server. Limited to 255 characters in
519 /// length. Before microversion 2.19 this was set to the server name.
520 ///
521 /// **New in version 2.19**
522 #[serde(skip_serializing_if = "Option::is_none")]
523 #[builder(default, setter(into))]
524 pub(crate) description: Option<Option<Cow<'a, str>>>,
525
526 /// The flavor reference, as an ID (including a UUID) or full URL, for the
527 /// flavor for your server instance.
528 #[serde(rename = "flavorRef")]
529 #[builder(setter(into))]
530 pub(crate) flavor_ref: Cow<'a, str>,
531
532 /// The UUID of the image to use for your server instance. This is not
533 /// required in case of boot from volume. In all other cases it is required
534 /// and must be a valid UUID otherwise API will return 400.
535 #[serde(rename = "imageRef", skip_serializing_if = "Option::is_none")]
536 #[builder(default, setter(into))]
537 pub(crate) image_ref: Option<Cow<'a, str>>,
538
539 /// A target cell name. Schedule the server in a host in the cell
540 /// specified. It is available when `TargetCellFilter` is available on
541 /// cloud side that is cell v1 environment.
542 #[serde(skip_serializing_if = "Option::is_none")]
543 #[builder(default, setter(into))]
544 pub(crate) key_name: Option<Cow<'a, str>>,
545
546 #[serde(skip_serializing_if = "Option::is_none")]
547 #[builder(default, setter(into))]
548 pub(crate) max_count: Option<i32>,
549
550 /// Metadata key and value pairs. The maximum size of the metadata key and
551 /// value is 255 bytes each.
552 #[serde(skip_serializing_if = "Option::is_none")]
553 #[builder(default, private, setter(into, name = "_metadata"))]
554 pub(crate) metadata: Option<BTreeMap<Cow<'a, str>, Cow<'a, str>>>,
555
556 #[serde(skip_serializing_if = "Option::is_none")]
557 #[builder(default, setter(into))]
558 pub(crate) min_count: Option<i32>,
559
560 /// A target cell name. Schedule the server in a host in the cell
561 /// specified. It is available when `TargetCellFilter` is available on
562 /// cloud side that is cell v1 environment.
563 #[serde()]
564 #[builder(setter(into))]
565 pub(crate) name: Cow<'a, str>,
566
567 /// A list of `network` object. Required parameter when there are multiple
568 /// networks defined for the tenant. When you do not specify the networks
569 /// parameter, the server attaches to the only network created for the
570 /// current tenant. Optionally, you can create one or more NICs on the
571 /// server. To provision the server instance with a NIC for a network,
572 /// specify the UUID of the network in the `uuid` attribute in a `networks`
573 /// object. To provision the server instance with a NIC for an already
574 /// existing port, specify the port-id in the `port` attribute in a
575 /// `networks` object.
576 ///
577 /// If multiple networks are defined, the order in which they appear in the
578 /// guest operating system will not necessarily reflect the order in which
579 /// they are given in the server boot request. Guests should therefore not
580 /// depend on device order to deduce any information about their network
581 /// devices. Instead, device role tags should be used: introduced in 2.32,
582 /// broken in 2.37, and re-introduced and fixed in 2.42, the `tag` is an
583 /// optional, string attribute that can be used to assign a tag to a
584 /// virtual network interface. This tag is then exposed to the guest in the
585 /// metadata API and the config drive and is associated to hardware
586 /// metadata for that network interface, such as bus (ex: PCI), bus address
587 /// (ex: 0000:00:02.0), and MAC address.
588 ///
589 /// A bug has caused the `tag` attribute to no longer be accepted starting
590 /// with version 2.37. Therefore, network interfaces could only be tagged
591 /// in versions 2.32 to 2.36 inclusively. Version 2.42 has restored the
592 /// `tag` attribute.
593 ///
594 /// Starting with microversion 2.37, this field is required and the special
595 /// string values *auto* and *none* can be specified for networks. *auto*
596 /// tells the Compute service to use a network that is available to the
597 /// project, if one exists. If one does not exist, the Compute service will
598 /// attempt to automatically allocate a network for the project (if
599 /// possible). *none* tells the Compute service to not allocate a network
600 /// for the instance. The *auto* and *none* values cannot be used with any
601 /// other network values, including other network uuids, ports, fixed IPs
602 /// or device tags. These are requested as strings for the networks value,
603 /// not in a list. See the associated example.
604 #[serde(skip_serializing_if = "Option::is_none")]
605 #[builder(default, setter(into))]
606 pub(crate) networks: Option<Vec<Networks<'a>>>,
607
608 /// Controls how the API partitions the disk when you create, rebuild, or
609 /// resize servers. A server inherits the `OS-DCF:diskConfig` value from
610 /// the image from which it was created, and an image inherits the
611 /// `OS-DCF:diskConfig` value from the server from which it was created. To
612 /// override the inherited setting, you can include this attribute in the
613 /// request body of a server create, rebuild, or resize request. If the
614 /// `OS-DCF:diskConfig` value for an image is `MANUAL`, you cannot create a
615 /// server from that image and set its `OS-DCF:diskConfig` value to `AUTO`.
616 /// A valid value is:
617 ///
618 /// - `AUTO`. The API builds the server with a single partition the size of
619 /// the target flavor disk. The API automatically adjusts the file system
620 /// to fit the entire partition.
621 /// - `MANUAL`. The API builds the server by using whatever partition
622 /// scheme and file system is in the source image. If the target flavor
623 /// disk is larger, the API does not partition the remaining disk space.
624 #[serde(rename = "OS-DCF:diskConfig", skip_serializing_if = "Option::is_none")]
625 #[builder(default)]
626 pub(crate) os_dcf_disk_config: Option<OsDcfDiskConfig>,
627
628 /// The file path and contents, text only, to inject into the server at
629 /// launch. The maximum size of the file path data is 255 bytes. The
630 /// maximum limit is the number of allowed bytes in the decoded, rather
631 /// than encoded, data.
632 ///
633 /// **Available until version 2.56**
634 #[serde(skip_serializing_if = "Option::is_none")]
635 #[builder(default, setter(into))]
636 pub(crate) personality: Option<Vec<Personality<'a>>>,
637
638 /// Indicates whether a config drive enables metadata injection. The
639 /// config_drive setting provides information about a drive that the
640 /// instance can mount at boot time. The instance reads files from the
641 /// drive to get information that is normally available through the
642 /// metadata service. This metadata is different from the user data. Not
643 /// all cloud providers enable the `config_drive`. Read more in the
644 /// [OpenStack End User Guide](https://docs.openstack.org/nova/latest/user/config-drive.html).
645 #[serde(skip_serializing_if = "Option::is_none")]
646 #[builder(default, setter(into))]
647 pub(crate) return_reservation_id: Option<bool>,
648
649 /// One or more security groups. Specify the name of the security group in
650 /// the `name` attribute. If you omit this attribute, the API creates the
651 /// server in the `default` security group. Requested security groups are
652 /// not applied to pre-existing ports.
653 #[serde(skip_serializing_if = "Option::is_none")]
654 #[builder(default, setter(into))]
655 pub(crate) security_groups: Option<Vec<SecurityGroups<'a>>>,
656
657 /// Configuration information or scripts to use upon launch. Must be Base64
658 /// encoded. Restricted to 65535 bytes.
659 ///
660 /// Note
661 ///
662 /// The `null` value allowed in Nova legacy v2 API, but due to the strict
663 /// input validation, it isn’t allowed in Nova v2.1 API.
664 #[serde(skip_serializing_if = "Option::is_none")]
665 #[builder(default, setter(into))]
666 pub(crate) user_data: Option<Cow<'a, str>>,
667}
668
669impl<'a> ServerBuilder<'a> {
670 /// Metadata key and value pairs. The maximum size of the metadata key and
671 /// value is 255 bytes each.
672 pub fn metadata<I, K, V>(&mut self, iter: I) -> &mut Self
673 where
674 I: Iterator<Item = (K, V)>,
675 K: Into<Cow<'a, str>>,
676 V: Into<Cow<'a, str>>,
677 {
678 self.metadata
679 .get_or_insert(None)
680 .get_or_insert_with(BTreeMap::new)
681 .extend(iter.map(|(k, v)| (k.into(), v.into())));
682 self
683 }
684}
685
686#[derive(Builder, Debug, Clone)]
687#[builder(setter(strip_option))]
688pub struct Request<'a> {
689 #[builder(default, setter(into))]
690 pub(crate) os_sch_hnt_scheduler_hints: Option<OsSchHntSchedulerHints<'a>>,
691
692 /// The dictionary of data to send to the scheduler. Alternatively, you can
693 /// specify `OS-SCH-HNT:scheduler_hints` as the key in the request body.
694 ///
695 /// Note
696 ///
697 /// This is a top-level key in the request body, not part of the server
698 /// portion of the request body.
699 ///
700 /// There are a few caveats with scheduler hints:
701 ///
702 /// - The request validation schema is per hint. For example, some require
703 /// a single string value, and some accept a list of values.
704 /// - Hints are only used based on the cloud scheduler configuration, which
705 /// varies per deployment.
706 /// - Hints are pluggable per deployment, meaning that a cloud can have
707 /// custom hints which may not be available in another cloud.
708 ///
709 /// For these reasons, it is important to consult each cloud’s user
710 /// documentation to know what is available for scheduler hints.
711 #[builder(default, setter(into))]
712 pub(crate) os_scheduler_hints: Option<OsSchedulerHints<'a>>,
713
714 /// A `server` object.
715 #[builder(setter(into))]
716 pub(crate) server: Server<'a>,
717
718 #[builder(setter(name = "_headers"), default, private)]
719 _headers: Option<HeaderMap>,
720}
721impl<'a> Request<'a> {
722 /// Create a builder for the endpoint.
723 pub fn builder() -> RequestBuilder<'a> {
724 RequestBuilder::default()
725 }
726}
727
728impl<'a> RequestBuilder<'a> {
729 /// Add a single header to the Server.
730 pub fn header<K, V>(&mut self, header_name: K, header_value: V) -> &mut Self
731 where
732 K: Into<HeaderName>,
733 V: Into<HeaderValue>,
734 {
735 self._headers
736 .get_or_insert(None)
737 .get_or_insert_with(HeaderMap::new)
738 .insert(header_name.into(), header_value.into());
739 self
740 }
741
742 /// Add multiple headers.
743 pub fn headers<I, T>(&mut self, iter: I) -> &mut Self
744 where
745 I: Iterator<Item = T>,
746 T: Into<(Option<HeaderName>, HeaderValue)>,
747 {
748 self._headers
749 .get_or_insert(None)
750 .get_or_insert_with(HeaderMap::new)
751 .extend(iter.map(Into::into));
752 self
753 }
754}
755
756impl RestEndpoint for Request<'_> {
757 fn method(&self) -> http::Method {
758 http::Method::POST
759 }
760
761 fn endpoint(&self) -> Cow<'static, str> {
762 "servers".to_string().into()
763 }
764
765 fn parameters(&self) -> QueryParams<'_> {
766 QueryParams::default()
767 }
768
769 fn body(&self) -> Result<Option<(&'static str, Vec<u8>)>, BodyError> {
770 let mut params = JsonBodyParams::default();
771
772 if let Some(val) = &self.os_sch_hnt_scheduler_hints {
773 params.push("OS-SCH-HNT:scheduler_hints", serde_json::to_value(val)?);
774 }
775 if let Some(val) = &self.os_scheduler_hints {
776 params.push("os:scheduler_hints", serde_json::to_value(val)?);
777 }
778 params.push("server", serde_json::to_value(&self.server)?);
779
780 params.into_body()
781 }
782
783 fn service_type(&self) -> ServiceType {
784 ServiceType::Compute
785 }
786
787 fn response_key(&self) -> Option<Cow<'static, str>> {
788 Some("server".into())
789 }
790
791 /// Returns headers to be set into the request
792 fn request_headers(&self) -> Option<&HeaderMap> {
793 self._headers.as_ref()
794 }
795
796 /// Returns required API version
797 fn api_version(&self) -> Option<ApiVersion> {
798 Some(ApiVersion::new(2, 32))
799 }
800}
801
802#[cfg(test)]
803mod tests {
804 use super::*;
805 #[cfg(feature = "sync")]
806 use crate::api::Query;
807 use crate::test::client::FakeOpenStackClient;
808 use crate::types::ServiceType;
809 use http::{HeaderName, HeaderValue};
810 use httpmock::MockServer;
811 use serde_json::json;
812
813 #[test]
814 fn test_service_type() {
815 assert_eq!(
816 Request::builder()
817 .server(
818 ServerBuilder::default()
819 .flavor_ref("foo")
820 .name("foo")
821 .build()
822 .unwrap()
823 )
824 .build()
825 .unwrap()
826 .service_type(),
827 ServiceType::Compute
828 );
829 }
830
831 #[test]
832 fn test_response_key() {
833 assert_eq!(
834 Request::builder()
835 .server(
836 ServerBuilder::default()
837 .flavor_ref("foo")
838 .name("foo")
839 .build()
840 .unwrap()
841 )
842 .build()
843 .unwrap()
844 .response_key()
845 .unwrap(),
846 "server"
847 );
848 }
849
850 #[cfg(feature = "sync")]
851 #[test]
852 fn endpoint() {
853 let server = MockServer::start();
854 let client = FakeOpenStackClient::new(server.base_url());
855 let mock = server.mock(|when, then| {
856 when.method(httpmock::Method::POST)
857 .path("/servers".to_string());
858
859 then.status(200)
860 .header("content-type", "application/json")
861 .json_body(json!({ "server": {} }));
862 });
863
864 let endpoint = Request::builder()
865 .server(
866 ServerBuilder::default()
867 .flavor_ref("foo")
868 .name("foo")
869 .build()
870 .unwrap(),
871 )
872 .build()
873 .unwrap();
874 let _: serde_json::Value = endpoint.query(&client).unwrap();
875 mock.assert();
876 }
877
878 #[cfg(feature = "sync")]
879 #[test]
880 fn endpoint_headers() {
881 let server = MockServer::start();
882 let client = FakeOpenStackClient::new(server.base_url());
883 let mock = server.mock(|when, then| {
884 when.method(httpmock::Method::POST)
885 .path("/servers".to_string())
886 .header("foo", "bar")
887 .header("not_foo", "not_bar");
888 then.status(200)
889 .header("content-type", "application/json")
890 .json_body(json!({ "server": {} }));
891 });
892
893 let endpoint = Request::builder()
894 .server(
895 ServerBuilder::default()
896 .flavor_ref("foo")
897 .name("foo")
898 .build()
899 .unwrap(),
900 )
901 .headers(
902 [(
903 Some(HeaderName::from_static("foo")),
904 HeaderValue::from_static("bar"),
905 )]
906 .into_iter(),
907 )
908 .header(
909 HeaderName::from_static("not_foo"),
910 HeaderValue::from_static("not_bar"),
911 )
912 .build()
913 .unwrap();
914 let _: serde_json::Value = endpoint.query(&client).unwrap();
915 mock.assert();
916 }
917}