Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.

Bug 1131932

Summary: Updating VM description using python API do not work
Product: Red Hat Enterprise Virtualization Manager Reporter: Petter Reinholdtsen <pere>
Component: ovirt-engine-sdkAssignee: Juan Hernández <juan.hernandez>
Status: CLOSED DUPLICATE QA Contact: Shai Revivo <srevivo>
Severity: high Docs Contact:
Priority: unspecified    
Version: 3.4.1-1CC: acathrow, ecohen, gklein, iheim, oramraz, Rhev-m-bugs, yeylon
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2014-08-20 12:25:17 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Petter Reinholdtsen 2014-08-20 10:55:50 UTC
This issue is similar to bug #1091688.

Since version 3.3 of RHEV, our script to create virtual machines
automatically have been unable to update the VM description.  This is
rather fatal for us, as we use the description to track the VM status
across several stages in the creation process.

This is how the script fail:

[root@rhev ~]# kinit -t /etc/sssd/krb5.keytab -k linuxsystem_ro@REALM; RHEVPASSWD=$(cat /etc/rhevm/admin-password) ./x.py -d
Found vm test.uio.no (under installation)
updating description
error: Updating VMs failed: 
status: 400
reason: Bad Request
detail: If Domain supplied, Domain name expected to be supplied as well.
Traceback (most recent call last):
  File "./x.py", line 94, in <module>
    main()
  File "./x.py", line 91, in main
    raise e
ovirtsdk.infrastructure.errors.RequestError: 
status: 400
reason: Bad Request
detail: If Domain supplied, Domain name expected to be supplied as well.
[root@rhevm ~]# 


This is the script in question.  Note, the failing call is the
vm.update() call after setting the description.


#!/usr/bin/python
# Run like this to avoid interactivity
# kinit -t /etc/sssd/krb5.keytab -k linuxsystem_ro@REALM; \
#   RHEVPASSWD=secret ./virtcreate

from ovirtsdk.api import API
from ovirtsdk.xml import params
import getpass
import time
import os.path
import syslog

##################
# HARDCODED VALUES
##################

cafile = '/etc/pki/ovirt-engine/ca.pem'
if not os.path.isfile(cafile):
    cafile = 'ca.pem'

rhevurl = "https://rhevm.uio.no:443/api"
rhevuser = "admin@internal"

def log(level, msg):
    global options
    limit = 1
    sysloglevel = syslog.LOG_INFO
    if options is not None and options.debug:
        limit = 2
    if 0 == level:
        sysloglevel = syslog.LOG_ERR
    if level <= limit:
        syslog.syslog(sysloglevel, msg)
        print msg

def main():
    global options
    rhevpwd = os.environ['RHEVPASSWD']
    if not rhevpwd:
        rhevpwd = getpass.getpass("RHEV password for %s: " % rhevuser)

    from optparse import OptionParser

    parser = OptionParser()
    parser.add_option("-d", "--debug",
                      action="store_true", dest="debug", default=False,
                      help="enable debug output")
    
    (options, args) = parser.parse_args()
    syslog.openlog("virtcreate-cleanup", 0, syslog.LOG_CRON)

    rhev = API(url=rhevurl,
               username=rhevuser, password=rhevpwd,
               ca_file=cafile)
    try:
        # Check if they already exist as virtual machines
        vms = rhev.vms.list()
        for vm in vms:
            hostname = vm.get_name()
            description = vm.get_description()
            log(2, 'Found vm %s (%s)' % (hostname, description))
            if 'under installation' == description:
                log(2, 'updating description')
                vm.description = 'installation running'
                vm = vm.update()
    except Exception, e:
        log(0, "error: Updating VMs failed: %s" % str(e))
        pass
    # Clean up
    rhev.disconnect()
    raise e

if __name__ == "__main__":
    main()

Can we get access to the RPM mentioned in bug #1091688 to test if it
solve our problem?

-- 
Happy hacking
Petter Reinholdtsen

Comment 1 Juan Hernández 2014-08-20 11:17:04 UTC
I'd suggest to workaround the issue by forcing an empty domain name during the update of the VM:

  # This is a workaround for bug 1091688, it can be removed
  # once version 3.5 of the rhevm-sdk-python package is
  # available:
  domain = vm.get_domain()
  if domain is not None and domain.get_name() is None:
    domain.set_name("")
  vm.update()

This should work with the current version of the RPM.

The 3.5 version of the RPM isn't in good shape at the moment, so I don't recommend using it before we release it.

Please try this workaround, if it works then we will close this bug as duplicate of bug 1091688.

Comment 2 Petter Reinholdtsen 2014-08-20 11:33:01 UTC
The workaround worked for me.  Thank you!

Comment 3 Juan Hernández 2014-08-20 12:25:17 UTC

*** This bug has been marked as a duplicate of bug 1091688 ***