Ce contenu n'est pas disponible dans la langue sélectionnée.
2.15. Example: Creating a Virtual Machine Storage Disk using Python
To ensure a newly created virtual machine has access to persistent storage you must create and attach a disk.
Example 2.14. Creating a virtual machine storage disk using Python
This Python example creates an 8 GB
These options are combined into a disk parameter object, before using the
virtio
disk drive and attaches it to the virtual machine named vm1
. The disk in this example:
- must be stored on the storage domain named
data1
,disk_storage_domain = params.StorageDomains(storage_domain=[api.storagedomains.get(name="data1")])
disk_storage_domain = params.StorageDomains(storage_domain=[api.storagedomains.get(name="data1")])
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - must be 8 GB in size,
disk_size = 8*1024*1024
disk_size = 8*1024*1024
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - must be a
system
type disk (as opposed todata
),disk_type = "system"
disk_type = "system"
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - must be
virtio
storage device,disk_interface = "virtio"
disk_interface = "virtio"
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - must be stored in
cow
format, anddisk_format = "cow"
disk_format = "cow"
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - must be marked as a usable boot device.
disk_bootable = True
disk_bootable = True
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
add
method of the virtual machine's disks
collection to create the disk itself.
If the
add
request is successful then the script will output:
Disk 'vm1_Disk1' added to 'vm1'.
Disk 'vm1_Disk1' added to 'vm1'.