diff options
Diffstat (limited to 'src/software/openlmi/software/LMI_SoftwareInstalledPackage.py')
-rw-r--r-- | src/software/openlmi/software/LMI_SoftwareInstalledPackage.py | 104 |
1 files changed, 56 insertions, 48 deletions
diff --git a/src/software/openlmi/software/LMI_SoftwareInstalledPackage.py b/src/software/openlmi/software/LMI_SoftwareInstalledPackage.py index 51d15b6..b59121d 100644 --- a/src/software/openlmi/software/LMI_SoftwareInstalledPackage.py +++ b/src/software/openlmi/software/LMI_SoftwareInstalledPackage.py @@ -28,12 +28,14 @@ Instruments the CIM class LMI_SoftwareInstalledPackage import itertools import pywbem +import yum from pywbem.cim_provider2 import CIMProvider2 -from openlmi.software.LMI_SoftwarePackage import pkg2model, LMI_SoftwarePackage -from openlmi.software.LMI_SoftwareFileCheck import filecheck2model -from openlmi.software.util.common import * +from openlmi.software.LMI_SoftwarePackage import LMI_SoftwarePackage +from openlmi.software.util import common +from openlmi.software.util.common import ( + YumDB, SoftwarePackage, SoftwareFileCheck) -class LMI_SoftwareInstalledPackage(CIMProvider2): +class LMI_SoftwareInstalledPackage(CIMProvider2): #pylint: disable=R0904 """Instrument the CIM class LMI_SoftwareInstalledPackage The InstalledSoftwareElement association allows the identification of @@ -79,10 +81,11 @@ class LMI_SoftwareInstalledPackage(CIMProvider2): if not "System" in model: raise pywbem.CIMError(pywbem.CIM_ERR_NOT_FOUND, "Missing System property.") - check_computer_system_op(env, model['System']) + common.check_computer_system_op(env, model['System']) + model['System'] = common.get_computer_system_op() with YumDB.getInstance(env): pkg = SoftwarePackage.object_path2pkg(env, model['Software']) - model['Software'] = pkg2model(env, pkg, True) + model['Software'] = SoftwarePackage.pkg2model(env, pkg, True) return model def enum_instances(self, env, model, keys_only): @@ -120,19 +123,20 @@ class LMI_SoftwareInstalledPackage(CIMProvider2): yum_package_path = pywbem.CIMInstanceName("LMI_SoftwarePackage", namespace=model.path.namespace, host=model.path.host) - model['System'] = get_computer_system_op() - with YumDB.getInstance(env) as yb: - for rpm in yb.rpmdb: - iname = pkg2model(env, rpm, True, yum_package_path) + model['System'] = common.get_computer_system_op() + with YumDB.getInstance(env) as ydb: + for pkg in ydb.rpmdb: + iname = SoftwarePackage.pkg2model(env, pkg, + True, yum_package_path) model['Software'] = iname if keys_only: yield model else: try: yield self.get_instance(env, model) - except pywbem.CIMError, (num, msg): - if num not in (pywbem.CIM_ERR_NOT_FOUND, - pywbem.CIM_ERR_ACCESS_DENIED): + except pywbem.CIMError as error: + if error.args[0] not in (pywbem.CIM_ERR_NOT_FOUND, + pywbem.CIM_ERR_ACCESS_DENIED): raise def set_instance(self, env, instance, modify_existing): @@ -177,27 +181,28 @@ class LMI_SoftwareInstalledPackage(CIMProvider2): if not "System" in instance: raise pywbem.CIMError(pywbem.CIM_ERR_NOT_FOUND, "Missing System property.") - check_computer_system_op(env, instance['System']) + common.check_computer_system_op(env, instance['System']) - with YumDB.getInstance(env) as yb: - pkg = SoftwarePackage.object_path2pkg_search(env, instance['Software']) + with YumDB.getInstance(env) as ydb: + pkg = SoftwarePackage.object_path2pkg_search( + env, instance['Software']) if isinstance(pkg, yum.rpmsack.RPMInstalledPackage): raise pywbem.CIMError(pywbem.CIM_ERR_ALREADY_EXISTS, "Package is already installed.") logger.log_info('installing package {}'.format(pkg.nevra)) # install - yb.install(pkg) - yb.buildTransaction() - yb.processTransaction() + ydb.install(pkg) + ydb.buildTransaction() + ydb.processTransaction() logger.log_info('package installed'.format(pkg.nevra)) # return instance - pkg_iname = pkg2model(env, pkg, True) + pkg_iname = SoftwarePackage.pkg2model(env, pkg, True) pkg_iname["SoftwareElementState"] = \ LMI_SoftwarePackage.Values.SoftwareElementState.Executable instance["Software"] = pkg_iname - return LMI_SoftwareInstalledPackage(env).get_instance(env, instance) + return self.get_instance(env, instance) def delete_instance(self, env, instance_name): """Delete an instance. @@ -231,13 +236,14 @@ class LMI_SoftwareInstalledPackage(CIMProvider2): if not "System" in instance_name: raise pywbem.CIMError(pywbem.CIM_ERR_NOT_FOUND, "Missing System property.") - check_computer_system_op(env, instance_name['System']) - with YumDB.getInstance(env) as yb: - pkg = SoftwarePackage.object_path2pkg(env, instance_name["Software"]) + common.check_computer_system_op(env, instance_name['System']) + with YumDB.getInstance(env) as ydb: + pkg = SoftwarePackage.object_path2pkg( + env, instance_name["Software"]) logger.log_info('removing package "%s"' % pkg.nevra) - yb.remove(pkg) - yb.buildTransaction() - yb.processTransaction() + ydb.remove(pkg) + ydb.buildTransaction() + ydb.processTransaction() logger.log_info('package "%s" removed' % pkg.nevra) def references(self, env, object_name, model, result_class_name, role, @@ -302,14 +308,14 @@ class LMI_SoftwareInstalledPackage(CIMProvider2): logger = env.get_logger() logger.log_debug('Entering %s.references()' \ % self.__class__.__name__) - ch = env.get_cimom_handle() + cimhandle = env.get_cimom_handle() # If you want to get references for free, implemented in terms # of enum_instances, just leave the code below unaltered. - if ch.is_subclass(object_name.namespace, + if cimhandle.is_subclass(object_name.namespace, sub=object_name.classname, super='CIM_ComputerSystem') or \ - ch.is_subclass(object_name.namespace, + cimhandle.is_subclass(object_name.namespace, sub=object_name.classname, super='LMI_SoftwarePackage'): return self.simple_refs(env, object_name, model, @@ -363,16 +369,18 @@ class LMI_SoftwareInstalledPackage(CIMProvider2): if not "System" in object_name: raise pywbem.CIMError(pywbem.CIM_ERR_NOT_FOUND, "Missing System property.") - with YumDB.getInstance(env) as yb: + with YumDB.getInstance(env): pkg = SoftwarePackage.object_path2pkg(env, object_name['Software']) csum = SoftwareFileCheck.pkg_checksum_type(pkg) vpkg = yum.packages._RPMVerifyPackage( pkg, pkg.hdr.fiFromHeader(), csum, [], True) for vpf in vpkg: - fc = SoftwareFileCheck.test_file(env, csum, vpf) - if SoftwareFileCheck.filecheck_passed(fc): continue - failed.append(filecheck2model( - vpkg, vpf.filename, env, keys_only=True, fc=fc)) + file_check = SoftwareFileCheck.test_file(env, csum, vpf) + if SoftwareFileCheck.filecheck_passed(file_check): + continue + failed.append(SoftwareFileCheck.filecheck2model( + vpkg, vpf.filename, env, keys_only=True, + file_check=file_check)) out_params = [ pywbem.CIMParameter('Failed', type='reference', value=failed) ] return ( getattr(self.Values.CheckIntegrity, @@ -433,9 +441,9 @@ class LMI_SoftwareInstalledPackage(CIMProvider2): if not "System" in object_name: raise pywbem.CIMError(pywbem.CIM_ERR_NOT_FOUND, "Missing System property.") - check_computer_system_op(env, object_name['System']) + common.check_computer_system_op(env, object_name['System']) - with YumDB.getInstance(env) as yb: + with YumDB.getInstance(env) as ydb: orig = SoftwarePackage.object_path2pkg(env, object_name['Software']) evr_str = [] @@ -443,7 +451,7 @@ class LMI_SoftwareInstalledPackage(CIMProvider2): ('epoch', param_epoch), ('version', param_version), ('release', param_release)): - evr_str.append("%s(%s)"%(name,param)) + evr_str.append("%s(%s)"%(name, param)) if len(evr_str): evr_str = "specific "+'-'.join(evr_str) else: @@ -452,9 +460,9 @@ class LMI_SoftwareInstalledPackage(CIMProvider2): logger.log_info('trying to update to %s of package \"%s\"' % (evr_str, object_name["Software"]["Name"])) - pl = yb.doPackageLists('all', showdups=True) - exact,_,_ = yum.packages.parsePackages( - itertools.chain(pl.available, pl.installed), + pkglist = ydb.doPackageLists('all', showdups=True) + exact, _, _ = yum.packages.parsePackages( + itertools.chain(pkglist.available, pkglist.installed), [orig.name]) # NOTE: available ∩ installed = ∅ exact = sorted(exact, key=lambda a:a.evra) @@ -469,18 +477,18 @@ class LMI_SoftwareInstalledPackage(CIMProvider2): 'could not find any matching available package') raise pywbem.CIMError(pywbem.CIM_ERR_NOT_FOUND) out_params = [pywbem.CIMParameter('Installed', type='reference', - value=pkg2model(env, pkg, True))] + value=SoftwarePackage.pkg2model(env, pkg, True))] if orig.evra == pkg.evra: logger.log_info('already up to date') return (self.Values.Update.Already_newest, out_params) - yb.update(update_to=True, + ydb.update(update_to=True, name=pkg.name, epoch=pkg.epoch, version=pkg.version, release=pkg.release) - yb.buildTransaction() - yb.processTransaction() + ydb.buildTransaction() + ydb.processTransaction() logger.log_info('package {} updated to: {}'.format( orig.name, pkg.evra)) @@ -502,8 +510,8 @@ class LMI_SoftwareInstalledPackage(CIMProvider2): ## end of class LMI_SoftwareInstalledPackage -## get_providers() for associating CIM Class Name to python provider class name def get_providers(env): - lmi_softwareinstalledpackage_prov = LMI_SoftwareInstalledPackage(env) - return {'LMI_SoftwareInstalledPackage': lmi_softwareinstalledpackage_prov} + """Associates CIM Class Name to python provider class name""" + lmi_sip_prov = LMI_SoftwareInstalledPackage(env) + return {'LMI_SoftwareInstalledPackage': lmi_sip_prov} |