| 1 |
#!/usr/bin/python |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
# Copyright: (c) 2021, Ansible Project |
| 4 |
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 5 |
# template: header.j2 |
| 6 |
# This module is autogenerated using the ansible.content_builder. |
| 7 |
# See: https://github.com/ansible-community/ansible.content_builder |
| 8 |
|
| 9 |
|
| 10 |
DOCUMENTATION = r""" |
| 11 |
module: vcenter_vm |
| 12 |
short_description: Creates a virtual machine. |
| 13 |
description: Creates a virtual machine. |
| 14 |
deprecated: |
| 15 |
removed_in: 5.0.0 |
| 16 |
why: This module has been moved to the L(new vmware.vmware collection,https://forum.ansible.com/t/5880) |
| 17 |
alternative: Use M(vmware.vmware.vm) instead. |
| 18 |
options: |
| 19 |
bios_uuid: |
| 20 |
description: |
| 21 |
- 128-bit SMBIOS UUID of a virtual machine represented as a hexadecimal string |
| 22 |
in "12345678-abcd-1234-cdef-123456789abc" format. |
| 23 |
- If unset, will be generated. |
| 24 |
type: str |
| 25 |
boot: |
| 26 |
description: |
| 27 |
- Boot configuration. |
| 28 |
- If unset, guest-specific default values will be used. |
| 29 |
- 'Valid attributes are:' |
| 30 |
- ' - C(type) (str): This option defines the valid firmware types for a virtual |
| 31 |
machine. ([''present''])' |
| 32 |
- ' - Accepted values:' |
| 33 |
- ' - BIOS' |
| 34 |
- ' - EFI' |
| 35 |
- ' - C(efi_legacy_boot) (bool): Flag indicating whether to use EFI legacy |
| 36 |
boot mode.' |
| 37 |
- If unset, defaults to value that is recommended for the guest OS and is |
| 38 |
supported for the virtual hardware version. (['present']) |
| 39 |
- ' - C(network_protocol) (str): This option defines the valid network boot |
| 40 |
protocols supported when booting a virtual machine with EFI firmware over |
| 41 |
the network. ([''present''])' |
| 42 |
- ' - Accepted values:' |
| 43 |
- ' - IPV4' |
| 44 |
- ' - IPV6' |
| 45 |
- ' - C(delay) (int): Delay in milliseconds before beginning the firmware |
| 46 |
boot process when the virtual machine is powered on. This delay may be |
| 47 |
used to provide a time window for users to connect to the virtual machine |
| 48 |
console and enter BIOS setup mode.' |
| 49 |
- If unset, default value is 0. (['present']) |
| 50 |
- ' - C(retry) (bool): Flag indicating whether the virtual machine should |
| 51 |
automatically retry the boot process after a failure.' |
| 52 |
- If unset, default value is false. (['present']) |
| 53 |
- ' - C(retry_delay) (int): Delay in milliseconds before retrying the boot |
| 54 |
process after a failure; applicable only when I(retry) is true.' |
| 55 |
- If unset, default value is 10000. (['present']) |
| 56 |
- ' - C(enter_setup_mode) (bool): Flag indicating whether the firmware boot |
| 57 |
process should automatically enter setup mode the next time the virtual |
| 58 |
machine boots. Note that this flag will automatically be reset to false |
| 59 |
once the virtual machine enters setup mode.' |
| 60 |
- If unset, the value is unchanged. (['present']) |
| 61 |
type: dict |
| 62 |
boot_devices: |
| 63 |
description: |
| 64 |
- Boot device configuration. |
| 65 |
- If unset, a server-specific boot sequence will be used. |
| 66 |
- 'Valid attributes are:' |
| 67 |
- ' - C(type) (str): This option defines the valid device types that may be |
| 68 |
used as bootable devices. ([''present''])' |
| 69 |
- ' This key is required with [''present''].' |
| 70 |
- ' - Accepted values:' |
| 71 |
- ' - CDROM' |
| 72 |
- ' - DISK' |
| 73 |
- ' - ETHERNET' |
| 74 |
- ' - FLOPPY' |
| 75 |
elements: dict |
| 76 |
type: list |
| 77 |
cdroms: |
| 78 |
description: |
| 79 |
- List of CD-ROMs. |
| 80 |
- If unset, no CD-ROM devices will be created. |
| 81 |
- 'Valid attributes are:' |
| 82 |
- ' - C(type) (str): This option defines the valid types of host bus adapters |
| 83 |
that may be used for attaching a Cdrom to a virtual machine. ([''present''])' |
| 84 |
- ' - Accepted values:' |
| 85 |
- ' - IDE' |
| 86 |
- ' - SATA' |
| 87 |
- ' - C(ide) (dict): Address for attaching the device to a virtual IDE adapter.' |
| 88 |
- If unset, the server will choose an available address; if none is available, |
| 89 |
the request will fail. (['present']) |
| 90 |
- ' - Accepted keys:' |
| 91 |
- ' - primary (boolean): Flag specifying whether the device should be |
| 92 |
attached to the primary or secondary IDE adapter of the virtual machine.' |
| 93 |
- If unset, the server will choose a adapter with an available connection. |
| 94 |
If no IDE connections are available, the request will be rejected. |
| 95 |
- ' - master (boolean): Flag specifying whether the device should be the |
| 96 |
master or slave device on the IDE adapter.' |
| 97 |
- If unset, the server will choose an available connection type. If no IDE |
| 98 |
connections are available, the request will be rejected. |
| 99 |
- ' - C(sata) (dict): Address for attaching the device to a virtual SATA adapter.' |
| 100 |
- If unset, the server will choose an available address; if none is available, |
| 101 |
the request will fail. (['present']) |
| 102 |
- ' - Accepted keys:' |
| 103 |
- ' - bus (integer): Bus number of the adapter to which the device should |
| 104 |
be attached.' |
| 105 |
- ' - unit (integer): Unit number of the device.' |
| 106 |
- If unset, the server will choose an available unit number on the specified |
| 107 |
adapter. If there are no available connections on the adapter, the request |
| 108 |
will be rejected. |
| 109 |
- ' - C(backing) (dict): Physical resource backing for the virtual CD-ROM |
| 110 |
device.' |
| 111 |
- If unset, defaults to automatic detection of a suitable host device. (['present']) |
| 112 |
- ' - Accepted keys:' |
| 113 |
- ' - type (string): This option defines the valid backing types for a |
| 114 |
virtual CD-ROM device.' |
| 115 |
- 'Accepted value for this field:' |
| 116 |
- ' - C(CLIENT_DEVICE)' |
| 117 |
- ' - C(HOST_DEVICE)' |
| 118 |
- ' - C(ISO_FILE)' |
| 119 |
- ' - iso_file (string): Path of the image file that should be used as |
| 120 |
the virtual CD-ROM device backing.' |
| 121 |
- This field is optional and it is only relevant when the value of I(type) |
| 122 |
is ISO_FILE. |
| 123 |
- ' - host_device (string): Name of the device that should be used as |
| 124 |
the virtual CD-ROM device backing.' |
| 125 |
- If unset, the virtual CD-ROM device will be configured to automatically |
| 126 |
detect a suitable host device. |
| 127 |
- ' - device_access_type (string): This option defines the valid device |
| 128 |
access types for a physical device packing of a virtual CD-ROM device.' |
| 129 |
- 'Accepted value for this field:' |
| 130 |
- ' - C(EMULATION)' |
| 131 |
- ' - C(PASSTHRU)' |
| 132 |
- ' - C(PASSTHRU_EXCLUSIVE)' |
| 133 |
- ' - C(start_connected) (bool): Flag indicating whether the virtual device |
| 134 |
should be connected whenever the virtual machine is powered on.' |
| 135 |
- Defaults to false if unset. (['present']) |
| 136 |
- ' - C(allow_guest_control) (bool): Flag indicating whether the guest can |
| 137 |
connect and disconnect the device.' |
| 138 |
- Defaults to false if unset. (['present']) |
| 139 |
elements: dict |
| 140 |
type: list |
| 141 |
cpu: |
| 142 |
description: |
| 143 |
- CPU configuration. |
| 144 |
- If unset, guest-specific default values will be used. |
| 145 |
- 'Valid attributes are:' |
| 146 |
- ' - C(count) (int): New number of CPU cores. The number of CPU cores in |
| 147 |
the virtual machine must be a multiple of the number of cores per socket. ' |
| 148 |
- ' The supported range of CPU counts is constrained by the configured guest |
| 149 |
operating system and virtual hardware version of the virtual machine. ' |
| 150 |
- '' |
| 151 |
- ' If the virtual machine is running, the number of CPU cores may only be |
| 152 |
increased if I(hot_add_enabled) is true, and may only be decreased if |
| 153 |
I(hot_remove_enabled) is true.' |
| 154 |
- '' |
| 155 |
- If unset, the value is unchanged. (['present']) |
| 156 |
- ' - C(cores_per_socket) (int): New number of CPU cores per socket. The number |
| 157 |
of CPU cores in the virtual machine must be a multiple of the number of |
| 158 |
cores per socket.' |
| 159 |
- If unset, the value is unchanged. (['present']) |
| 160 |
- ' - C(hot_add_enabled) (bool): Flag indicating whether adding CPUs while |
| 161 |
the virtual machine is running is enabled. ' |
| 162 |
- ' This field may only be modified if the virtual machine is powered off.' |
| 163 |
- '' |
| 164 |
- If unset, the value is unchanged. (['present']) |
| 165 |
- ' - C(hot_remove_enabled) (bool): Flag indicating whether removing CPUs |
| 166 |
while the virtual machine is running is enabled. ' |
| 167 |
- ' This field may only be modified if the virtual machine is powered off.' |
| 168 |
- '' |
| 169 |
- If unset, the value is unchanged. (['present']) |
| 170 |
type: dict |
| 171 |
datastore: |
| 172 |
description: |
| 173 |
- Identifier of the datastore on which the virtual machine's configuration |
| 174 |
state is stored. |
| 175 |
- If unset, I(path) must also be unset and I(datastore_path) must be set. |
| 176 |
- 'When clients pass a value of this structure as a parameter, the field must |
| 177 |
be the id of a resource returned by M(vmware.vmware_rest.vcenter_datastore_info). ' |
| 178 |
type: str |
| 179 |
datastore_path: |
| 180 |
description: |
| 181 |
- Datastore path for the virtual machine's configuration file in the format |
| 182 |
"[datastore name] path". For example "[storage1] Test-VM/Test-VM.vmx". |
| 183 |
- If unset, both I(datastore) and I(path) must be set. |
| 184 |
type: str |
| 185 |
disconnect_all_nics: |
| 186 |
description: |
| 187 |
- Indicates whether all NICs on the destination virtual machine should be |
| 188 |
disconnected from the newtwork |
| 189 |
- If unset, connection status of all NICs on the destination virtual machine |
| 190 |
will be the same as on the source virtual machine. |
| 191 |
type: bool |
| 192 |
disks: |
| 193 |
description: |
| 194 |
- Individual disk relocation map. |
| 195 |
- If unset, all disks will migrate to the datastore specified in the I(datastore) |
| 196 |
field of I() |
| 197 |
- 'When clients pass a value of this structure as a parameter, the key in |
| 198 |
the field map must be the id of a resource returned by M(vmware.vmware_rest.vcenter_vm_hardware_disk). ' |
| 199 |
- 'Valid attributes are:' |
| 200 |
- ' - C(type) (str): This option defines the valid types of host bus adapters |
| 201 |
that may be used for attaching a virtual storage device to a virtual machine. |
| 202 |
([''present''])' |
| 203 |
- ' - Accepted values:' |
| 204 |
- ' - IDE' |
| 205 |
- ' - NVME' |
| 206 |
- ' - SATA' |
| 207 |
- ' - SCSI' |
| 208 |
- ' - C(ide) (dict): Address for attaching the device to a virtual IDE adapter.' |
| 209 |
- If unset, the server will choose an available address; if none is available, |
| 210 |
the request will fail. (['present']) |
| 211 |
- ' - Accepted keys:' |
| 212 |
- ' - primary (boolean): Flag specifying whether the device should be |
| 213 |
attached to the primary or secondary IDE adapter of the virtual machine.' |
| 214 |
- If unset, the server will choose a adapter with an available connection. |
| 215 |
If no IDE connections are available, the request will be rejected. |
| 216 |
- ' - master (boolean): Flag specifying whether the device should be the |
| 217 |
master or slave device on the IDE adapter.' |
| 218 |
- If unset, the server will choose an available connection type. If no IDE |
| 219 |
connections are available, the request will be rejected. |
| 220 |
- ' - C(scsi) (dict): Address for attaching the device to a virtual SCSI adapter.' |
| 221 |
- If unset, the server will choose an available address; if none is available, |
| 222 |
the request will fail. (['present']) |
| 223 |
- ' - Accepted keys:' |
| 224 |
- ' - bus (integer): Bus number of the adapter to which the device should |
| 225 |
be attached.' |
| 226 |
- ' - unit (integer): Unit number of the device.' |
| 227 |
- If unset, the server will choose an available unit number on the specified |
| 228 |
adapter. If there are no available connections on the adapter, the request |
| 229 |
will be rejected. |
| 230 |
- ' - C(sata) (dict): Address for attaching the device to a virtual SATA adapter.' |
| 231 |
- If unset, the server will choose an available address; if none is available, |
| 232 |
the request will fail. (['present']) |
| 233 |
- ' - Accepted keys:' |
| 234 |
- ' - bus (integer): Bus number of the adapter to which the device should |
| 235 |
be attached.' |
| 236 |
- ' - unit (integer): Unit number of the device.' |
| 237 |
- If unset, the server will choose an available unit number on the specified |
| 238 |
adapter. If there are no available connections on the adapter, the request |
| 239 |
will be rejected. |
| 240 |
- ' - C(nvme) (dict): Address for attaching the device to a virtual NVMe adapter.' |
| 241 |
- If unset, the server will choose an available address; if none is available, |
| 242 |
the request will fail. (['present']) |
| 243 |
- ' - Accepted keys:' |
| 244 |
- ' - bus (integer): Bus number of the adapter to which the device should |
| 245 |
be attached.' |
| 246 |
- ' - unit (integer): Unit number of the device.' |
| 247 |
- If unset, the server will choose an available unit number on the specified |
| 248 |
adapter. If there are no available connections on the adapter, the request |
| 249 |
will be rejected. |
| 250 |
- ' - C(backing) (dict): Existing physical resource backing for the virtual |
| 251 |
disk. Exactly one of I(backing) or I(new_vmdk) must be specified.' |
| 252 |
- If unset, the virtual disk will not be connected to an existing backing. |
| 253 |
(['present']) |
| 254 |
- ' - Accepted keys:' |
| 255 |
- ' - type (string): This option defines the valid backing types for a |
| 256 |
virtual disk.' |
| 257 |
- 'Accepted value for this field:' |
| 258 |
- ' - C(VMDK_FILE)' |
| 259 |
- ' - vmdk_file (string): Path of the VMDK file backing the virtual disk.' |
| 260 |
- This field is optional and it is only relevant when the value of I(type) |
| 261 |
is VMDK_FILE. |
| 262 |
- ' - C(new_vmdk) (dict): Specification for creating a new VMDK backing for |
| 263 |
the virtual disk. Exactly one of I(backing) or I(new_vmdk) must be specified.' |
| 264 |
- If unset, a new VMDK backing will not be created. (['present']) |
| 265 |
- ' - Accepted keys:' |
| 266 |
- ' - name (string): Base name of the VMDK file. The name should not include |
| 267 |
the ''.vmdk'' file extension.' |
| 268 |
- If unset, a name (derived from the name of the virtual machine) will be |
| 269 |
chosen by the server. |
| 270 |
- ' - capacity (integer): Capacity of the virtual disk backing in bytes.' |
| 271 |
- If unset, defaults to a guest-specific capacity. |
| 272 |
- ' - storage_policy (object): The I(storage_policy_spec) structure contains |
| 273 |
information about the storage policy that is to be associated the with |
| 274 |
VMDK file.' |
| 275 |
- 'If unset the default storage policy of the target datastore (if applicable) |
| 276 |
is applied. Currently a default storage policy is only supported by object |
| 277 |
based datastores : VVol & vSAN. For non- object datastores, if unset then |
| 278 |
no storage policy would be associated with the VMDK file.' |
| 279 |
elements: dict |
| 280 |
type: list |
| 281 |
disks_to_remove: |
| 282 |
description: |
| 283 |
- Set of Disks to Remove. |
| 284 |
- If unset, all disks will be copied. If the same identifier is in I(disks_to_update) |
| 285 |
InvalidArgument fault will be returned. |
| 286 |
- When clients pass a value of this structure as a parameter, the field must |
| 287 |
contain the id of resources returned by M(vmware.vmware_rest.vcenter_vm_hardware_disk). |
| 288 |
elements: str |
| 289 |
type: list |
| 290 |
disks_to_update: |
| 291 |
description: |
| 292 |
- Map of Disks to Update. |
| 293 |
- If unset, all disks will copied to the datastore specified in the I(datastore) |
| 294 |
field of I() If the same identifier is in I(disks_to_remove) InvalidArgument |
| 295 |
fault will be thrown. |
| 296 |
- 'When clients pass a value of this structure as a parameter, the key in |
| 297 |
the field map must be the id of a resource returned by M(vmware.vmware_rest.vcenter_vm_hardware_disk). ' |
| 298 |
type: dict |
| 299 |
floppies: |
| 300 |
description: |
| 301 |
- List of floppy drives. |
| 302 |
- If unset, no floppy drives will be created. |
| 303 |
- 'Valid attributes are:' |
| 304 |
- ' - C(backing) (dict): Physical resource backing for the virtual floppy |
| 305 |
drive.' |
| 306 |
- If unset, defaults to automatic detection of a suitable host device. (['present']) |
| 307 |
- ' - Accepted keys:' |
| 308 |
- ' - type (string): This option defines the valid backing types for a |
| 309 |
virtual floppy drive.' |
| 310 |
- 'Accepted value for this field:' |
| 311 |
- ' - C(CLIENT_DEVICE)' |
| 312 |
- ' - C(HOST_DEVICE)' |
| 313 |
- ' - C(IMAGE_FILE)' |
| 314 |
- ' - image_file (string): Path of the image file that should be used |
| 315 |
as the virtual floppy drive backing.' |
| 316 |
- This field is optional and it is only relevant when the value of I(type) |
| 317 |
is IMAGE_FILE. |
| 318 |
- ' - host_device (string): Name of the device that should be used as |
| 319 |
the virtual floppy drive backing.' |
| 320 |
- If unset, the virtual floppy drive will be configured to automatically detect |
| 321 |
a suitable host device. |
| 322 |
- ' - C(start_connected) (bool): Flag indicating whether the virtual device |
| 323 |
should be connected whenever the virtual machine is powered on.' |
| 324 |
- Defaults to false if unset. (['present']) |
| 325 |
- ' - C(allow_guest_control) (bool): Flag indicating whether the guest can |
| 326 |
connect and disconnect the device.' |
| 327 |
- Defaults to false if unset. (['present']) |
| 328 |
elements: dict |
| 329 |
type: list |
| 330 |
guest_OS: |
| 331 |
choices: |
| 332 |
- ALMALINUX_64 |
| 333 |
- AMAZONLINUX2_64 |
| 334 |
- AMAZONLINUX3_64 |
| 335 |
- ASIANUX_3 |
| 336 |
- ASIANUX_3_64 |
| 337 |
- ASIANUX_4 |
| 338 |
- ASIANUX_4_64 |
| 339 |
- ASIANUX_5_64 |
| 340 |
- ASIANUX_7_64 |
| 341 |
- ASIANUX_8_64 |
| 342 |
- ASIANUX_9_64 |
| 343 |
- CENTOS |
| 344 |
- CENTOS_6 |
| 345 |
- CENTOS_64 |
| 346 |
- CENTOS_6_64 |
| 347 |
- CENTOS_7 |
| 348 |
- CENTOS_7_64 |
| 349 |
- CENTOS_8_64 |
| 350 |
- CENTOS_9_64 |
| 351 |
- COREOS_64 |
| 352 |
- CRXPOD_1 |
| 353 |
- DARWIN |
| 354 |
- DARWIN_10 |
| 355 |
- DARWIN_10_64 |
| 356 |
- DARWIN_11 |
| 357 |
- DARWIN_11_64 |
| 358 |
- DARWIN_12_64 |
| 359 |
- DARWIN_13_64 |
| 360 |
- DARWIN_14_64 |
| 361 |
- DARWIN_15_64 |
| 362 |
- DARWIN_16_64 |
| 363 |
- DARWIN_17_64 |
| 364 |
- DARWIN_18_64 |
| 365 |
- DARWIN_19_64 |
| 366 |
- DARWIN_20_64 |
| 367 |
- DARWIN_21_64 |
| 368 |
- DARWIN_22_64 |
| 369 |
- DARWIN_23_64 |
| 370 |
- DARWIN_64 |
| 371 |
- DEBIAN_10 |
| 372 |
- DEBIAN_10_64 |
| 373 |
- DEBIAN_11 |
| 374 |
- DEBIAN_11_64 |
| 375 |
- DEBIAN_12 |
| 376 |
- DEBIAN_12_64 |
| 377 |
- DEBIAN_4 |
| 378 |
- DEBIAN_4_64 |
| 379 |
- DEBIAN_5 |
| 380 |
- DEBIAN_5_64 |
| 381 |
- DEBIAN_6 |
| 382 |
- DEBIAN_6_64 |
| 383 |
- DEBIAN_7 |
| 384 |
- DEBIAN_7_64 |
| 385 |
- DEBIAN_8 |
| 386 |
- DEBIAN_8_64 |
| 387 |
- DEBIAN_9 |
| 388 |
- DEBIAN_9_64 |
| 389 |
- DOS |
| 390 |
- ECOMSTATION |
| 391 |
- ECOMSTATION_2 |
| 392 |
- FEDORA |
| 393 |
- FEDORA_64 |
| 394 |
- FREEBSD |
| 395 |
- FREEBSD_11 |
| 396 |
- FREEBSD_11_64 |
| 397 |
- FREEBSD_12 |
| 398 |
- FREEBSD_12_64 |
| 399 |
- FREEBSD_13 |
| 400 |
- FREEBSD_13_64 |
| 401 |
- FREEBSD_14 |
| 402 |
- FREEBSD_14_64 |
| 403 |
- FREEBSD_64 |
| 404 |
- GENERIC_LINUX |
| 405 |
- MANDRAKE |
| 406 |
- MANDRIVA |
| 407 |
- MANDRIVA_64 |
| 408 |
- NETWARE_4 |
| 409 |
- NETWARE_5 |
| 410 |
- NETWARE_6 |
| 411 |
- NLD_9 |
| 412 |
- OES |
| 413 |
- OPENSERVER_5 |
| 414 |
- OPENSERVER_6 |
| 415 |
- OPENSUSE |
| 416 |
- OPENSUSE_64 |
| 417 |
- ORACLE_LINUX |
| 418 |
- ORACLE_LINUX_6 |
| 419 |
- ORACLE_LINUX_64 |
| 420 |
- ORACLE_LINUX_6_64 |
| 421 |
- ORACLE_LINUX_7 |
| 422 |
- ORACLE_LINUX_7_64 |
| 423 |
- ORACLE_LINUX_8_64 |
| 424 |
- ORACLE_LINUX_9_64 |
| 425 |
- OS2 |
| 426 |
- OTHER |
| 427 |
- OTHER_24X_LINUX |
| 428 |
- OTHER_24X_LINUX_64 |
| 429 |
- OTHER_26X_LINUX |
| 430 |
- OTHER_26X_LINUX_64 |
| 431 |
- OTHER_3X_LINUX |
| 432 |
- OTHER_3X_LINUX_64 |
| 433 |
- OTHER_4X_LINUX |
| 434 |
- OTHER_4X_LINUX_64 |
| 435 |
- OTHER_5X_LINUX |
| 436 |
- OTHER_5X_LINUX_64 |
| 437 |
- OTHER_64 |
| 438 |
- OTHER_6X_LINUX |
| 439 |
- OTHER_6X_LINUX_64 |
| 440 |
- OTHER_LINUX |
| 441 |
- OTHER_LINUX_64 |
| 442 |
- REDHAT |
| 443 |
- RHEL_2 |
| 444 |
- RHEL_3 |
| 445 |
- RHEL_3_64 |
| 446 |
- RHEL_4 |
| 447 |
- RHEL_4_64 |
| 448 |
- RHEL_5 |
| 449 |
- RHEL_5_64 |
| 450 |
- RHEL_6 |
| 451 |
- RHEL_6_64 |
| 452 |
- RHEL_7 |
| 453 |
- RHEL_7_64 |
| 454 |
- RHEL_8_64 |
| 455 |
- RHEL_9_64 |
| 456 |
- ROCKYLINUX_64 |
| 457 |
- SJDS |
| 458 |
- SLES |
| 459 |
- SLES_10 |
| 460 |
- SLES_10_64 |
| 461 |
- SLES_11 |
| 462 |
- SLES_11_64 |
| 463 |
- SLES_12 |
| 464 |
- SLES_12_64 |
| 465 |
- SLES_15_64 |
| 466 |
- SLES_16_64 |
| 467 |
- SLES_64 |
| 468 |
- SOLARIS_10 |
| 469 |
- SOLARIS_10_64 |
| 470 |
- SOLARIS_11_64 |
| 471 |
- SOLARIS_6 |
| 472 |
- SOLARIS_7 |
| 473 |
- SOLARIS_8 |
| 474 |
- SOLARIS_9 |
| 475 |
- SUSE |
| 476 |
- SUSE_64 |
| 477 |
- TURBO_LINUX |
| 478 |
- TURBO_LINUX_64 |
| 479 |
- UBUNTU |
| 480 |
- UBUNTU_64 |
| 481 |
- UNIXWARE_7 |
| 482 |
- VMKERNEL |
| 483 |
- VMKERNEL_5 |
| 484 |
- VMKERNEL_6 |
| 485 |
- VMKERNEL_65 |
| 486 |
- VMKERNEL_7 |
| 487 |
- VMKERNEL_8 |
| 488 |
- VMWARE_PHOTON_64 |
| 489 |
- WINDOWS_11_64 |
| 490 |
- WINDOWS_12_64 |
| 491 |
- WINDOWS_7 |
| 492 |
- WINDOWS_7_64 |
| 493 |
- WINDOWS_7_SERVER_64 |
| 494 |
- WINDOWS_8 |
| 495 |
- WINDOWS_8_64 |
| 496 |
- WINDOWS_8_SERVER_64 |
| 497 |
- WINDOWS_9 |
| 498 |
- WINDOWS_9_64 |
| 499 |
- WINDOWS_9_SERVER_64 |
| 500 |
- WINDOWS_HYPERV |
| 501 |
- WINDOWS_SERVER_2019 |
| 502 |
- WINDOWS_SERVER_2021 |
| 503 |
- WINDOWS_SERVER_2025 |
| 504 |
- WIN_2000_ADV_SERV |
| 505 |
- WIN_2000_PRO |
| 506 |
- WIN_2000_SERV |
| 507 |
- WIN_31 |
| 508 |
- WIN_95 |
| 509 |
- WIN_98 |
| 510 |
- WIN_LONGHORN |
| 511 |
- WIN_LONGHORN_64 |
| 512 |
- WIN_ME |
| 513 |
- WIN_NET_BUSINESS |
| 514 |
- WIN_NET_DATACENTER |
| 515 |
- WIN_NET_DATACENTER_64 |
| 516 |
- WIN_NET_ENTERPRISE |
| 517 |
- WIN_NET_ENTERPRISE_64 |
| 518 |
- WIN_NET_STANDARD |
| 519 |
- WIN_NET_STANDARD_64 |
| 520 |
- WIN_NET_WEB |
| 521 |
- WIN_NT |
| 522 |
- WIN_VISTA |
| 523 |
- WIN_VISTA_64 |
| 524 |
- WIN_XP_HOME |
| 525 |
- WIN_XP_PRO |
| 526 |
- WIN_XP_PRO_64 |
| 527 |
description: |
| 528 |
- The GuestOS enumerated type defines the valid guest operating system types |
| 529 |
used for configuring a virtual machine. Required with I(state=['present']) |
| 530 |
type: str |
| 531 |
guest_customization_spec: |
| 532 |
description: |
| 533 |
- Guest customization spec to apply to the virtual machine after the virtual |
| 534 |
machine is deployed. |
| 535 |
- If unset, the guest operating system is not customized after clone. |
| 536 |
- 'Valid attributes are:' |
| 537 |
- ' - C(name) (str): Name of the customization specification.' |
| 538 |
- If unset, no guest customization is performed. (['clone']) |
| 539 |
type: dict |
| 540 |
hardware_version: |
| 541 |
choices: |
| 542 |
- VMX_03 |
| 543 |
- VMX_04 |
| 544 |
- VMX_06 |
| 545 |
- VMX_07 |
| 546 |
- VMX_08 |
| 547 |
- VMX_09 |
| 548 |
- VMX_10 |
| 549 |
- VMX_11 |
| 550 |
- VMX_12 |
| 551 |
- VMX_13 |
| 552 |
- VMX_14 |
| 553 |
- VMX_15 |
| 554 |
- VMX_16 |
| 555 |
- VMX_17 |
| 556 |
- VMX_18 |
| 557 |
- VMX_19 |
| 558 |
- VMX_20 |
| 559 |
- VMX_21 |
| 560 |
description: |
| 561 |
- The I(version) enumerated type defines the valid virtual hardware versions |
| 562 |
for a virtual machine. See https://kb.vmware.com/s/article/1003746 (Virtual |
| 563 |
machine hardware versions (1003746)). |
| 564 |
type: str |
| 565 |
memory: |
| 566 |
description: |
| 567 |
- Memory configuration. |
| 568 |
- If unset, guest-specific default values will be used. |
| 569 |
- 'Valid attributes are:' |
| 570 |
- ' - C(size_MiB) (int): New memory size in mebibytes. ' |
| 571 |
- ' The supported range of memory sizes is constrained by the configured guest |
| 572 |
operating system and virtual hardware version of the virtual machine. ' |
| 573 |
- '' |
| 574 |
- ' If the virtual machine is running, this value may only be changed if I(hot_add_enabled) |
| 575 |
is true, and the new memory size must satisfy the constraints specified |
| 576 |
by I(hot_add_increment_size_mib) and I()' |
| 577 |
- '' |
| 578 |
- If unset, the value is unchanged. (['present']) |
| 579 |
- ' - C(hot_add_enabled) (bool): Flag indicating whether adding memory while |
| 580 |
the virtual machine is running should be enabled. ' |
| 581 |
- ' Some guest operating systems may consume more resources or perform less |
| 582 |
efficiently when they run on hardware that supports adding memory while |
| 583 |
the machine is running. ' |
| 584 |
- '' |
| 585 |
- ' This field may only be modified if the virtual machine is not powered |
| 586 |
on.' |
| 587 |
- '' |
| 588 |
- If unset, the value is unchanged. (['present']) |
| 589 |
type: dict |
| 590 |
name: |
| 591 |
description: |
| 592 |
- Virtual machine name. |
| 593 |
- If unset, the display name from the virtual machine's configuration file |
| 594 |
will be used. |
| 595 |
type: str |
| 596 |
nics: |
| 597 |
description: |
| 598 |
- List of Ethernet adapters. |
| 599 |
- If unset, no Ethernet adapters will be created. |
| 600 |
- 'Valid attributes are:' |
| 601 |
- ' - C(type) (str): This option defines the valid emulation types for a virtual |
| 602 |
Ethernet adapter. ([''present''])' |
| 603 |
- ' - Accepted values:' |
| 604 |
- ' - E1000' |
| 605 |
- ' - E1000E' |
| 606 |
- ' - PCNET32' |
| 607 |
- ' - VMXNET' |
| 608 |
- ' - VMXNET2' |
| 609 |
- ' - VMXNET3' |
| 610 |
- ' - C(upt_compatibility_enabled) (bool): Flag indicating whether Universal |
| 611 |
Pass-Through (UPT) compatibility is enabled on this virtual Ethernet adapter.' |
| 612 |
- If unset, UPT will not be enabled on the newly-created virtual Ethernet |
| 613 |
adapter. (['present']) |
| 614 |
- ' - C(mac_type) (str): This option defines the valid MAC address origins |
| 615 |
for a virtual Ethernet adapter. ([''present''])' |
| 616 |
- ' - Accepted values:' |
| 617 |
- ' - ASSIGNED' |
| 618 |
- ' - GENERATED' |
| 619 |
- ' - MANUAL' |
| 620 |
- ' - C(mac_address) (str): MAC address.' |
| 621 |
- Workaround for PR1459647 (['present']) |
| 622 |
- ' - C(pci_slot_number) (int): Address of the virtual Ethernet adapter on |
| 623 |
the PCI bus. If the PCI address is invalid, the server will change when |
| 624 |
it the VM is started or as the device is hot added.' |
| 625 |
- If unset, the server will choose an available address when the virtual machine |
| 626 |
is powered on. (['present']) |
| 627 |
- ' - C(wake_on_lan_enabled) (bool): Flag indicating whether wake-on-LAN is |
| 628 |
enabled on this virtual Ethernet adapter.' |
| 629 |
- Defaults to false if unset. (['present']) |
| 630 |
- ' - C(backing) (dict): Physical resource backing for the virtual Ethernet |
| 631 |
adapter.' |
| 632 |
- If unset, the system may try to find an appropriate backing. If one is not |
| 633 |
found, the request will fail. (['present']) |
| 634 |
- ' - Accepted keys:' |
| 635 |
- ' - type (string): This option defines the valid backing types for a |
| 636 |
virtual Ethernet adapter.' |
| 637 |
- 'Accepted value for this field:' |
| 638 |
- ' - C(DISTRIBUTED_PORTGROUP)' |
| 639 |
- ' - C(HOST_DEVICE)' |
| 640 |
- ' - C(OPAQUE_NETWORK)' |
| 641 |
- ' - C(STANDARD_PORTGROUP)' |
| 642 |
- ' - network (string): Identifier of the network that backs the virtual |
| 643 |
Ethernet adapter.' |
| 644 |
- This field is optional and it is only relevant when the value of I(type) |
| 645 |
is one of STANDARD_PORTGROUP, DISTRIBUTED_PORTGROUP, or OPAQUE_NETWORK. |
| 646 |
- 'When clients pass a value of this structure as a parameter, the field must |
| 647 |
be the id of a resource returned by M(vmware.vmware_rest.vcenter_network_info). ' |
| 648 |
- ' - distributed_port (string): Key of the distributed virtual port that |
| 649 |
backs the virtual Ethernet adapter. Depending on the type of the Portgroup, |
| 650 |
the port may be specified using this field. If the portgroup type is early-binding |
| 651 |
(also known as static), a port is assigned when the Ethernet adapter is |
| 652 |
configured to use the port. The port may be either automatically or specifically |
| 653 |
assigned based on the value of this field. If the portgroup type is ephemeral, |
| 654 |
the port is created and assigned to a virtual machine when it is powered |
| 655 |
on and the Ethernet adapter is connected. This field cannot be specified |
| 656 |
as no free ports exist before use.' |
| 657 |
- May be used to specify a port when the network specified on the I(network) |
| 658 |
field is a static or early binding distributed portgroup. If unset, the |
| 659 |
port will be automatically assigned to the Ethernet adapter based on the |
| 660 |
policy embodied by the portgroup type. |
| 661 |
- ' - C(start_connected) (bool): Flag indicating whether the virtual device |
| 662 |
should be connected whenever the virtual machine is powered on.' |
| 663 |
- Defaults to false if unset. (['present']) |
| 664 |
- ' - C(allow_guest_control) (bool): Flag indicating whether the guest can |
| 665 |
connect and disconnect the device.' |
| 666 |
- Defaults to false if unset. (['present']) |
| 667 |
elements: dict |
| 668 |
type: list |
| 669 |
nics_to_update: |
| 670 |
description: |
| 671 |
- Map of NICs to update. |
| 672 |
- If unset, no NICs will be updated. |
| 673 |
- 'When clients pass a value of this structure as a parameter, the key in |
| 674 |
the field map must be the id of a resource returned by M(vmware.vmware_rest.vcenter_vm_hardware_ethernet). ' |
| 675 |
type: dict |
| 676 |
nvme_adapters: |
| 677 |
description: |
| 678 |
- List of NVMe adapters. |
| 679 |
- If unset, any adapters necessary to connect the virtual machine's storage |
| 680 |
devices will be created; this includes any devices that explicitly specify |
| 681 |
a NVMe host bus adapter, as well as any devices that do not specify a |
| 682 |
host bus adapter if the guest's preferred adapter type is NVMe. |
| 683 |
- 'Valid attributes are:' |
| 684 |
- ' - C(bus) (int): NVMe bus number.' |
| 685 |
- If unset, the server will choose an available bus number; if none is available, |
| 686 |
the request will fail. (['present']) |
| 687 |
- ' - C(pci_slot_number) (int): Address of the NVMe adapter on the PCI bus.' |
| 688 |
- If unset, the server will choose an available address when the virtual machine |
| 689 |
is powered on. (['present']) |
| 690 |
elements: dict |
| 691 |
type: list |
| 692 |
parallel_ports: |
| 693 |
description: |
| 694 |
- List of parallel ports. |
| 695 |
- If unset, no parallel ports will be created. |
| 696 |
- 'Valid attributes are:' |
| 697 |
- ' - C(backing) (dict): Physical resource backing for the virtual parallel |
| 698 |
port.' |
| 699 |
- If unset, defaults to automatic detection of a suitable host device. (['present']) |
| 700 |
- ' - Accepted keys:' |
| 701 |
- ' - type (string): This option defines the valid backing types for a |
| 702 |
virtual parallel port.' |
| 703 |
- 'Accepted value for this field:' |
| 704 |
- ' - C(FILE)' |
| 705 |
- ' - C(HOST_DEVICE)' |
| 706 |
- ' - file (string): Path of the file that should be used as the virtual |
| 707 |
parallel port backing.' |
| 708 |
- This field is optional and it is only relevant when the value of I(type) |
| 709 |
is FILE. |
| 710 |
- ' - host_device (string): Name of the device that should be used as |
| 711 |
the virtual parallel port backing.' |
| 712 |
- If unset, the virtual parallel port will be configured to automatically |
| 713 |
detect a suitable host device. |
| 714 |
- ' - C(start_connected) (bool): Flag indicating whether the virtual device |
| 715 |
should be connected whenever the virtual machine is powered on.' |
| 716 |
- Defaults to false if unset. (['present']) |
| 717 |
- ' - C(allow_guest_control) (bool): Flag indicating whether the guest can |
| 718 |
connect and disconnect the device.' |
| 719 |
- Defaults to false if unset. (['present']) |
| 720 |
elements: dict |
| 721 |
type: list |
| 722 |
parallel_ports_to_update: |
| 723 |
description: |
| 724 |
- Map of parallel ports to Update. |
| 725 |
- If unset, no parallel ports will be updated. |
| 726 |
- 'When clients pass a value of this structure as a parameter, the key in |
| 727 |
the field map must be the id of a resource returned by M(vmware.vmware_rest.vcenter_vm_hardware_parallel). ' |
| 728 |
type: dict |
| 729 |
path: |
| 730 |
description: |
| 731 |
- 'Path to the virtual machine''s configuration file on the datastore corresponding |
| 732 |
to {@link #datastore).' |
| 733 |
- If unset, I(datastore) must also be unset and I(datastore_path) must be |
| 734 |
set. |
| 735 |
type: str |
| 736 |
placement: |
| 737 |
description: |
| 738 |
- Virtual machine placement information. |
| 739 |
- If this field is unset, the system will use the values from the source virtual |
| 740 |
machine. If specified, each field will be used for placement. If the fields |
| 741 |
result in disjoint placement the operation will fail. If the fields along |
| 742 |
with the other existing placement of the virtual machine result in disjoint |
| 743 |
placement the operation will fail. |
| 744 |
- 'Valid attributes are:' |
| 745 |
- ' - C(folder) (str): Virtual machine folder into which the virtual machine |
| 746 |
should be placed.' |
| 747 |
- If this field is unset, the virtual machine will stay in the current folder. |
| 748 |
- When clients pass a value of this structure as a parameter, the field must |
| 749 |
be the id of a resource returned by M(vmware.vmware_rest.vcenter_folder_info). |
| 750 |
(['clone', 'instant_clone', 'present', 'register', 'relocate']) |
| 751 |
- ' - C(resource_pool) (str): Resource pool into which the virtual machine |
| 752 |
should be placed.' |
| 753 |
- If this field is unset, the virtual machine will stay in the current resource |
| 754 |
pool. |
| 755 |
- When clients pass a value of this structure as a parameter, the field must |
| 756 |
be the id of a resource returned by M(vmware.vmware_rest.vcenter_resourcepool_info). |
| 757 |
(['clone', 'instant_clone', 'present', 'register', 'relocate']) |
| 758 |
- ' - C(host) (str): Host onto which the virtual machine should be placed. ' |
| 759 |
- ' If I(host) and I(resource_pool) are both specified, I(resource_pool) must |
| 760 |
belong to I(host). ' |
| 761 |
- '' |
| 762 |
- ' If I(host) and I(cluster) are both specified, I(host) must be a member |
| 763 |
of I(cluster).' |
| 764 |
- '' |
| 765 |
- If this field is unset, if I(resource_pool) is unset, the virtual machine |
| 766 |
will remain on the current host. if I(resource_pool) is set, and the target |
| 767 |
is a standalone host, the host is used. if I(resource_pool) is set, and |
| 768 |
the target is a DRS cluster, a host will be picked by DRS. if I(resource_pool) |
| 769 |
is set, and the target is a cluster without DRS, InvalidArgument will |
| 770 |
be thrown. |
| 771 |
- When clients pass a value of this structure as a parameter, the field must |
| 772 |
be the id of a resource returned by M(vmware.vmware_rest.vcenter_host_info). |
| 773 |
(['clone', 'present', 'register', 'relocate']) |
| 774 |
- ' - C(cluster) (str): Cluster into which the virtual machine should be placed. ' |
| 775 |
- ' If I(cluster) and I(resource_pool) are both specified, I(resource_pool) |
| 776 |
must belong to I(cluster). ' |
| 777 |
- '' |
| 778 |
- ' If I(cluster) and I(host) are both specified, I(host) must be a member |
| 779 |
of I(cluster).' |
| 780 |
- '' |
| 781 |
- If I(resource_pool) or I(host) is specified, it is recommended that this |
| 782 |
field be unset. |
| 783 |
- When clients pass a value of this structure as a parameter, the field must |
| 784 |
be the id of a resource returned by M(vmware.vmware_rest.vcenter_cluster_info). |
| 785 |
(['clone', 'present', 'register', 'relocate']) |
| 786 |
- ' - C(datastore) (str): Datastore on which the virtual machine''s configuration |
| 787 |
state should be stored. This datastore will also be used for any virtual |
| 788 |
disks that are associated with the virtual machine, unless individually |
| 789 |
overridden.' |
| 790 |
- If this field is unset, the virtual machine will remain on the current datastore. |
| 791 |
- When clients pass a value of this structure as a parameter, the field must |
| 792 |
be the id of a resource returned by M(vmware.vmware_rest.vcenter_datastore_info). |
| 793 |
(['clone', 'instant_clone', 'present', 'relocate']) |
| 794 |
type: dict |
| 795 |
power_on: |
| 796 |
description: |
| 797 |
- Attempt to perform a I(power_on) after clone. |
| 798 |
- If unset, the virtual machine will not be powered on. |
| 799 |
type: bool |
| 800 |
sata_adapters: |
| 801 |
description: |
| 802 |
- List of SATA adapters. |
| 803 |
- If unset, any adapters necessary to connect the virtual machine's storage |
| 804 |
devices will be created; this includes any devices that explicitly specify |
| 805 |
a SATA host bus adapter, as well as any devices that do not specify a |
| 806 |
host bus adapter if the guest's preferred adapter type is SATA. |
| 807 |
- 'Valid attributes are:' |
| 808 |
- ' - C(type) (str): This option defines the valid emulation types for a virtual |
| 809 |
SATA adapter. ([''present''])' |
| 810 |
- ' - Accepted values:' |
| 811 |
- ' - AHCI' |
| 812 |
- ' - C(bus) (int): SATA bus number.' |
| 813 |
- If unset, the server will choose an available bus number; if none is available, |
| 814 |
the request will fail. (['present']) |
| 815 |
- ' - C(pci_slot_number) (int): Address of the SATA adapter on the PCI bus.' |
| 816 |
- If unset, the server will choose an available address when the virtual machine |
| 817 |
is powered on. (['present']) |
| 818 |
elements: dict |
| 819 |
type: list |
| 820 |
scsi_adapters: |
| 821 |
description: |
| 822 |
- List of SCSI adapters. |
| 823 |
- If unset, any adapters necessary to connect the virtual machine's storage |
| 824 |
devices will be created; this includes any devices that explicitly specify |
| 825 |
a SCSI host bus adapter, as well as any devices that do not specify a |
| 826 |
host bus adapter if the guest's preferred adapter type is SCSI. The type |
| 827 |
of the SCSI adapter will be a guest-specific default type. |
| 828 |
- 'Valid attributes are:' |
| 829 |
- ' - C(type) (str): This option defines the valid emulation types for a virtual |
| 830 |
SCSI adapter. ([''present''])' |
| 831 |
- ' - Accepted values:' |
| 832 |
- ' - BUSLOGIC' |
| 833 |
- ' - LSILOGIC' |
| 834 |
- ' - LSILOGICSAS' |
| 835 |
- ' - PVSCSI' |
| 836 |
- ' - C(bus) (int): SCSI bus number.' |
| 837 |
- If unset, the server will choose an available bus number; if none is available, |
| 838 |
the request will fail. (['present']) |
| 839 |
- ' - C(pci_slot_number) (int): Address of the SCSI adapter on the PCI bus. |
| 840 |
If the PCI address is invalid, the server will change it when the VM is |
| 841 |
started or as the device is hot added.' |
| 842 |
- If unset, the server will choose an available address when the virtual machine |
| 843 |
is powered on. (['present']) |
| 844 |
- ' - C(sharing) (str): This option defines the valid bus sharing modes for |
| 845 |
a virtual SCSI adapter. ([''present''])' |
| 846 |
- ' - Accepted values:' |
| 847 |
- ' - NONE' |
| 848 |
- ' - PHYSICAL' |
| 849 |
- ' - VIRTUAL' |
| 850 |
elements: dict |
| 851 |
type: list |
| 852 |
serial_ports: |
| 853 |
description: |
| 854 |
- List of serial ports. |
| 855 |
- If unset, no serial ports will be created. |
| 856 |
- 'Valid attributes are:' |
| 857 |
- ' - C(yield_on_poll) (bool): CPU yield behavior. If set to true, the virtual |
| 858 |
machine will periodically relinquish the processor if its sole task is |
| 859 |
polling the virtual serial port. The amount of time it takes to regain |
| 860 |
the processor will depend on the degree of other virtual machine activity |
| 861 |
on the host.' |
| 862 |
- If unset, defaults to false. (['present']) |
| 863 |
- ' - C(backing) (dict): Physical resource backing for the virtual serial |
| 864 |
port.' |
| 865 |
- If unset, defaults to automatic detection of a suitable host device. (['present']) |
| 866 |
- ' - Accepted keys:' |
| 867 |
- ' - type (string): This option defines the valid backing types for a |
| 868 |
virtual serial port.' |
| 869 |
- 'Accepted value for this field:' |
| 870 |
- ' - C(FILE)' |
| 871 |
- ' - C(HOST_DEVICE)' |
| 872 |
- ' - C(NETWORK_CLIENT)' |
| 873 |
- ' - C(NETWORK_SERVER)' |
| 874 |
- ' - C(PIPE_CLIENT)' |
| 875 |
- ' - C(PIPE_SERVER)' |
| 876 |
- ' - file (string): Path of the file backing the virtual serial port.' |
| 877 |
- This field is optional and it is only relevant when the value of I(type) |
| 878 |
is FILE. |
| 879 |
- ' - host_device (string): Name of the device backing the virtual serial |
| 880 |
port. ' |
| 881 |
- '' |
| 882 |
- '' |
| 883 |
- If unset, the virtual serial port will be configured to automatically detect |
| 884 |
a suitable host device. |
| 885 |
- ' - pipe (string): Name of the pipe backing the virtual serial port.' |
| 886 |
- This field is optional and it is only relevant when the value of I(type) |
| 887 |
is one of PIPE_SERVER or PIPE_CLIENT. |
| 888 |
- ' - no_rx_loss (boolean): Flag that enables optimized data transfer |
| 889 |
over the pipe. When the value is true, the host buffers data to prevent |
| 890 |
data overrun. This allows the virtual machine to read all of the data |
| 891 |
transferred over the pipe with no data loss.' |
| 892 |
- If unset, defaults to false. |
| 893 |
- ' - network_location (string): URI specifying the location of the network |
| 894 |
service backing the virtual serial port. ' |
| 895 |
- ' - If I(type) is NETWORK_SERVER, this field is the location used by clients |
| 896 |
to connect to this server. The hostname part of the URI should either |
| 897 |
be empty or should specify the address of the host on which the virtual |
| 898 |
machine is running.' |
| 899 |
- ' - If I(type) is NETWORK_CLIENT, this field is the location used by the |
| 900 |
virtual machine to connect to the remote server.' |
| 901 |
- ' ' |
| 902 |
- This field is optional and it is only relevant when the value of I(type) |
| 903 |
is one of NETWORK_SERVER or NETWORK_CLIENT. |
| 904 |
- ' - proxy (string): Proxy service that provides network access to the |
| 905 |
network backing. If set, the virtual machine initiates a connection with |
| 906 |
the proxy service and forwards the traffic to the proxy.' |
| 907 |
- If unset, no proxy service should be used. |
| 908 |
- ' - C(start_connected) (bool): Flag indicating whether the virtual device |
| 909 |
should be connected whenever the virtual machine is powered on.' |
| 910 |
- Defaults to false if unset. (['present']) |
| 911 |
- ' - C(allow_guest_control) (bool): Flag indicating whether the guest can |
| 912 |
connect and disconnect the device.' |
| 913 |
- Defaults to false if unset. (['present']) |
| 914 |
elements: dict |
| 915 |
type: list |
| 916 |
serial_ports_to_update: |
| 917 |
description: |
| 918 |
- Map of serial ports to Update. |
| 919 |
- If unset, no serial ports will be updated. |
| 920 |
- 'When clients pass a value of this structure as a parameter, the key in |
| 921 |
the field map must be the id of a resource returned by M(vmware.vmware_rest.vcenter_vm_hardware_serial). ' |
| 922 |
type: dict |
| 923 |
session_timeout: |
| 924 |
description: |
| 925 |
- 'Timeout settings for client session. ' |
| 926 |
- 'The maximal number of seconds for the whole operation including connection |
| 927 |
establishment, request sending and response. ' |
| 928 |
- The default value is 300s. |
| 929 |
type: float |
| 930 |
version_added: 2.1.0 |
| 931 |
source: |
| 932 |
description: |
| 933 |
- Virtual machine to InstantClone from. |
| 934 |
- When clients pass a value of this structure as a parameter, the field must |
| 935 |
be the id of a resource returned by M(vmware.vmware_rest.vcenter_vm_info). |
| 936 |
Required with I(state=['clone', 'instant_clone']) |
| 937 |
type: str |
| 938 |
state: |
| 939 |
choices: |
| 940 |
- absent |
| 941 |
- clone |
| 942 |
- instant_clone |
| 943 |
- present |
| 944 |
- register |
| 945 |
- relocate |
| 946 |
- unregister |
| 947 |
default: present |
| 948 |
description: [] |
| 949 |
type: str |
| 950 |
storage_policy: |
| 951 |
description: |
| 952 |
- The I(storage_policy_spec) structure contains information about the storage |
| 953 |
policy that is to be associated with the virtual machine home (which contains |
| 954 |
the configuration and log files). |
| 955 |
- 'If unset the datastore default storage policy (if applicable) is applied. |
| 956 |
Currently a default storage policy is only supported by object datastores |
| 957 |
: VVol and vSAN. For non-object datastores, if unset then no storage policy |
| 958 |
would be associated with the virtual machine home. Required with I(state=[''present''])' |
| 959 |
- 'Valid attributes are:' |
| 960 |
- ' - C(policy) (str): Identifier of the storage policy which should be associated |
| 961 |
with the virtual machine.' |
| 962 |
- When clients pass a value of this structure as a parameter, the field must |
| 963 |
be the id of a resource returned by M(vmware.vmware_rest.vcenter_storage_policies_info). |
| 964 |
(['present']) |
| 965 |
- ' This key is required with [''present''].' |
| 966 |
type: dict |
| 967 |
vcenter_hostname: |
| 968 |
description: |
| 969 |
- The hostname or IP address of the vSphere vCenter |
| 970 |
- If the value is not specified in the task, the value of environment variable |
| 971 |
C(VMWARE_HOST) will be used instead. |
| 972 |
required: true |
| 973 |
type: str |
| 974 |
vcenter_password: |
| 975 |
description: |
| 976 |
- The vSphere vCenter password |
| 977 |
- If the value is not specified in the task, the value of environment variable |
| 978 |
C(VMWARE_PASSWORD) will be used instead. |
| 979 |
required: true |
| 980 |
type: str |
| 981 |
vcenter_rest_log_file: |
| 982 |
description: |
| 983 |
- 'You can use this optional parameter to set the location of a log file. ' |
| 984 |
- 'This file will be used to record the HTTP REST interaction. ' |
| 985 |
- 'The file will be stored on the host that runs the module. ' |
| 986 |
- 'If the value is not specified in the task, the value of ' |
| 987 |
- environment variable C(VMWARE_REST_LOG_FILE) will be used instead. |
| 988 |
type: str |
| 989 |
vcenter_username: |
| 990 |
description: |
| 991 |
- The vSphere vCenter username |
| 992 |
- If the value is not specified in the task, the value of environment variable |
| 993 |
C(VMWARE_USER) will be used instead. |
| 994 |
required: true |
| 995 |
type: str |
| 996 |
vcenter_validate_certs: |
| 997 |
default: true |
| 998 |
description: |
| 999 |
- Allows connection when SSL certificates are not valid. Set to C(false) when |
| 1000 |
certificates are not trusted. |
| 1001 |
- If the value is not specified in the task, the value of environment variable |
| 1002 |
C(VMWARE_VALIDATE_CERTS) will be used instead. |
| 1003 |
type: bool |
| 1004 |
vm: |
| 1005 |
description: |
| 1006 |
- Identifier of the virtual machine to be unregistered. |
| 1007 |
- The parameter must be the id of a resource returned by M(vmware.vmware_rest.vcenter_vm_info). |
| 1008 |
Required with I(state=['absent', 'relocate', 'unregister']) |
| 1009 |
type: str |
| 1010 |
author: |
| 1011 |
- Ansible Cloud Team (@ansible-collections) |
| 1012 |
version_added: 0.1.0 |
| 1013 |
requirements: |
| 1014 |
- vSphere 7.0.3 or greater |
| 1015 |
- python >= 3.6 |
| 1016 |
- aiohttp |
| 1017 |
notes: |
| 1018 |
- Tested on vSphere 7.0.3 |
| 1019 |
""" |
| 1020 |
|
| 1021 |
EXAMPLES = r""" |
| 1022 |
- name: Create a VM |
| 1023 |
vmware.vmware_rest.vcenter_vm: |
| 1024 |
placement: |
| 1025 |
cluster: "{{ lookup('vmware.vmware_rest.cluster_moid', '/my_dc/host/my_cluster') }}" |
| 1026 |
datastore: "{{ lookup('vmware.vmware_rest.datastore_moid', '/my_dc/datastore/rw_datastore') }}" |
| 1027 |
folder: "{{ lookup('vmware.vmware_rest.folder_moid', '/my_dc/vm') }}" |
| 1028 |
resource_pool: "{{ lookup('vmware.vmware_rest.resource_pool_moid', '/my_dc/host/my_cluster/Resources') }}" |
| 1029 |
name: test_vm1 |
| 1030 |
guest_OS: RHEL_7_64 |
| 1031 |
hardware_version: VMX_11 |
| 1032 |
memory: |
| 1033 |
hot_add_enabled: true |
| 1034 |
size_MiB: 1024 |
| 1035 |
register: my_vm |
| 1036 |
|
| 1037 |
- name: Create a VM |
| 1038 |
vmware.vmware_rest.vcenter_vm: |
| 1039 |
placement: |
| 1040 |
cluster: "{{ lookup('vmware.vmware_rest.cluster_moid', '/my_dc/host/my_cluster') }}" |
| 1041 |
datastore: "{{ lookup('vmware.vmware_rest.datastore_moid', '/my_dc/datastore/local') }}" |
| 1042 |
folder: "{{ lookup('vmware.vmware_rest.folder_moid', '/my_dc/vm') }}" |
| 1043 |
resource_pool: "{{ lookup('vmware.vmware_rest.resource_pool_moid', '/my_dc/host/my_cluster/Resources') }}" |
| 1044 |
name: test_vm1 |
| 1045 |
guest_OS: RHEL_7_64 |
| 1046 |
hardware_version: VMX_11 |
| 1047 |
memory: |
| 1048 |
hot_add_enabled: true |
| 1049 |
size_MiB: 1024 |
| 1050 |
disks: |
| 1051 |
- type: SATA |
| 1052 |
backing: |
| 1053 |
type: VMDK_FILE |
| 1054 |
vmdk_file: '[local] test_vm1/{{ disk_name }}.vmdk' |
| 1055 |
- type: SATA |
| 1056 |
new_vmdk: |
| 1057 |
name: second_disk |
| 1058 |
capacity: 32000000000 |
| 1059 |
cdroms: |
| 1060 |
- type: SATA |
| 1061 |
sata: |
| 1062 |
bus: 0 |
| 1063 |
unit: 2 |
| 1064 |
nics: |
| 1065 |
- backing: |
| 1066 |
type: STANDARD_PORTGROUP |
| 1067 |
network: "{{ lookup('vmware.vmware_rest.network_moid', '/my_dc/network/VM Network') }}" |
| 1068 |
register: my_vm |
| 1069 |
|
| 1070 |
- name: Create a content library based on a DataStore |
| 1071 |
vmware.vmware_rest.content_locallibrary: |
| 1072 |
name: my_library_on_datastore |
| 1073 |
description: automated |
| 1074 |
publish_info: |
| 1075 |
published: true |
| 1076 |
authentication_method: NONE |
| 1077 |
storage_backings: |
| 1078 |
- datastore_id: "{{ lookup('vmware.vmware_rest.datastore_moid', '/my_dc/datastore/local') }}" |
| 1079 |
type: DATASTORE |
| 1080 |
state: present |
| 1081 |
register: nfs_lib |
| 1082 |
|
| 1083 |
- name: Get the list of items of the NFS library |
| 1084 |
vmware.vmware.content_library_item_info: |
| 1085 |
library_id: '{{ nfs_lib.id }}' |
| 1086 |
register: lib_items |
| 1087 |
|
| 1088 |
- name: Use the name to identify the item |
| 1089 |
set_fact: |
| 1090 |
my_template_item: "{{ lib_items.value | selectattr('name', 'equalto', 'golden-template')|first }}" |
| 1091 |
|
| 1092 |
- name: Deploy a new VM based on the template |
| 1093 |
vmware.vmware_rest.vcenter_vmtemplate_libraryitems: |
| 1094 |
name: vm-from-template |
| 1095 |
library: '{{ nfs_lib.id }}' |
| 1096 |
template_library_item: '{{ my_template_item.id }}' |
| 1097 |
placement: |
| 1098 |
cluster: "{{ lookup('vmware.vmware_rest.cluster_moid', '/my_dc/host/my_cluster') }}" |
| 1099 |
folder: "{{ lookup('vmware.vmware_rest.folder_moid', '/my_dc/vm') }}" |
| 1100 |
resource_pool: "{{ lookup('vmware.vmware_rest.resource_pool_moid', '/my_dc/host/my_cluster/Resources') }}" |
| 1101 |
state: deploy |
| 1102 |
register: my_new_vm |
| 1103 |
|
| 1104 |
- name: Retrieve all the details about the new VM |
| 1105 |
vmware.vmware_rest.vcenter_vm: |
| 1106 |
vm: '{{ my_new_vm.value }}' |
| 1107 |
register: my_new_vm_info |
| 1108 |
|
| 1109 |
- name: Create an instant clone of a VM |
| 1110 |
vmware.vmware_rest.vcenter_vm: |
| 1111 |
placement: |
| 1112 |
datastore: "{{ lookup('vmware.vmware_rest.datastore_moid', '/my_dc/datastore/local') }}" |
| 1113 |
folder: "{{ lookup('vmware.vmware_rest.folder_moid', '/my_dc/vm') }}" |
| 1114 |
resource_pool: "{{ lookup('vmware.vmware_rest.resource_pool_moid', '/my_dc/host/my_cluster/Resources') }}" |
| 1115 |
source: '{{ my_vm.id }}' |
| 1116 |
name: test_vm2 |
| 1117 |
state: instant_clone |
| 1118 |
register: my_instant_clone |
| 1119 |
|
| 1120 |
- name: Create a clone of a VM |
| 1121 |
vmware.vmware_rest.vcenter_vm: |
| 1122 |
placement: |
| 1123 |
datastore: "{{ lookup('vmware.vmware_rest.datastore_moid', '/my_dc/datastore/local') }}" |
| 1124 |
folder: "{{ lookup('vmware.vmware_rest.folder_moid', '/my_dc/vm') }}" |
| 1125 |
resource_pool: "{{ lookup('vmware.vmware_rest.resource_pool_moid', '/my_dc/host/my_cluster/Resources') }}" |
| 1126 |
source: '{{ my_vm.id }}' |
| 1127 |
name: test_vm3 |
| 1128 |
state: clone |
| 1129 |
register: my_clone_vm |
| 1130 |
|
| 1131 |
- name: Build a list of all the clusters |
| 1132 |
vmware.vmware_rest.vcenter_cluster_info: |
| 1133 |
register: all_the_clusters |
| 1134 |
|
| 1135 |
- name: Retrieve details about the first cluster |
| 1136 |
vmware.vmware_rest.vcenter_cluster_info: |
| 1137 |
cluster: '{{ all_the_clusters.value[0].cluster }}' |
| 1138 |
register: my_cluster_info |
| 1139 |
|
| 1140 |
- name: Build a list of all the folders with the type VIRTUAL_MACHINE and called vm |
| 1141 |
vmware.vmware_rest.vcenter_folder_info: |
| 1142 |
filter_type: VIRTUAL_MACHINE |
| 1143 |
filter_names: |
| 1144 |
- vm |
| 1145 |
register: my_folders |
| 1146 |
|
| 1147 |
- name: Set my_virtual_machine_folder |
| 1148 |
ansible.builtin.set_fact: |
| 1149 |
my_virtual_machine_folder: '{{ my_folders.value|first }}' |
| 1150 |
|
| 1151 |
- name: Create a VM |
| 1152 |
vmware.vmware_rest.vcenter_vm: |
| 1153 |
placement: |
| 1154 |
cluster: '{{ my_cluster_info.id }}' |
| 1155 |
datastore: "{{ lookup('vmware.vmware_rest.datastore_moid', '/my_dc/datastore/local') }}" |
| 1156 |
folder: '{{ my_virtual_machine_folder.folder }}' |
| 1157 |
resource_pool: '{{ my_cluster_info.value.resource_pool }}' |
| 1158 |
name: test_vm1 |
| 1159 |
guest_OS: DEBIAN_7_64 |
| 1160 |
hardware_version: VMX_10 |
| 1161 |
memory: |
| 1162 |
hot_add_enabled: true |
| 1163 |
size_MiB: 1024 |
| 1164 |
register: my_vm |
| 1165 |
""" |
| 1166 |
RETURN = r""" |
| 1167 |
# content generated by the update_return_section callback# task: Create an instant clone of a VM |
| 1168 |
id: |
| 1169 |
description: moid of the resource |
| 1170 |
returned: On success |
| 1171 |
sample: vm-1104 |
| 1172 |
type: str |
| 1173 |
value: |
| 1174 |
description: Create an instant clone of a VM |
| 1175 |
returned: On success |
| 1176 |
sample: |
| 1177 |
boot: |
| 1178 |
delay: 0 |
| 1179 |
enter_setup_mode: 0 |
| 1180 |
retry: 0 |
| 1181 |
retry_delay: 10000 |
| 1182 |
type: BIOS |
| 1183 |
boot_devices: [] |
| 1184 |
cdroms: |
| 1185 |
'16002': |
| 1186 |
allow_guest_control: 0 |
| 1187 |
backing: |
| 1188 |
auto_detect: 1 |
| 1189 |
device_access_type: EMULATION |
| 1190 |
type: HOST_DEVICE |
| 1191 |
label: CD/DVD drive 1 |
| 1192 |
sata: |
| 1193 |
bus: 0 |
| 1194 |
unit: 2 |
| 1195 |
start_connected: 0 |
| 1196 |
state: NOT_CONNECTED |
| 1197 |
type: SATA |
| 1198 |
cpu: |
| 1199 |
cores_per_socket: 1 |
| 1200 |
count: 1 |
| 1201 |
hot_add_enabled: 0 |
| 1202 |
hot_remove_enabled: 0 |
| 1203 |
disks: |
| 1204 |
'16000': |
| 1205 |
backing: |
| 1206 |
type: VMDK_FILE |
| 1207 |
vmdk_file: '[local] test_vm2/test_vm2_2.vmdk' |
| 1208 |
capacity: 16106127360 |
| 1209 |
label: Hard disk 1 |
| 1210 |
sata: |
| 1211 |
bus: 0 |
| 1212 |
unit: 0 |
| 1213 |
type: SATA |
| 1214 |
'16001': |
| 1215 |
backing: |
| 1216 |
type: VMDK_FILE |
| 1217 |
vmdk_file: '[local] test_vm2/test_vm2_1.vmdk' |
| 1218 |
capacity: 32000000000 |
| 1219 |
label: Hard disk 2 |
| 1220 |
sata: |
| 1221 |
bus: 0 |
| 1222 |
unit: 1 |
| 1223 |
type: SATA |
| 1224 |
floppies: {} |
| 1225 |
guest_OS: RHEL_7_64 |
| 1226 |
hardware: |
| 1227 |
upgrade_policy: NEVER |
| 1228 |
upgrade_status: NONE |
| 1229 |
version: VMX_11 |
| 1230 |
identity: |
| 1231 |
bios_uuid: 4231bf8b-3cb4-3a3f-1bfb-18c857ce95b6 |
| 1232 |
instance_uuid: 5031b322-6030-a020-8e73-1a9ad0fd03ce |
| 1233 |
name: test_vm2 |
| 1234 |
instant_clone_frozen: 0 |
| 1235 |
memory: |
| 1236 |
hot_add_enabled: 1 |
| 1237 |
hot_add_increment_size_MiB: 128 |
| 1238 |
hot_add_limit_MiB: 3072 |
| 1239 |
size_MiB: 1024 |
| 1240 |
name: test_vm2 |
| 1241 |
nics: |
| 1242 |
'4000': |
| 1243 |
allow_guest_control: 0 |
| 1244 |
backing: |
| 1245 |
network: network-1095 |
| 1246 |
network_name: VM Network |
| 1247 |
type: STANDARD_PORTGROUP |
| 1248 |
label: Network adapter 1 |
| 1249 |
mac_address: 00:50:56:b1:26:0c |
| 1250 |
mac_type: ASSIGNED |
| 1251 |
pci_slot_number: 160 |
| 1252 |
start_connected: 0 |
| 1253 |
state: NOT_CONNECTED |
| 1254 |
type: VMXNET3 |
| 1255 |
upt_compatibility_enabled: 0 |
| 1256 |
wake_on_lan_enabled: 0 |
| 1257 |
nvme_adapters: {} |
| 1258 |
parallel_ports: {} |
| 1259 |
power_state: POWERED_ON |
| 1260 |
sata_adapters: |
| 1261 |
'15000': |
| 1262 |
bus: 0 |
| 1263 |
label: SATA controller 0 |
| 1264 |
pci_slot_number: 32 |
| 1265 |
type: AHCI |
| 1266 |
scsi_adapters: {} |
| 1267 |
serial_ports: {} |
| 1268 |
type: dict |
| 1269 |
""" |
| 1270 |
|
| 1271 |
|
| 1272 |
# This structure describes the format of the data expected by the end-points |
| 1273 |
PAYLOAD_FORMAT = { |
| 1274 |
"create": { |
| 1275 |
"query": {}, |
| 1276 |
"body": { |
| 1277 |
"boot": "boot", |
| 1278 |
"boot_devices": "boot_devices", |
| 1279 |
"cdroms": "cdroms", |
| 1280 |
"cpu": "cpu", |
| 1281 |
"disks": "disks", |
| 1282 |
"floppies": "floppies", |
| 1283 |
"guest_OS": "guest_OS", |
| 1284 |
"hardware_version": "hardware_version", |
| 1285 |
"memory": "memory", |
| 1286 |
"name": "name", |
| 1287 |
"nics": "nics", |
| 1288 |
"nvme_adapters": "nvme_adapters", |
| 1289 |
"parallel_ports": "parallel_ports", |
| 1290 |
"placement": "placement", |
| 1291 |
"sata_adapters": "sata_adapters", |
| 1292 |
"scsi_adapters": "scsi_adapters", |
| 1293 |
"serial_ports": "serial_ports", |
| 1294 |
"storage_policy": "storage_policy", |
| 1295 |
}, |
| 1296 |
"path": {}, |
| 1297 |
}, |
| 1298 |
"clone": { |
| 1299 |
"query": {}, |
| 1300 |
"body": { |
| 1301 |
"disks_to_remove": "disks_to_remove", |
| 1302 |
"disks_to_update": "disks_to_update", |
| 1303 |
"guest_customization_spec": "guest_customization_spec", |
| 1304 |
"name": "name", |
| 1305 |
"placement": "placement", |
| 1306 |
"power_on": "power_on", |
| 1307 |
"source": "source", |
| 1308 |
}, |
| 1309 |
"path": {}, |
| 1310 |
}, |
| 1311 |
"delete": {"query": {}, "body": {}, "path": {"vm": "vm"}}, |
| 1312 |
"relocate": { |
| 1313 |
"query": {}, |
| 1314 |
"body": {"disks": "disks", "placement": "placement"}, |
| 1315 |
"path": {"vm": "vm"}, |
| 1316 |
}, |
| 1317 |
"unregister": {"query": {}, "body": {}, "path": {"vm": "vm"}}, |
| 1318 |
"instant_clone": { |
| 1319 |
"query": {}, |
| 1320 |
"body": { |
| 1321 |
"bios_uuid": "bios_uuid", |
| 1322 |
"disconnect_all_nics": "disconnect_all_nics", |
| 1323 |
"name": "name", |
| 1324 |
"nics_to_update": "nics_to_update", |
| 1325 |
"parallel_ports_to_update": "parallel_ports_to_update", |
| 1326 |
"placement": "placement", |
| 1327 |
"serial_ports_to_update": "serial_ports_to_update", |
| 1328 |
"source": "source", |
| 1329 |
}, |
| 1330 |
"path": {}, |
| 1331 |
}, |
| 1332 |
"register": { |
| 1333 |
"query": {}, |
| 1334 |
"body": { |
| 1335 |
"datastore": "datastore", |
| 1336 |
"datastore_path": "datastore_path", |
| 1337 |
"name": "name", |
| 1338 |
"path": "path", |
| 1339 |
"placement": "placement", |
| 1340 |
}, |
| 1341 |
"path": {}, |
| 1342 |
}, |
| 1343 |
} # pylint: disable=line-too-long |
| 1344 |
|
| 1345 |
from ansible.module_utils.basic import env_fallback |
| 1346 |
import os |
| 1347 |
|
| 1348 |
if os.getenv("VMWARE_ENABLE_TURBO", False): |
| 1349 |
try: |
| 1350 |
from ansible_collections.cloud.common.plugins.module_utils.turbo.module import ( |
| 1351 |
AnsibleTurboModule as AnsibleModule, |
| 1352 |
) |
| 1353 |
|
| 1354 |
AnsibleModule.collection_name = "vmware.vmware_rest" |
| 1355 |
except ImportError: |
| 1356 |
from ansible.module_utils.basic import AnsibleModule |
| 1357 |
else: |
| 1358 |
from ansible.module_utils.basic import AnsibleModule |
| 1359 |
|
| 1360 |
from ansible_collections.vmware.vmware_rest.plugins.module_utils.vmware_rest import ( |
| 1361 |
exists, |
| 1362 |
gen_args, |
| 1363 |
get_device_info, |
| 1364 |
get_subdevice_type, |
| 1365 |
open_session, |
| 1366 |
prepare_payload, |
| 1367 |
session_timeout, |
| 1368 |
update_changed_flag, |
| 1369 |
) |
| 1370 |
|
| 1371 |
|
| 1372 |
def prepare_argument_spec(): |
| 1373 |
argument_spec = { |
| 1374 |
"vcenter_hostname": dict( |
| 1375 |
type="str", |
| 1376 |
required=True, |
| 1377 |
fallback=(env_fallback, ["VMWARE_HOST"]), |
| 1378 |
), |
| 1379 |
"vcenter_username": dict( |
| 1380 |
type="str", |
| 1381 |
required=True, |
| 1382 |
fallback=(env_fallback, ["VMWARE_USER"]), |
| 1383 |
), |
| 1384 |
"vcenter_password": dict( |
| 1385 |
type="str", |
| 1386 |
required=True, |
| 1387 |
no_log=True, |
| 1388 |
fallback=(env_fallback, ["VMWARE_PASSWORD"]), |
| 1389 |
), |
| 1390 |
"vcenter_validate_certs": dict( |
| 1391 |
type="bool", |
| 1392 |
required=False, |
| 1393 |
default=True, |
| 1394 |
fallback=(env_fallback, ["VMWARE_VALIDATE_CERTS"]), |
| 1395 |
), |
| 1396 |
"vcenter_rest_log_file": dict( |
| 1397 |
type="str", |
| 1398 |
required=False, |
| 1399 |
fallback=(env_fallback, ["VMWARE_REST_LOG_FILE"]), |
| 1400 |
), |
| 1401 |
"session_timeout": dict( |
| 1402 |
type="float", |
| 1403 |
required=False, |
| 1404 |
fallback=(env_fallback, ["VMWARE_SESSION_TIMEOUT"]), |
| 1405 |
), |
| 1406 |
} |
| 1407 |
|
| 1408 |
argument_spec["bios_uuid"] = {"type": "str"} |
| 1409 |
argument_spec["boot"] = {"type": "dict"} |
| 1410 |
argument_spec["boot_devices"] = {"type": "list", "elements": "dict"} |
| 1411 |
argument_spec["cdroms"] = {"type": "list", "elements": "dict"} |
| 1412 |
argument_spec["cpu"] = {"type": "dict"} |
| 1413 |
argument_spec["datastore"] = {"type": "str"} |
| 1414 |
argument_spec["datastore_path"] = {"type": "str"} |
| 1415 |
argument_spec["disconnect_all_nics"] = {"type": "bool"} |
| 1416 |
argument_spec["disks"] = {"type": "list", "elements": "dict"} |
| 1417 |
argument_spec["disks_to_remove"] = {"type": "list", "elements": "str"} |
| 1418 |
argument_spec["disks_to_update"] = {"type": "dict"} |
| 1419 |
argument_spec["floppies"] = {"type": "list", "elements": "dict"} |
| 1420 |
argument_spec["guest_OS"] = { |
| 1421 |
"type": "str", |
| 1422 |
"choices": [ |
| 1423 |
"ALMALINUX_64", |
| 1424 |
"AMAZONLINUX2_64", |
| 1425 |
"AMAZONLINUX3_64", |
| 1426 |
"ASIANUX_3", |
| 1427 |
"ASIANUX_3_64", |
| 1428 |
"ASIANUX_4", |
| 1429 |
"ASIANUX_4_64", |
| 1430 |
"ASIANUX_5_64", |
| 1431 |
"ASIANUX_7_64", |
| 1432 |
"ASIANUX_8_64", |
| 1433 |
"ASIANUX_9_64", |
| 1434 |
"CENTOS", |
| 1435 |
"CENTOS_6", |
| 1436 |
"CENTOS_64", |
| 1437 |
"CENTOS_6_64", |
| 1438 |
"CENTOS_7", |
| 1439 |
"CENTOS_7_64", |
| 1440 |
"CENTOS_8_64", |
| 1441 |
"CENTOS_9_64", |
| 1442 |
"COREOS_64", |
| 1443 |
"CRXPOD_1", |
| 1444 |
"DARWIN", |
| 1445 |
"DARWIN_10", |
| 1446 |
"DARWIN_10_64", |
| 1447 |
"DARWIN_11", |
| 1448 |
"DARWIN_11_64", |
| 1449 |
"DARWIN_12_64", |
| 1450 |
"DARWIN_13_64", |
| 1451 |
"DARWIN_14_64", |
| 1452 |
"DARWIN_15_64", |
| 1453 |
"DARWIN_16_64", |
| 1454 |
"DARWIN_17_64", |
| 1455 |
"DARWIN_18_64", |
| 1456 |
"DARWIN_19_64", |
| 1457 |
"DARWIN_20_64", |
| 1458 |
"DARWIN_21_64", |
| 1459 |
"DARWIN_22_64", |
| 1460 |
"DARWIN_23_64", |
| 1461 |
"DARWIN_64", |
| 1462 |
"DEBIAN_10", |
| 1463 |
"DEBIAN_10_64", |
| 1464 |
"DEBIAN_11", |
| 1465 |
"DEBIAN_11_64", |
| 1466 |
"DEBIAN_12", |
| 1467 |
"DEBIAN_12_64", |
| 1468 |
"DEBIAN_4", |
| 1469 |
"DEBIAN_4_64", |
| 1470 |
"DEBIAN_5", |
| 1471 |
"DEBIAN_5_64", |
| 1472 |
"DEBIAN_6", |
| 1473 |
"DEBIAN_6_64", |
| 1474 |
"DEBIAN_7", |
| 1475 |
"DEBIAN_7_64", |
| 1476 |
"DEBIAN_8", |
| 1477 |
"DEBIAN_8_64", |
| 1478 |
"DEBIAN_9", |
| 1479 |
"DEBIAN_9_64", |
| 1480 |
"DOS", |
| 1481 |
"ECOMSTATION", |
| 1482 |
"ECOMSTATION_2", |
| 1483 |
"FEDORA", |
| 1484 |
"FEDORA_64", |
| 1485 |
"FREEBSD", |
| 1486 |
"FREEBSD_11", |
| 1487 |
"FREEBSD_11_64", |
| 1488 |
"FREEBSD_12", |
| 1489 |
"FREEBSD_12_64", |
| 1490 |
"FREEBSD_13", |
| 1491 |
"FREEBSD_13_64", |
| 1492 |
"FREEBSD_14", |
| 1493 |
"FREEBSD_14_64", |
| 1494 |
"FREEBSD_64", |
| 1495 |
"GENERIC_LINUX", |
| 1496 |
"MANDRAKE", |
| 1497 |
"MANDRIVA", |
| 1498 |
"MANDRIVA_64", |
| 1499 |
"NETWARE_4", |
| 1500 |
"NETWARE_5", |
| 1501 |
"NETWARE_6", |
| 1502 |
"NLD_9", |
| 1503 |
"OES", |
| 1504 |
"OPENSERVER_5", |
| 1505 |
"OPENSERVER_6", |
| 1506 |
"OPENSUSE", |
| 1507 |
"OPENSUSE_64", |
| 1508 |
"ORACLE_LINUX", |
| 1509 |
"ORACLE_LINUX_6", |
| 1510 |
"ORACLE_LINUX_64", |
| 1511 |
"ORACLE_LINUX_6_64", |
| 1512 |
"ORACLE_LINUX_7", |
| 1513 |
"ORACLE_LINUX_7_64", |
| 1514 |
"ORACLE_LINUX_8_64", |
| 1515 |
"ORACLE_LINUX_9_64", |
| 1516 |
"OS2", |
| 1517 |
"OTHER", |
| 1518 |
"OTHER_24X_LINUX", |
| 1519 |
"OTHER_24X_LINUX_64", |
| 1520 |
"OTHER_26X_LINUX", |
| 1521 |
"OTHER_26X_LINUX_64", |
| 1522 |
"OTHER_3X_LINUX", |
| 1523 |
"OTHER_3X_LINUX_64", |
| 1524 |
"OTHER_4X_LINUX", |
| 1525 |
"OTHER_4X_LINUX_64", |
| 1526 |
"OTHER_5X_LINUX", |
| 1527 |
"OTHER_5X_LINUX_64", |
| 1528 |
"OTHER_64", |
| 1529 |
"OTHER_6X_LINUX", |
| 1530 |
"OTHER_6X_LINUX_64", |
| 1531 |
"OTHER_LINUX", |
| 1532 |
"OTHER_LINUX_64", |
| 1533 |
"REDHAT", |
| 1534 |
"RHEL_2", |
| 1535 |
"RHEL_3", |
| 1536 |
"RHEL_3_64", |
| 1537 |
"RHEL_4", |
| 1538 |
"RHEL_4_64", |
| 1539 |
"RHEL_5", |
| 1540 |
"RHEL_5_64", |
| 1541 |
"RHEL_6", |
| 1542 |
"RHEL_6_64", |
| 1543 |
"RHEL_7", |
| 1544 |
"RHEL_7_64", |
| 1545 |
"RHEL_8_64", |
| 1546 |
"RHEL_9_64", |
| 1547 |
"ROCKYLINUX_64", |
| 1548 |
"SJDS", |
| 1549 |
"SLES", |
| 1550 |
"SLES_10", |
| 1551 |
"SLES_10_64", |
| 1552 |
"SLES_11", |
| 1553 |
"SLES_11_64", |
| 1554 |
"SLES_12", |
| 1555 |
"SLES_12_64", |
| 1556 |
"SLES_15_64", |
| 1557 |
"SLES_16_64", |
| 1558 |
"SLES_64", |
| 1559 |
"SOLARIS_10", |
| 1560 |
"SOLARIS_10_64", |
| 1561 |
"SOLARIS_11_64", |
| 1562 |
"SOLARIS_6", |
| 1563 |
"SOLARIS_7", |
| 1564 |
"SOLARIS_8", |
| 1565 |
"SOLARIS_9", |
| 1566 |
"SUSE", |
| 1567 |
"SUSE_64", |
| 1568 |
"TURBO_LINUX", |
| 1569 |
"TURBO_LINUX_64", |
| 1570 |
"UBUNTU", |
| 1571 |
"UBUNTU_64", |
| 1572 |
"UNIXWARE_7", |
| 1573 |
"VMKERNEL", |
| 1574 |
"VMKERNEL_5", |
| 1575 |
"VMKERNEL_6", |
| 1576 |
"VMKERNEL_65", |
| 1577 |
"VMKERNEL_7", |
| 1578 |
"VMKERNEL_8", |
| 1579 |
"VMWARE_PHOTON_64", |
| 1580 |
"WINDOWS_11_64", |
| 1581 |
"WINDOWS_12_64", |
| 1582 |
"WINDOWS_7", |
| 1583 |
"WINDOWS_7_64", |
| 1584 |
"WINDOWS_7_SERVER_64", |
| 1585 |
"WINDOWS_8", |
| 1586 |
"WINDOWS_8_64", |
| 1587 |
"WINDOWS_8_SERVER_64", |
| 1588 |
"WINDOWS_9", |
| 1589 |
"WINDOWS_9_64", |
| 1590 |
"WINDOWS_9_SERVER_64", |
| 1591 |
"WINDOWS_HYPERV", |
| 1592 |
"WINDOWS_SERVER_2019", |
| 1593 |
"WINDOWS_SERVER_2021", |
| 1594 |
"WINDOWS_SERVER_2025", |
| 1595 |
"WIN_2000_ADV_SERV", |
| 1596 |
"WIN_2000_PRO", |
| 1597 |
"WIN_2000_SERV", |
| 1598 |
"WIN_31", |
| 1599 |
"WIN_95", |
| 1600 |
"WIN_98", |
| 1601 |
"WIN_LONGHORN", |
| 1602 |
"WIN_LONGHORN_64", |
| 1603 |
"WIN_ME", |
| 1604 |
"WIN_NET_BUSINESS", |
| 1605 |
"WIN_NET_DATACENTER", |
| 1606 |
"WIN_NET_DATACENTER_64", |
| 1607 |
"WIN_NET_ENTERPRISE", |
| 1608 |
"WIN_NET_ENTERPRISE_64", |
| 1609 |
"WIN_NET_STANDARD", |
| 1610 |
"WIN_NET_STANDARD_64", |
| 1611 |
"WIN_NET_WEB", |
| 1612 |
"WIN_NT", |
| 1613 |
"WIN_VISTA", |
| 1614 |
"WIN_VISTA_64", |
| 1615 |
"WIN_XP_HOME", |
| 1616 |
"WIN_XP_PRO", |
| 1617 |
"WIN_XP_PRO_64", |
| 1618 |
], |
| 1619 |
} |
| 1620 |
argument_spec["guest_customization_spec"] = {"type": "dict"} |
| 1621 |
argument_spec["hardware_version"] = { |
| 1622 |
"type": "str", |
| 1623 |
"choices": [ |
| 1624 |
"VMX_03", |
| 1625 |
"VMX_04", |
| 1626 |
"VMX_06", |
| 1627 |
"VMX_07", |
| 1628 |
"VMX_08", |
| 1629 |
"VMX_09", |
| 1630 |
"VMX_10", |
| 1631 |
"VMX_11", |
| 1632 |
"VMX_12", |
| 1633 |
"VMX_13", |
| 1634 |
"VMX_14", |
| 1635 |
"VMX_15", |
| 1636 |
"VMX_16", |
| 1637 |
"VMX_17", |
| 1638 |
"VMX_18", |
| 1639 |
"VMX_19", |
| 1640 |
"VMX_20", |
| 1641 |
"VMX_21", |
| 1642 |
], |
| 1643 |
} |
| 1644 |
argument_spec["memory"] = {"type": "dict"} |
| 1645 |
argument_spec["name"] = {"type": "str"} |
| 1646 |
argument_spec["nics"] = {"type": "list", "elements": "dict"} |
| 1647 |
argument_spec["nics_to_update"] = {"type": "dict"} |
| 1648 |
argument_spec["nvme_adapters"] = {"type": "list", "elements": "dict"} |
| 1649 |
argument_spec["parallel_ports"] = {"type": "list", "elements": "dict"} |
| 1650 |
argument_spec["parallel_ports_to_update"] = {"type": "dict"} |
| 1651 |
argument_spec["path"] = {"type": "str"} |
| 1652 |
argument_spec["placement"] = {"type": "dict"} |
| 1653 |
argument_spec["power_on"] = {"type": "bool"} |
| 1654 |
argument_spec["sata_adapters"] = {"type": "list", "elements": "dict"} |
| 1655 |
argument_spec["scsi_adapters"] = {"type": "list", "elements": "dict"} |
| 1656 |
argument_spec["serial_ports"] = {"type": "list", "elements": "dict"} |
| 1657 |
argument_spec["serial_ports_to_update"] = {"type": "dict"} |
| 1658 |
argument_spec["source"] = {"type": "str"} |
| 1659 |
argument_spec["state"] = { |
| 1660 |
"type": "str", |
| 1661 |
"choices": [ |
| 1662 |
"absent", |
| 1663 |
"clone", |
| 1664 |
"instant_clone", |
| 1665 |
"present", |
| 1666 |
"register", |
| 1667 |
"relocate", |
| 1668 |
"unregister", |
| 1669 |
], |
| 1670 |
"default": "present", |
| 1671 |
} |
| 1672 |
argument_spec["storage_policy"] = {"type": "dict"} |
| 1673 |
argument_spec["vm"] = {"type": "str"} |
| 1674 |
|
| 1675 |
return argument_spec |
| 1676 |
|
| 1677 |
|
| 1678 |
async def main(): |
| 1679 |
required_if = list([]) |
| 1680 |
|
| 1681 |
module_args = prepare_argument_spec() |
| 1682 |
module = AnsibleModule( |
| 1683 |
argument_spec=module_args, required_if=required_if, supports_check_mode=False |
| 1684 |
) |
| 1685 |
if not module.params["vcenter_hostname"]: |
| 1686 |
module.fail_json("vcenter_hostname cannot be empty") |
| 1687 |
if not module.params["vcenter_username"]: |
| 1688 |
module.fail_json("vcenter_username cannot be empty") |
| 1689 |
if not module.params["vcenter_password"]: |
| 1690 |
module.fail_json("vcenter_password cannot be empty") |
| 1691 |
try: |
| 1692 |
session = await open_session( |
| 1693 |
vcenter_hostname=module.params["vcenter_hostname"], |
| 1694 |
vcenter_username=module.params["vcenter_username"], |
| 1695 |
vcenter_password=module.params["vcenter_password"], |
| 1696 |
validate_certs=module.params["vcenter_validate_certs"], |
| 1697 |
log_file=module.params["vcenter_rest_log_file"], |
| 1698 |
) |
| 1699 |
except Exception as err: |
| 1700 |
if hasattr(err, "get_message"): |
| 1701 |
module.fail_json(err.get_message()) |
| 1702 |
else: |
| 1703 |
module.fail_json(str(err)) |
| 1704 |
result = await entry_point(module, session) |
| 1705 |
module.exit_json(**result) |
| 1706 |
|
| 1707 |
|
| 1708 |
# template: default_module.j2 |
| 1709 |
def build_url(params): |
| 1710 |
return ("https://{vcenter_hostname}" "/api/vcenter/vm").format(**params) |
| 1711 |
|
| 1712 |
|
| 1713 |
async def entry_point(module, session): |
| 1714 |
|
| 1715 |
if module.params["state"] == "present": |
| 1716 |
if "_create" in globals(): |
| 1717 |
operation = "create" |
| 1718 |
else: |
| 1719 |
operation = "update" |
| 1720 |
elif module.params["state"] == "absent": |
| 1721 |
operation = "delete" |
| 1722 |
else: |
| 1723 |
operation = module.params["state"] |
| 1724 |
|
| 1725 |
func = globals()["_" + operation] |
| 1726 |
|
| 1727 |
return await func(module.params, session) |
| 1728 |
|
| 1729 |
|
| 1730 |
async def _clone(params, session): |
| 1731 |
|
| 1732 |
lookup_url = per_id_url = build_url(params) |
| 1733 |
uniquity_keys = ["vm"] |
| 1734 |
comp_func = None |
| 1735 |
|
| 1736 |
async def lookup_with_filters(params, session, url): |
| 1737 |
search_filter = "" |
| 1738 |
|
| 1739 |
if "name" not in params: |
| 1740 |
return |
| 1741 |
async with session.get(f"{url}?names={params['name']}{search_filter}") as resp: |
| 1742 |
_json = await resp.json() |
| 1743 |
if isinstance(_json, list) and len(_json) == 1: |
| 1744 |
return await get_device_info(session, url, _json[0]["vm"]) |
| 1745 |
|
| 1746 |
_json = None |
| 1747 |
|
| 1748 |
if params["vm"]: |
| 1749 |
_json = await get_device_info(session, build_url(params), params["vm"]) |
| 1750 |
|
| 1751 |
if not _json and (uniquity_keys or comp_func): |
| 1752 |
_json = await exists( |
| 1753 |
params, |
| 1754 |
session, |
| 1755 |
url=lookup_url, |
| 1756 |
uniquity_keys=uniquity_keys, |
| 1757 |
per_id_url=per_id_url, |
| 1758 |
comp_func=comp_func, |
| 1759 |
) |
| 1760 |
|
| 1761 |
if not _json: |
| 1762 |
_json = await lookup_with_filters(params, session, build_url(params)) |
| 1763 |
|
| 1764 |
if _json: |
| 1765 |
if "value" not in _json: # 7.0.2+ |
| 1766 |
_json = {"value": _json} |
| 1767 |
if "_update" in globals(): |
| 1768 |
params["vm"] = _json["id"] |
| 1769 |
return await globals()["_update"](params, session) |
| 1770 |
|
| 1771 |
return await update_changed_flag(_json, 200, "get") |
| 1772 |
|
| 1773 |
payload = prepare_payload(params, PAYLOAD_FORMAT["clone"]) |
| 1774 |
_url = ("https://{vcenter_hostname}" "/api/vcenter/vm?action=clone").format( |
| 1775 |
**params |
| 1776 |
) |
| 1777 |
async with session.post(_url, json=payload, **session_timeout(params)) as resp: |
| 1778 |
if resp.status == 500: |
| 1779 |
text = await resp.text() |
| 1780 |
raise Exception(f"Request has failed: status={resp.status}, {text}") |
| 1781 |
try: |
| 1782 |
if resp.headers["Content-Type"] == "application/json": |
| 1783 |
_json = await resp.json() |
| 1784 |
except KeyError: |
| 1785 |
_json = {} |
| 1786 |
|
| 1787 |
if (resp.status in [200, 201]) and "error" not in _json: |
| 1788 |
if isinstance(_json, str): # 7.0.2 and greater |
| 1789 |
_id = _json # TODO: fetch the object |
| 1790 |
elif isinstance(_json, dict) and "value" not in _json: |
| 1791 |
_id = list(_json["value"].values())[0] |
| 1792 |
elif isinstance(_json, dict) and "value" in _json: |
| 1793 |
_id = _json["value"] |
| 1794 |
_json_device_info = await get_device_info(session, _url, _id) |
| 1795 |
if _json_device_info: |
| 1796 |
_json = _json_device_info |
| 1797 |
|
| 1798 |
return await update_changed_flag(_json, resp.status, "clone") |
| 1799 |
|
| 1800 |
|
| 1801 |
async def _create(params, session): |
| 1802 |
|
| 1803 |
lookup_url = per_id_url = build_url(params) |
| 1804 |
uniquity_keys = ["vm"] |
| 1805 |
comp_func = None |
| 1806 |
|
| 1807 |
async def lookup_with_filters(params, session, url): |
| 1808 |
search_filter = "" |
| 1809 |
|
| 1810 |
if "name" not in params: |
| 1811 |
return |
| 1812 |
async with session.get(f"{url}?names={params['name']}{search_filter}") as resp: |
| 1813 |
_json = await resp.json() |
| 1814 |
if isinstance(_json, list) and len(_json) == 1: |
| 1815 |
return await get_device_info(session, url, _json[0]["vm"]) |
| 1816 |
|
| 1817 |
_json = None |
| 1818 |
|
| 1819 |
if params["vm"]: |
| 1820 |
_json = await get_device_info(session, build_url(params), params["vm"]) |
| 1821 |
|
| 1822 |
if not _json and (uniquity_keys or comp_func): |
| 1823 |
_json = await exists( |
| 1824 |
params, |
| 1825 |
session, |
| 1826 |
url=lookup_url, |
| 1827 |
uniquity_keys=uniquity_keys, |
| 1828 |
per_id_url=per_id_url, |
| 1829 |
comp_func=comp_func, |
| 1830 |
) |
| 1831 |
|
| 1832 |
if not _json: |
| 1833 |
_json = await lookup_with_filters(params, session, build_url(params)) |
| 1834 |
|
| 1835 |
if _json: |
| 1836 |
if "value" not in _json: # 7.0.2+ |
| 1837 |
_json = {"value": _json} |
| 1838 |
if "_update" in globals(): |
| 1839 |
params["vm"] = _json["id"] |
| 1840 |
return await globals()["_update"](params, session) |
| 1841 |
|
| 1842 |
return await update_changed_flag(_json, 200, "get") |
| 1843 |
|
| 1844 |
payload = prepare_payload(params, PAYLOAD_FORMAT["create"]) |
| 1845 |
_url = ("https://{vcenter_hostname}" "/api/vcenter/vm").format(**params) |
| 1846 |
async with session.post(_url, json=payload, **session_timeout(params)) as resp: |
| 1847 |
if resp.status == 500: |
| 1848 |
text = await resp.text() |
| 1849 |
raise Exception(f"Request has failed: status={resp.status}, {text}") |
| 1850 |
try: |
| 1851 |
if resp.headers["Content-Type"] == "application/json": |
| 1852 |
_json = await resp.json() |
| 1853 |
except KeyError: |
| 1854 |
_json = {} |
| 1855 |
|
| 1856 |
if (resp.status in [200, 201]) and "error" not in _json: |
| 1857 |
if isinstance(_json, str): # 7.0.2 and greater |
| 1858 |
_id = _json # TODO: fetch the object |
| 1859 |
elif isinstance(_json, dict) and "value" not in _json: |
| 1860 |
_id = list(_json["value"].values())[0] |
| 1861 |
elif isinstance(_json, dict) and "value" in _json: |
| 1862 |
_id = _json["value"] |
| 1863 |
_json_device_info = await get_device_info(session, _url, _id) |
| 1864 |
if _json_device_info: |
| 1865 |
_json = _json_device_info |
| 1866 |
|
| 1867 |
return await update_changed_flag(_json, resp.status, "create") |
| 1868 |
|
| 1869 |
|
| 1870 |
async def _delete(params, session): |
| 1871 |
_in_query_parameters = PAYLOAD_FORMAT["delete"]["query"].keys() |
| 1872 |
payload = prepare_payload(params, PAYLOAD_FORMAT["delete"]) |
| 1873 |
subdevice_type = get_subdevice_type("/api/vcenter/vm/{vm}") |
| 1874 |
if subdevice_type and not params[subdevice_type]: |
| 1875 |
_json = await exists(params, session, build_url(params)) |
| 1876 |
if _json: |
| 1877 |
params[subdevice_type] = _json["id"] |
| 1878 |
_url = ("https://{vcenter_hostname}" "/api/vcenter/vm/{vm}").format( |
| 1879 |
**params |
| 1880 |
) + gen_args(params, _in_query_parameters) |
| 1881 |
async with session.delete(_url, json=payload, **session_timeout(params)) as resp: |
| 1882 |
try: |
| 1883 |
if resp.headers["Content-Type"] == "application/json": |
| 1884 |
_json = await resp.json() |
| 1885 |
except KeyError: |
| 1886 |
_json = {} |
| 1887 |
return await update_changed_flag(_json, resp.status, "delete") |
| 1888 |
|
| 1889 |
|
| 1890 |
async def _instant_clone(params, session): |
| 1891 |
|
| 1892 |
lookup_url = per_id_url = build_url(params) |
| 1893 |
uniquity_keys = ["vm"] |
| 1894 |
comp_func = None |
| 1895 |
|
| 1896 |
async def lookup_with_filters(params, session, url): |
| 1897 |
search_filter = "" |
| 1898 |
|
| 1899 |
if "name" not in params: |
| 1900 |
return |
| 1901 |
async with session.get(f"{url}?names={params['name']}{search_filter}") as resp: |
| 1902 |
_json = await resp.json() |
| 1903 |
if isinstance(_json, list) and len(_json) == 1: |
| 1904 |
return await get_device_info(session, url, _json[0]["vm"]) |
| 1905 |
|
| 1906 |
_json = None |
| 1907 |
|
| 1908 |
if params["vm"]: |
| 1909 |
_json = await get_device_info(session, build_url(params), params["vm"]) |
| 1910 |
|
| 1911 |
if not _json and (uniquity_keys or comp_func): |
| 1912 |
_json = await exists( |
| 1913 |
params, |
| 1914 |
session, |
| 1915 |
url=lookup_url, |
| 1916 |
uniquity_keys=uniquity_keys, |
| 1917 |
per_id_url=per_id_url, |
| 1918 |
comp_func=comp_func, |
| 1919 |
) |
| 1920 |
|
| 1921 |
if not _json: |
| 1922 |
_json = await lookup_with_filters(params, session, build_url(params)) |
| 1923 |
|
| 1924 |
if _json: |
| 1925 |
if "value" not in _json: # 7.0.2+ |
| 1926 |
_json = {"value": _json} |
| 1927 |
if "_update" in globals(): |
| 1928 |
params["vm"] = _json["id"] |
| 1929 |
return await globals()["_update"](params, session) |
| 1930 |
|
| 1931 |
return await update_changed_flag(_json, 200, "get") |
| 1932 |
|
| 1933 |
payload = prepare_payload(params, PAYLOAD_FORMAT["instant_clone"]) |
| 1934 |
_url = ("https://{vcenter_hostname}" "/api/vcenter/vm?action=instant-clone").format( |
| 1935 |
**params |
| 1936 |
) |
| 1937 |
async with session.post(_url, json=payload, **session_timeout(params)) as resp: |
| 1938 |
if resp.status == 500: |
| 1939 |
text = await resp.text() |
| 1940 |
raise Exception(f"Request has failed: status={resp.status}, {text}") |
| 1941 |
try: |
| 1942 |
if resp.headers["Content-Type"] == "application/json": |
| 1943 |
_json = await resp.json() |
| 1944 |
except KeyError: |
| 1945 |
_json = {} |
| 1946 |
|
| 1947 |
if (resp.status in [200, 201]) and "error" not in _json: |
| 1948 |
if isinstance(_json, str): # 7.0.2 and greater |
| 1949 |
_id = _json # TODO: fetch the object |
| 1950 |
elif isinstance(_json, dict) and "value" not in _json: |
| 1951 |
_id = list(_json["value"].values())[0] |
| 1952 |
elif isinstance(_json, dict) and "value" in _json: |
| 1953 |
_id = _json["value"] |
| 1954 |
_json_device_info = await get_device_info(session, _url, _id) |
| 1955 |
if _json_device_info: |
| 1956 |
_json = _json_device_info |
| 1957 |
|
| 1958 |
return await update_changed_flag(_json, resp.status, "instant_clone") |
| 1959 |
|
| 1960 |
|
| 1961 |
async def _register(params, session): |
| 1962 |
_in_query_parameters = PAYLOAD_FORMAT["register"]["query"].keys() |
| 1963 |
payload = prepare_payload(params, PAYLOAD_FORMAT["register"]) |
| 1964 |
subdevice_type = get_subdevice_type("/api/vcenter/vm?action=register") |
| 1965 |
if subdevice_type and not params[subdevice_type]: |
| 1966 |
_json = await exists(params, session, build_url(params)) |
| 1967 |
if _json: |
| 1968 |
params[subdevice_type] = _json["id"] |
| 1969 |
_url = ( |
| 1970 |
"https://{vcenter_hostname}" |
| 1971 |
# aa |
| 1972 |
"/api/vcenter/vm?action=register" |
| 1973 |
).format(**params) + gen_args(params, _in_query_parameters) |
| 1974 |
async with session.post(_url, json=payload, **session_timeout(params)) as resp: |
| 1975 |
try: |
| 1976 |
if resp.headers["Content-Type"] == "application/json": |
| 1977 |
_json = await resp.json() |
| 1978 |
except KeyError: |
| 1979 |
_json = {} |
| 1980 |
if "value" not in _json: # 7.0.2 |
| 1981 |
_json = {"value": _json} |
| 1982 |
|
| 1983 |
return await update_changed_flag(_json, resp.status, "register") |
| 1984 |
|
| 1985 |
|
| 1986 |
async def _relocate(params, session): |
| 1987 |
_in_query_parameters = PAYLOAD_FORMAT["relocate"]["query"].keys() |
| 1988 |
payload = prepare_payload(params, PAYLOAD_FORMAT["relocate"]) |
| 1989 |
subdevice_type = get_subdevice_type("/api/vcenter/vm/{vm}?action=relocate") |
| 1990 |
if subdevice_type and not params[subdevice_type]: |
| 1991 |
_json = await exists(params, session, build_url(params)) |
| 1992 |
if _json: |
| 1993 |
params[subdevice_type] = _json["id"] |
| 1994 |
_url = ( |
| 1995 |
"https://{vcenter_hostname}" |
| 1996 |
# aa |
| 1997 |
"/api/vcenter/vm/{vm}?action=relocate" |
| 1998 |
).format(**params) + gen_args(params, _in_query_parameters) |
| 1999 |
async with session.post(_url, json=payload, **session_timeout(params)) as resp: |
| 2000 |
try: |
| 2001 |
if resp.headers["Content-Type"] == "application/json": |
| 2002 |
_json = await resp.json() |
| 2003 |
except KeyError: |
| 2004 |
_json = {} |
| 2005 |
if "value" not in _json: # 7.0.2 |
| 2006 |
_json = {"value": _json} |
| 2007 |
|
| 2008 |
return await update_changed_flag(_json, resp.status, "relocate") |
| 2009 |
|
| 2010 |
|
| 2011 |
async def _unregister(params, session): |
| 2012 |
_in_query_parameters = PAYLOAD_FORMAT["unregister"]["query"].keys() |
| 2013 |
payload = prepare_payload(params, PAYLOAD_FORMAT["unregister"]) |
| 2014 |
subdevice_type = get_subdevice_type("/api/vcenter/vm/{vm}?action=unregister") |
| 2015 |
if subdevice_type and not params[subdevice_type]: |
| 2016 |
_json = await exists(params, session, build_url(params)) |
| 2017 |
if _json: |
| 2018 |
params[subdevice_type] = _json["id"] |
| 2019 |
_url = ( |
| 2020 |
"https://{vcenter_hostname}" |
| 2021 |
# aa |
| 2022 |
"/api/vcenter/vm/{vm}?action=unregister" |
| 2023 |
).format(**params) + gen_args(params, _in_query_parameters) |
| 2024 |
async with session.post(_url, json=payload, **session_timeout(params)) as resp: |
| 2025 |
try: |
| 2026 |
if resp.headers["Content-Type"] == "application/json": |
| 2027 |
_json = await resp.json() |
| 2028 |
except KeyError: |
| 2029 |
_json = {} |
| 2030 |
if "value" not in _json: # 7.0.2 |
| 2031 |
_json = {"value": _json} |
| 2032 |
|
| 2033 |
return await update_changed_flag(_json, resp.status, "unregister") |
| 2034 |
|
| 2035 |
|
| 2036 |
if __name__ == "__main__": |
| 2037 |
import asyncio |
| 2038 |
|
| 2039 |
current_loop = asyncio.new_event_loop() |
| 2040 |
try: |
| 2041 |
asyncio.set_event_loop(current_loop) |
| 2042 |
current_loop.run_until_complete(main()) |
| 2043 |
finally: |
| 2044 |
current_loop.close() |