[Users] python-sdk : how to modify a vm to "Run on" a "Specific" host and set "Migration Options

karthik S karthik.lubdup at gmail.com
Fri Dec 27 21:54:10 UTC 2013


Dear Users,

I am karthik, based in Mountain View, CA. I have been using python ovirtsdk
for QA Automation tests for RHEV-M for past two months. My knowledge on
ovirtsdk is intermittent at this stage.

I want to do the below actions that we do on rhev-M using python ovirtsdk.

On, RHEV-M UI
============
1) right click a offline VM >> Edit >> Host >> "Run On:" >> Specific >.
choose a hostname
2) right click a offline VM >> Edit >> Host >>  "Migration Options:" >> "Do
not allow migration"

python Code:
==========

1) The VM was imported from export domain to my storage_domain using the
code


    def import_vm(self, source_vm_name, dest_vm_name, storage_domain_name,
rhev_host_name=None, cluster_name="Default",  async=False):
        """
            Import VM From a Export domain into your storage domain
        """
        timeoutSec=1800
        pollInterval=2

        exportStorageDomain =
self.api.storagedomains.list(type_="export")[0]
        actionParams = params.Action(

storage_domain=self.api.storagedomains.get(storage_domain_name),

cluster=self.api.clusters.get("Default"),
                                     clone=1,
                                     vm = params.VM (name=dest_vm_name,

snapshots=params.Snapshots(collapse_snapshots=1),
                                                     disks =
params.Disks(clone = 1),
                                                     host =
params.Host(name=rhev_host_name)
                                    ))

        exportStorageDomain.vms.get(source_vm_name).import_vm(actionParams)
        start = time.time()
        while self.api.vms.get(dest_vm_name).status.state != 'down':
                if time.time() - start > timeoutSec:
                    raise Exception("Timed out (%s) waiting for %s to
obtain down status" % (timeoutSec, vm_name))
                time.sleep(pollInterval)

        return self.api.vms.get(name=dest_vm_name)[0]


Issue :  Upon import, this method did not set the "Run as" to the specified
host  but "Run as" was set to "Any host in the cluster".  Am I missing
something ?

2) Secondly, I tried modifying the VM "Run as" hostname with the below code

>>> api = API (url = "xx" , username ="XX", pasword ="XX", ca_file = "ca")
>>> vm_obj = api.vms.list(name="test_vm_101")[0]
>>> vm_obj.set_host="rhev1"
>>> vm_obj.update()

This did not help either. Seems I am missing something..


3) finally how to set " "Migration Options" ?


Your help would appreciated and will help me to get greater understanding
of the SDK itself.

Thanks,
Karthik
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ovirt.org/pipermail/users/attachments/20131227/a3a25870/attachment-0001.html>


More information about the Users mailing list