summaryrefslogtreecommitdiffstats
path: root/src/yum/providers/LMI_YumInstalledPackage.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/yum/providers/LMI_YumInstalledPackage.py')
-rw-r--r--src/yum/providers/LMI_YumInstalledPackage.py47
1 files changed, 35 insertions, 12 deletions
diff --git a/src/yum/providers/LMI_YumInstalledPackage.py b/src/yum/providers/LMI_YumInstalledPackage.py
index 5a20b3c..915ff2b 100644
--- a/src/yum/providers/LMI_YumInstalledPackage.py
+++ b/src/yum/providers/LMI_YumInstalledPackage.py
@@ -25,7 +25,7 @@ Instruments the CIM class LMI_YumInstalledPackage
import itertools
import pywbem
from pywbem.cim_provider2 import CIMProvider2
-from LMI_YumPackage import pkg2model
+from LMI_YumPackage import pkg2model, LMI_YumPackage
from LMI_YumFileCheck import filecheck2model
from util.common import *
@@ -72,7 +72,7 @@ class LMI_YumInstalledPackage(CIMProvider2):
check_computer_system_op(env, model['System'])
with YumDB.getInstance(env):
pkg = YumPackage.object_path2pkg(env, model['Software'])
- model['Software'] = pkg2model(pkg, env, True)
+ model['Software'] = pkg2model(env, pkg, True)
return model
def enum_instances(self, env, model, keys_only):
@@ -113,7 +113,7 @@ class LMI_YumInstalledPackage(CIMProvider2):
model['System'] = get_computer_system_op()
with YumDB.getInstance(env) as yb:
for rpm in yb.rpmdb:
- iname = pkg2model(rpm, env, True, yum_package_path)
+ iname = pkg2model(env, rpm, True, yum_package_path)
model['Software'] = iname
if keys_only:
yield model
@@ -155,10 +155,33 @@ class LMI_YumInstalledPackage(CIMProvider2):
logger = env.get_logger()
logger.log_debug('Entering %s.set_instance()' \
% self.__class__.__name__)
- # TODO create or modify the instance
- # Remove to implement
- raise pywbem.CIMError(pywbem.CIM_ERR_NOT_SUPPORTED)
- return instance
+
+ # parse and check arguments
+ if modify_existing is True:
+ raise pywbem.CIMError(pywbem.CIM_ERR_NOT_FOUND,
+ "MofifyInstance is not supported")
+
+ check_computer_system_op(env, instance['System'])
+
+ with YumDB.getInstance(env) as yb:
+ pkg = YumPackage.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()
+ logger.log_info('package installed'.format(pkg.nevra))
+
+ # return instance
+ pkg_iname = pkg2model(env, pkg, True)
+ pkg_iname["SoftwareElementState"] = \
+ LMI_YumPackage.Values.SoftwareElementState.Executable
+ instance["Software"] = pkg_iname
+ return LMI_YumInstalledPackage(env).get_instance(env, instance)
def delete_instance(self, env, instance_name):
"""Delete an instance.
@@ -319,10 +342,7 @@ class LMI_YumInstalledPackage(CIMProvider2):
pkg, pkg.hdr.fiFromHeader(), csum, [], True)
for vpf in vpkg:
fc = YumFileCheck.test_file(env, csum, vpf)
- if ( fc.exists
- and all( v[0] == v[1]
- for v in fc if isinstance(v, tuple))):
- continue
+ if YumFileCheck.filecheck_passed(fc): continue
failed.append(filecheck2model(
vpkg, vpf.filename, env, keys_only=True, fc=fc))
out_params = [ pywbem.CIMParameter('Failed', type='reference',
@@ -415,7 +435,7 @@ class LMI_YumInstalledPackage(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(pkg, env, True))]
+ value=pkg2model(env, pkg, True))]
if orig.evra == pkg.evra:
logger.log_info('already up to date')
return (self.Values.Update.Already_newest, out_params)
@@ -430,6 +450,9 @@ class LMI_YumInstalledPackage(CIMProvider2):
logger.log_info('package {} updated to: {}'.format(
orig.name, pkg.evra))
+ out_params[0].value["SoftwareElementState"] = \
+ LMI_YumPackage.Values.SoftwareElementState.Executable
+
return (self.Values.Update.Successful_installation, out_params)
class Values(object):