我是ovirt的新手,正在尝试增加已连接到VM的磁盘的大小。这里有一个很好的例子:Ovirt SDK例子。
唯一的问题是,在本例中,我们首先连接磁盘,然后调整其大小。这样,我就可以访问稍后用于更新大小的disk_attachment。对我来说,这不是一个选项,因为我不会自己连接磁盘,因为它是从模板自动发生的。
//先连接磁盘
disk_attachment = disk_attachments_service.add(
types.DiskAttachment(
disk=types.Disk(
name='mydisk',
description='my disk',
format=types.DiskFormat.COW,
provisioned_size=10 * 2**30,
storage_domains=[
types.StorageDomain(
name='bs-scsi-012',
),
],
),
interface=types.DiskInterface.VIRTIO,
bootable=False,
active=True,
),
)
//更新
# Find the service that manages the disk attachment that was added in the
# previous step:
disk_attachment_service = disk_attachments_service.attachment_service(disk_attachment.id)
有没有一种方法可以让我访问disk_attachment.id,这样我就可以启动更新操作,或者有没有其他方法可以实现同样的操作?
如果需要查找磁盘附件id,可以使用此SDK示例。这个列出了虚拟机磁盘及其一些参数,包括它们的id。
一旦您有了所需的磁盘id,您就可以使用以下代码(基于您剪切的示例(:
# Locate the virtual machines service and use it to find the virtual
# machine:
vms_service = connection.system_service().vms_service()
vm = vms_service.list(search='name=vm1')[0]
# Locate the disk attachments service and use it to find the revelant
# disk attachment:
disk_attachments_service = vms_service.vm_service(vm.id).disk_attachments_service()
disk_attachment = disk_attachments_service.list(search='id=<the-disk-id>')[0]
disk_attachment_service = disk_attachments_service.attachment_service(disk_attachment.id)
# Extend the disk size to 3 GiB.
disk_attachment_service.update(
types.DiskAttachment(
disk=types.Disk(
provisioned_size=3 * 2**30,
),
),
)
disks_service = connection.system_service().disks_service()
disk_service = disks_service.disk_service(disk_attachment.disk.id)
# Wait till the disk is OK:
while True:
time.sleep(5)
disk = disk_service.get()
if disk.status == types.DiskStatus.OK:
break
# Close the connection to the server:
connection.close()
我希望它能有所帮助。