summaryrefslogtreecommitdiffstats
path: root/src/yum/providers/LMI_YumPackage.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/yum/providers/LMI_YumPackage.py')
-rw-r--r--src/yum/providers/LMI_YumPackage.py200
1 files changed, 105 insertions, 95 deletions
diff --git a/src/yum/providers/LMI_YumPackage.py b/src/yum/providers/LMI_YumPackage.py
index 427e7fa..3b93c86 100644
--- a/src/yum/providers/LMI_YumPackage.py
+++ b/src/yum/providers/LMI_YumPackage.py
@@ -32,11 +32,11 @@ from util.common import *
pkg2model = YumPackage.pkg2model_wrapper('root/cimv2', "LMI_YumPackage")
class LMI_YumPackage(CIMProvider2):
- """Instrument the CIM class LMI_YumPackage
+ """Instrument the CIM class LMI_YumPackage
RPM package installed on particular computer system with YUM (The
Yellowdog Updated, Modified) package manager.
-
+
"""
def __init__ (self, env):
@@ -49,47 +49,47 @@ class LMI_YumPackage(CIMProvider2):
Keyword arguments:
env -- Provider Environment (pycimmb.ProviderEnvironment)
- model -- A template of the pywbem.CIMInstance to be returned. The
- key properties are set on this instance to correspond to the
+ model -- A template of the pywbem.CIMInstance to be returned. The
+ key properties are set on this instance to correspond to the
instanceName that was requested. The properties of the model
- are already filtered according to the PropertyList from the
+ are already filtered according to the PropertyList from the
request. Only properties present in the model need to be
- given values. If you prefer, you can set all of the
- values, and the instance will be filtered for you.
+ given values. If you prefer, you can set all of the
+ values, and the instance will be filtered for you.
Possible Errors:
CIM_ERR_ACCESS_DENIED
- CIM_ERR_INVALID_PARAMETER (including missing, duplicate, unrecognized
+ CIM_ERR_INVALID_PARAMETER (including missing, duplicate, unrecognized
or otherwise incorrect parameters)
- CIM_ERR_NOT_FOUND (the CIM Class does exist, but the requested CIM
+ CIM_ERR_NOT_FOUND (the CIM Class does exist, but the requested CIM
Instance does not exist in the specified namespace)
CIM_ERR_FAILED (some other unspecified error occurred)
"""
-
+
logger = env.get_logger()
logger.log_debug('Entering %s.get_instance()' \
% self.__class__.__name__)
with YumDB.getInstance(env):
pkg = YumPackage.object_path2pkg(env, model.path, 'all')
- return pkg2model(pkg, env, keys_only=False, model=model)
+ return pkg2model(env, pkg, keys_only=False, model=model)
def enum_instances(self, env, model, keys_only):
"""Enumerate instances.
The WBEM operations EnumerateInstances and EnumerateInstanceNames
- are both mapped to this method.
+ are both mapped to this method.
This method is a python generator
Keyword arguments:
env -- Provider Environment (pycimmb.ProviderEnvironment)
- model -- A template of the pywbem.CIMInstances to be generated.
- The properties of the model are already filtered according to
- the PropertyList from the request. Only properties present in
- the model need to be given values. If you prefer, you can
- always set all of the values, and the instance will be filtered
- for you.
+ model -- A template of the pywbem.CIMInstances to be generated.
+ The properties of the model are already filtered according to
+ the PropertyList from the request. Only properties present in
+ the model need to be given values. If you prefer, you can
+ always set all of the values, and the instance will be filtered
+ for you.
keys_only -- A boolean. True if only the key properties should be
set on the generated instances.
@@ -101,43 +101,43 @@ class LMI_YumPackage(CIMProvider2):
logger = env.get_logger()
logger.log_debug('Entering %s.enum_instances()' \
% self.__class__.__name__)
-
+
# Prime model.path with knowledge of the keys, so key values on
# the CIMInstanceName (model.path) will automatically be set when
- # we set property values on the model.
+ # we set property values on the model.
model.path.update({'TargetOperatingSystem': None, 'Version': None,
'SoftwareElementState': None, 'Name': None,
'SoftwareElementID': None})
-
+
with YumDB.getInstance(env) as yb:
# get all packages
pl = yb.doPackageLists('all', showdups=True)
pl = itertools.chain(pl.installed, pl.available)
# NOTE: available ∩ installed = ∅
for pkg in sorted(pl, key=lambda a:a.evra):
- yield pkg2model(pkg, env, keys_only, model)
+ yield pkg2model(env, pkg, keys_only, model)
def set_instance(self, env, instance, modify_existing):
"""Return a newly created or modified instance.
Keyword arguments:
env -- Provider Environment (pycimmb.ProviderEnvironment)
- instance -- The new pywbem.CIMInstance. If modifying an existing
- instance, the properties on this instance have been filtered by
+ instance -- The new pywbem.CIMInstance. If modifying an existing
+ instance, the properties on this instance have been filtered by
the PropertyList from the request.
modify_existing -- True if ModifyInstance, False if CreateInstance
- Return the new instance. The keys must be set on the new instance.
+ Return the new instance. The keys must be set on the new instance.
Possible Errors:
CIM_ERR_ACCESS_DENIED
CIM_ERR_NOT_SUPPORTED
- CIM_ERR_INVALID_PARAMETER (including missing, duplicate, unrecognized
+ CIM_ERR_INVALID_PARAMETER (including missing, duplicate, unrecognized
or otherwise incorrect parameters)
- CIM_ERR_ALREADY_EXISTS (the CIM Instance already exists -- only
+ CIM_ERR_ALREADY_EXISTS (the CIM Instance already exists -- only
valid if modify_existing is False, indicating that the operation
was CreateInstance)
- CIM_ERR_NOT_FOUND (the CIM Instance does not exist -- only valid
+ CIM_ERR_NOT_FOUND (the CIM Instance does not exist -- only valid
if modify_existing is True, indicating that the operation
was ModifyInstance)
CIM_ERR_FAILED (some other unspecified error occurred)
@@ -156,22 +156,22 @@ class LMI_YumPackage(CIMProvider2):
Keyword arguments:
env -- Provider Environment (pycimmb.ProviderEnvironment)
- instance_name -- A pywbem.CIMInstanceName specifying the instance
+ instance_name -- A pywbem.CIMInstanceName specifying the instance
to delete.
Possible Errors:
CIM_ERR_ACCESS_DENIED
CIM_ERR_NOT_SUPPORTED
CIM_ERR_INVALID_NAMESPACE
- CIM_ERR_INVALID_PARAMETER (including missing, duplicate, unrecognized
+ CIM_ERR_INVALID_PARAMETER (including missing, duplicate, unrecognized
or otherwise incorrect parameters)
- CIM_ERR_INVALID_CLASS (the CIM Class does not exist in the specified
+ CIM_ERR_INVALID_CLASS (the CIM Class does not exist in the specified
namespace)
- CIM_ERR_NOT_FOUND (the CIM Class does exist, but the requested CIM
+ CIM_ERR_NOT_FOUND (the CIM Class does exist, but the requested CIM
Instance does not exist in the specified namespace)
CIM_ERR_FAILED (some other unspecified error occurred)
- """
+ """
logger = env.get_logger()
logger.log_debug('Entering %s.delete_instance()' \
@@ -185,11 +185,11 @@ class LMI_YumPackage(CIMProvider2):
"""Implements LMI_YumPackage.Install()
Will install available package.
-
+
Keyword arguments:
env -- Provider Environment (pycimmb.ProviderEnvironment)
- object_name -- A pywbem.CIMInstanceName or pywbem.CIMCLassName
- specifying the object on which the method Update()
+ object_name -- A pywbem.CIMInstanceName or pywbem.CIMCLassName
+ specifying the object on which the method Update()
should be invoked.
Returns a two-tuple containing the return value (type pywbem.Uint32 self.Values.Install)
@@ -197,17 +197,17 @@ class LMI_YumPackage(CIMProvider2):
Output parameters:
Installed -- (type REF (pywbem.CIMInstanceName(
- classname='LMI_YumInstalledPackage', ...))
+ classname='LMI_YumInstalledPackage', ...))
The reference to newly installed package, if installation was
successful. Null otherwise.
Possible Errors:
CIM_ERR_ACCESS_DENIED
- CIM_ERR_INVALID_PARAMETER (including missing, duplicate,
+ CIM_ERR_INVALID_PARAMETER (including missing, duplicate,
unrecognized or otherwise incorrect parameters)
- CIM_ERR_NOT_FOUND (the target CIM Class or instance does not
+ CIM_ERR_NOT_FOUND (the target CIM Class or instance does not
exist in the specified namespace)
- CIM_ERR_METHOD_NOT_AVAILABLE (the CIM Server is unable to honor
+ CIM_ERR_METHOD_NOT_AVAILABLE (the CIM Server is unable to honor
the invocation request)
CIM_ERR_FAILED (some other unspecified error occurred)
@@ -216,58 +216,13 @@ class LMI_YumPackage(CIMProvider2):
logger.log_debug('Entering %s.cim_method_install()' \
% self.__class__.__name__)
- # parse and check arguments
- match_props = {} # args for match_pkg
- if object_name['SoftwareElementID']:
- m = re_nevra.match(object_name['SoftwareElementID'])
- if not m:
- raise pywbem.CIMError(pywbem.CIM_ERR_INVALID_PARAMETER,
- "SoftwareElementID could not be parsed.")
- match_props['nevra'] = object_name['SoftwareElementID']
- match_props['name'] = m.group('name')
- else:
- for matchattr, instattr in (
- ('name', 'name'), ('epoch', 'epoch'), ('version', 'ver'),
- ('release', 'rel'), ('arch', 'arch')):
- if object_name.get(matchattr, None):
- match_props[matchattr] = object_name[matchattr]
-
- if not match_props:
- raise pywbem.CIMError(pywbem.CIM_ERR_FAILED,
- "Too few key values given (give at least a Name).")
- if not 'name' in match_props and not 'nevra' in match_props:
- raise pywbem.CIMError(pywbem.CIM_ERR_FAILED,
- "Missing either Name or SoftwareElementID property.")
-
with YumDB.getInstance(env) as yb:
# get available packages
- pl = yb.doPackageLists('all', showdups=True)
- exact,_,_ = yum.packages.parsePackages(
- itertools.chain(pl.available, pl.installed),
- [match_props['name']])
- exact = yum.misc.unique(exact)
- exact_orig = exact
- exact = sorted( [ p for p in exact if match_pkg(p, **match_props) ]
- , key=lambda a: a.evra)
- if len(exact) == 0:
- logger.log_error('could not find any package for query: {}'
- ' in list: {}'
- .format(match_props, [p.nevra for p in exact_orig]))
- raise pywbem.CIMError(pywbem.CIM_ERR_NOT_FOUND,
- "No matching package found.")
+ pkg = YumPackage.object_path2pkg_search(env, object_name)
out_params = [ pywbem.CIMParameter('Installed', type='reference') ]
- for pkg in exact: # check, whether package is already installed
- if yb.rpmdb.installed(po=pkg):
- out_params[0].value = pkg2model(pkg, env, True)
- return (self.Values.Install.Already_installed, out_params)
- if len(exact) > 1: # should not happen
- logger.log_info('found multiple matching packages'
- ' for query: {}'.format(match_props))
- pkg = exact[-1] # select highest version
- else:
- logger.log_debug('exact match found for query: {}'
- .format(match_props))
- pkg = exact[0]
+ if isinstance(pkg, yum.rpmsack.RPMInstalledPackage):
+ out_params[0].value = pkg2model(env, pkg, True)
+ return (self.Values.Install.Already_installed, out_params)
logger.log_info('installing package {}'.format(pkg.nevra))
# install
@@ -277,9 +232,59 @@ class LMI_YumPackage(CIMProvider2):
logger.log_info('package installed'.format(pkg.nevra))
# return object_name
- out_params[0].value = pkg2model(pkg, env, True, object_name)
+ out_params[0].value = pkg2model(env, pkg, True, object_name)
+ # pkg's class is YumAvailablePackage and pkg2model thinks it's
+ # not installed
+ out_params[0].value['SoftwareElementState'] = \
+ self.Values.SoftwareElementState.Executable
return (self.Values.Install.Successful_installation, out_params)
+ def cim_method_remove(self, env, object_name):
+ """Implements LMI_YumPackage.Remove()
+
+ Will uninstall installed package.
+
+ Keyword arguments:
+ env -- Provider Environment (pycimmb.ProviderEnvironment)
+ object_name -- A pywbem.CIMInstanceName or pywbem.CIMCLassName
+ specifying the object on which the method Remove()
+ should be invoked.
+
+ Returns a two-tuple containing the return value (type pywbem.Uint32 self.Values.Remove)
+ and a list of CIMParameter objects representing the output parameters
+
+ Output parameters: none
+
+ Possible Errors:
+ CIM_ERR_ACCESS_DENIED
+ CIM_ERR_INVALID_PARAMETER (including missing, duplicate,
+ unrecognized or otherwise incorrect parameters)
+ CIM_ERR_NOT_FOUND (the target CIM Class or instance does not
+ exist in the specified namespace)
+ CIM_ERR_METHOD_NOT_AVAILABLE (the CIM Server is unable to honor
+ the invocation request)
+ CIM_ERR_FAILED (some other unspecified error occurred)
+
+ """
+
+ logger = env.get_logger()
+ logger.log_debug('Entering %s.cim_method_remove()' \
+ % self.__class__.__name__)
+
+ with YumDB.getInstance(env) as yb:
+ pkg = YumPackage.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()
+ 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):
class DetailedStatus(object):
Not_Available = pywbem.Uint16(0)
@@ -430,6 +435,11 @@ class LMI_YumPackage(CIMProvider2):
Oracle_Enterprise_Linux_64_bit = pywbem.Uint16(109)
eComStation_32_bitx = pywbem.Uint16(110)
+ class Remove(object):
+ Not_installed = pywbem.Uint32(0)
+ Successful_removal = pywbem.Uint32(1)
+ Failed = pywbem.Uint32(2)
+
class CommunicationStatus(object):
Unknown = pywbem.Uint16(0)
Not_Available = pywbem.Uint16(1)
@@ -504,9 +514,9 @@ class LMI_YumPackage(CIMProvider2):
Failed = pywbem.Uint32(2)
## end of class LMI_YumPackage
-
+
## get_providers() for associating CIM Class Name to python provider class name
-
-def get_providers(env):
- lmi_yumpackage_prov = LMI_YumPackage(env)
- return {'LMI_YumPackage': lmi_yumpackage_prov}
+
+def get_providers(env):
+ lmi_yumpackage_prov = LMI_YumPackage(env)
+ return {'LMI_YumPackage': lmi_yumpackage_prov}