summaryrefslogtreecommitdiffstats
path: root/src/software/openlmi/software/LMI_SoftwarePackage.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/software/openlmi/software/LMI_SoftwarePackage.py')
-rw-r--r--src/software/openlmi/software/LMI_SoftwarePackage.py55
1 files changed, 24 insertions, 31 deletions
diff --git a/src/software/openlmi/software/LMI_SoftwarePackage.py b/src/software/openlmi/software/LMI_SoftwarePackage.py
index 2395dca..01956ce 100644
--- a/src/software/openlmi/software/LMI_SoftwarePackage.py
+++ b/src/software/openlmi/software/LMI_SoftwarePackage.py
@@ -27,14 +27,12 @@ Instruments the CIM class LMI_SoftwarePackage
"""
import itertools
-import datetime
import pywbem
+import yum
from pywbem.cim_provider2 import CIMProvider2
-from openlmi.software.util.common import *
+from openlmi.software.util.common import (YumDB, SoftwarePackage)
-pkg2model = SoftwarePackage.pkg2model_wrapper('root/cimv2', "LMI_SoftwarePackage")
-
-class LMI_SoftwarePackage(CIMProvider2):
+class LMI_SoftwarePackage(CIMProvider2): #pylint: disable=R0904
"""Instrument the CIM class LMI_SoftwarePackage
RPM package installed on particular computer system with YUM (The
@@ -42,7 +40,7 @@ class LMI_SoftwarePackage(CIMProvider2):
"""
- def __init__ (self, env):
+ def __init__(self, env):
logger = env.get_logger()
logger.log_debug('Initializing provider %s from %s' \
% (self.__class__.__name__, __file__))
@@ -76,7 +74,8 @@ class LMI_SoftwarePackage(CIMProvider2):
with YumDB.getInstance(env):
pkg = SoftwarePackage.object_path2pkg(env, model.path, 'all')
- return pkg2model(env, pkg, keys_only=False, model=model)
+ return SoftwarePackage.pkg2model(env, pkg,
+ keys_only=False, model=model)
def enum_instances(self, env, model, keys_only):
"""Enumerate instances.
@@ -112,13 +111,13 @@ class LMI_SoftwarePackage(CIMProvider2):
'SoftwareElementState': None, 'Name': None,
'SoftwareElementID': None})
- with YumDB.getInstance(env) as yb:
+ with YumDB.getInstance(env) as ydb:
# get all packages
- pl = yb.doPackageLists('all', showdups=True)
- pl = itertools.chain(pl.installed, pl.available)
+ pkglist = ydb.doPackageLists('all', showdups=True)
+ pkglist = itertools.chain(pkglist.installed, pkglist.available)
# NOTE: available ∩ installed = ∅
- for pkg in sorted(pl, key=lambda a:a.evra):
- yield pkg2model(env, pkg, keys_only, model)
+ for pkg in sorted(pkglist, key=lambda a:a.evra):
+ yield SoftwarePackage.pkg2model(env, pkg, keys_only, model)
def set_instance(self, env, instance, modify_existing):
"""Return a newly created or modified instance.
@@ -150,9 +149,7 @@ class LMI_SoftwarePackage(CIMProvider2):
logger = env.get_logger()
logger.log_debug('Entering %s.set_instance()' \
% self.__class__.__name__)
- # TODO create or modify the instance
- raise pywbem.CIMError(pywbem.CIM_ERR_NOT_SUPPORTED) # Remove to implement
- return instance
+ raise pywbem.CIMError(pywbem.CIM_ERR_NOT_SUPPORTED)
def delete_instance(self, env, instance_name):
"""Delete an instance.
@@ -179,9 +176,6 @@ class LMI_SoftwarePackage(CIMProvider2):
logger = env.get_logger()
logger.log_debug('Entering %s.delete_instance()' \
% self.__class__.__name__)
-
- # TODO delete the resource
- # Remove to implement
raise pywbem.CIMError(pywbem.CIM_ERR_NOT_SUPPORTED)
def cim_method_install(self, env, object_name):
@@ -219,22 +213,23 @@ class LMI_SoftwarePackage(CIMProvider2):
logger.log_debug('Entering %s.cim_method_install()' \
% self.__class__.__name__)
- with YumDB.getInstance(env) as yb:
+ with YumDB.getInstance(env) as ydb:
# get available packages
pkg = SoftwarePackage.object_path2pkg_search(env, object_name)
out_params = [ pywbem.CIMParameter('Installed', type='reference') ]
if isinstance(pkg, yum.rpmsack.RPMInstalledPackage):
- out_params[0].value = pkg2model(env, pkg, True)
+ out_params[0].value = SoftwarePackage.pkg2model(env, pkg, True)
return (self.Values.Install.Already_installed, out_params)
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))
- out_params[0].value = pkg2model(env, pkg, True, object_name)
+ out_params[0].value = SoftwarePackage.pkg2model(
+ env, pkg, True, object_name)
out_params[0].value['SoftwareElementState'] = \
self.Values.SoftwareElementState.Executable
return (self.Values.Install.Successful_installation, out_params)
@@ -271,18 +266,17 @@ class LMI_SoftwarePackage(CIMProvider2):
logger.log_debug('Entering %s.cim_method_remove()' \
% self.__class__.__name__)
- with YumDB.getInstance(env) as yb:
+ with YumDB.getInstance(env) as ydb:
pkg = SoftwarePackage.object_path2pkg(env, object_name, 'all')
if isinstance(pkg, yum.rpmsack.RPMInstalledPackage):
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)
rval = self.Values.Remove.Successful_removal
else:
rval = self.Values.Remove.Not_installed
- #rval = # TODO (type pywbem.Uint32 self.Values.Remove)
return (rval, [])
class Values(object):
@@ -515,8 +509,7 @@ class LMI_SoftwarePackage(CIMProvider2):
## end of class LMI_SoftwarePackage
-## get_providers() for associating CIM Class Name to python provider class name
-
def get_providers(env):
+ """Associates CIM Class Name to python provider class name"""
lmi_softwarepackage_prov = LMI_SoftwarePackage(env)
return {'LMI_SoftwarePackage': lmi_softwarepackage_prov}