+
+SUPPORTED_TYPES = ['KVM']
This should work with other guest types as well.
+default_dom = 'test_domain'
+libvirt_em_type_changeset = 737
+
+@do_main(SUPPORTED_TYPES)
+def main():
+ status = FAIL
+ options = main.options
+ curr_cim_rev, changeset = get_provider_version(options.virt, options.ip)
+ if curr_cim_rev < libvirt_em_type_changeset:
+ return SKIP
+
+ emu_types = [0, 1]
+ for exp_emu_type in emu_types:
+ cxml = vxml.get_class(options.virt)(default_dom, emu_type=exp_emu_type)
+ ret = cxml.cim_define(options.ip)
+ if not ret:
+ logger.error("Failed to call DefineSystem()")
+ return FAIL
+
+ drasd= get_typed_class(options.virt,
'DiskResourceAllocationSettingData')
+ try:
+ drasd_list = enumclass.EnumInstances(options.ip, drasd, ret_cim_inst=True)
+ if len(drasd_list) < 1:
+ logger.error("%s returned %i instances, excepted at least
1.",
+ drasd, len(drasd_list))
Need to undefine the guest
here.
+ return FAIL
+ except Exception, detail:
+ logger.error(CIM_ERROR_ENUMERATE, drasd)
+ logger.error("Exception: %s", detail)
Need to undefine the guest here.
+ return FAIL
+
+ for rasd in drasd_list:
+ guest, dev, status = parse_instance_id(rasd['InstanceID'])
+ if status != PASS:
+ logger.error("Unable to parse InstanceID: %s" %
rasd['InstanceID'])
Need to undefine the guest here.
+ return FAIL
+ if guest == default_dom:
+ if rasd['EmulatedType'] == exp_emu_type:
+ status = PASS
+ break
You don't need to break here if you use the raise exception solution
(see below).
+ else:
+ logger.error("EmulatedType Mismatch: got %d, expected
%d",\
+ rasd['EmulatedType'], exp_emu_type)
+ return FAIL
You don't want to have this else statement here. If there are multiple
guests defined, then you will return an error if the first DiskRASD in
the list doesn't belong to our guest.
+ elif rasd == drasd_list[len(drasd_list)-1]:
+ logger.error("The defined guest can not be found")
+ return FAIL
This is an awkward check. Instead, you should define a variable like
found_rasd before the for loop. Once you find a match, set found_rasd
equal to the rasd that matches our guest.
At the end of the loop, if found_rasd is None, then you know a match
wasn't found and an error should be returned.
+
+ cxml.undefine(options.ip)
+
+ return status
+
+if __name__ == "__main__":
+ sys.exit(main())
Since there are so many places where you need to undefine the guest, you
can do the following:
for exp_emu_type in emu_types:
cxml = vxml.get_class(options.virt)(default_dom,
emu_type=exp_emu_type)
ret = cxml.cim_define(options.ip)
if not ret:
logger.error("Failed to call DefineSystem()")
return FAIL
try:
drasd= get_typed_class(options.virt,
'DiskResourceAllocationSettingData')
drasd_list = enumclass.EnumInstances(options.ip, drasd,
ret_cim_inst=True)
if len(drasd_list) < 1:
raise Exception("%s returned %i instances, excepted at
least 1.", drasd, len(drasd_list))
for rasd in drasd_list:
guest, dev, status = parse_instance_id(rasd['InstanceID'])
if status != PASS:
raise Exception("Unable to parse InstanceID: %s" %
rasd['InstanceID'])
if guest == default_dom:
if rasd['EmulatedType'] == exp_emu_type:
status = PASS
except Exception, detail:
logger.error(CIM_ERROR_ENUMERATE, drasd)
logger.error("Exception: %s", detail)
status = FAIL
cxml.undefine(options.ip)
if status != PASS:
return status
--
Kaitlin Rupert
IBM Linux Technology Center
kaitlin(a)linux.vnet.ibm.com