Update disk alias by using ovirtsdk4

Hello list! I have been trying to rename a disk alias that defaults to "some_template_name-Disk1" to something more logical by using ovirtsdk4 (in my example to "vm2_disk_0"). On the list itself, I saw a couple of examples for older version of SDK. Basically, I am trying to create a VM and then update its properties, notably "alias" attribute that can be found in types.Disk. The first portion of the code works well (vm provisioning), but second one (alias update) does not, causing the TypeError exception. Obviously, I am doing something wrong here. I have spent most of the time trying to figure out how to actually do this. I would kindly ask for some hint. Thank you in advance! Regards, Branimir ******************************* # create a vm vms_service = connection.system_service().vms_service() vms_service.add( types.Vm( # --- vm name name='vm2', # --- vCpus cpu=types.Cpu( topology=types.CpuTopology(cores=2, sockets=1) ), # --- memory memory = 512*1024*1024, # -- oVirt cluster cluster = types.Cluster( name='cluster_1', ), # -- template to use template = types.Template( name='centos7-tmplt-compute-node-v1'), # -- boot device os = types.OperatingSystem(boot=types.Boot(devices=[types.BootDevice.HD])), ), ) # update the vm in terms of disk name vm = vms_service.list(search='name=vm2')[0] vm_service = vms_service.vm_service(vm.id) updated_vm = vm_service.update( types.Vm( disk_attachment = types.Disk(alias='vm2_disk_0') ) )

Try to update the DiskAttachment: vm = vms_service.list(search='name=NFSVM')[0] disk_attachments_service = vms_service.vm_service(vm.id ).disk_attachments_service() #here I take the first one, works because I have only one disk disk_attachment = disk_attachments_service.list()[0] disk_attachment_service = disk_attachments_service.attachment_service( disk_attachment.id) disk_attachment_service.update( types.DiskAttachment( disk=types.Disk( name='NewDiskName', ), ), ) On Thu, Aug 23, 2018 at 2:53 AM, <branimirp@gmail.com> wrote:
Hello list!
I have been trying to rename a disk alias that defaults to "some_template_name-Disk1" to something more logical by using ovirtsdk4 (in my example to "vm2_disk_0"). On the list itself, I saw a couple of examples for older version of SDK. Basically, I am trying to create a VM and then update its properties, notably "alias" attribute that can be found in types.Disk. The first portion of the code works well (vm provisioning), but second one (alias update) does not, causing the TypeError exception. Obviously, I am doing something wrong here. I have spent most of the time trying to figure out how to actually do this. I would kindly ask for some hint.
Thank you in advance!
Regards,
Branimir
*******************************
# create a vm vms_service = connection.system_service().vms_service()
vms_service.add( types.Vm(
# --- vm name name='vm2',
# --- vCpus cpu=types.Cpu( topology=types.CpuTopology(cores=2, sockets=1) ),
# --- memory memory = 512*1024*1024,
# -- oVirt cluster cluster = types.Cluster( name='cluster_1', ),
# -- template to use template = types.Template( name='centos7-tmplt-compute-node-v1'),
# -- boot device os = types.OperatingSystem(boot=types.Boot(devices=[types. BootDevice.HD])), ), )
# update the vm in terms of disk name vm = vms_service.list(search='name=vm2')[0] vm_service = vms_service.vm_service(vm.id)
updated_vm = vm_service.update( types.Vm( disk_attachment = types.Disk(alias='vm2_disk_0') ) ) _______________________________________________ Users mailing list -- users@ovirt.org To unsubscribe send an email to users-leave@ovirt.org Privacy Statement: https://www.ovirt.org/site/privacy-policy/ oVirt Code of Conduct: https://www.ovirt.org/community/about/community- guidelines/ List Archives: https://lists.ovirt.org/archives/list/users@ovirt.org/ message/JWUFND4JXIJMZ4HY5LPBSKIBBN4GEL5V/

Hi Fred! Thank you very much for your help! It is working! I only added the following (as suggested in https://access.redhat.com/documentation/en-us/red_hat_virtualization/4.2/pdf...; page 12) in order to wait for a vm to go from "image locked" to "down" state. vm_service = vms_service.vm_service(vm.id) while True: time.sleep(5) vm_s = vm_service.get() if vm_s.status == types.VmStatus.DOWN: break Thank you once more! Regards, Branimir
participants (2)
-
branimirp@gmail.com
-
Fred Rolland