Este contenido no está disponible en el idioma seleccionado.
2.14. Example: Creating a Virtual Machine using Python
Virtual machine creation is performed in several steps. The first step, covered here, is to create the virtual machine object itself.
Example 2.13. Creating a virtual machine using Python
This Python example creates a virtual machine named
These options are combined into a virtual machine parameter object, before using the
vm1
. The virtual machine in this example:
- Must have 512 MB of memory, expressed in bytes.
vm_memory = 512 * 1024 * 1024
vm_memory = 512 * 1024 * 1024
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Must be attached to the
Default
cluster, and therefore theDefault
data center.vm_cluster = api.clusters.get(name="Default")
vm_cluster = api.clusters.get(name="Default")
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Must be based on the default
Blank
template.vm_template = api.templates.get(name="Blank")
vm_template = api.templates.get(name="Blank")
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Must boot from the virtual hard disk drive.
vm_os = params.OperatingSystem(boot=[params.Boot(dev="hd")])
vm_os = params.OperatingSystem(boot=[params.Boot(dev="hd")])
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
add
method of the vms
collection to create the virtual machine itself.
If the
add
request is successful then the script will output:
Virtual machine 'vm1' added.
Virtual machine 'vm1' added.