diff options
Diffstat (limited to 'src/software/openlmi/software/LMI_SoftwarePackage.py')
-rw-r--r-- | src/software/openlmi/software/LMI_SoftwarePackage.py | 258 |
1 files changed, 0 insertions, 258 deletions
diff --git a/src/software/openlmi/software/LMI_SoftwarePackage.py b/src/software/openlmi/software/LMI_SoftwarePackage.py deleted file mode 100644 index 17483e8..0000000 --- a/src/software/openlmi/software/LMI_SoftwarePackage.py +++ /dev/null @@ -1,258 +0,0 @@ -# -*- encoding: utf-8 -*- -# Software Management Providers -# -# Copyright (C) 2012 Red Hat, Inc. All rights reserved. -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License, or (at your option) any later version. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -# -# Authors: Michal Minar <miminar@redhat.com> -# - -"""Python Provider for LMI_SoftwarePackage - -Instruments the CIM class LMI_SoftwarePackage - -""" - -import pywbem -from pywbem.cim_provider2 import CIMProvider2 - -from openlmi.common import cmpi_logging -from openlmi.software.core import SoftwarePackage -from openlmi.software.yumdb import YumDB - -class LMI_SoftwarePackage(CIMProvider2): - """Instrument the CIM class LMI_SoftwarePackage - - RPM package installed on particular computer system with YUM (The - Yellowdog Updated, Modified) package manager. - - """ - - def __init__(self, _env): - cmpi_logging.logger.debug('Initializing provider %s from %s' \ - % (self.__class__.__name__, __file__)) - - @cmpi_logging.trace_method - def get_instance(self, env, model): - """Return an instance. - - 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 - instanceName that was requested. 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 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 - or otherwise incorrect parameters) - 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) - - """ - with YumDB.getInstance(): - pkg_info = SoftwarePackage.object_path2pkg(model.path, 'all') - return SoftwarePackage.pkg2model( - pkg_info, keys_only=False, model=model) - - @cmpi_logging.trace_method - def enum_instances(self, env, model, keys_only): - """Enumerate instances. - - The WBEM operations EnumerateInstances and EnumerateInstanceNames - 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. - keys_only -- A boolean. True if only the key properties should be - set on the generated instances. - - Possible Errors: - CIM_ERR_FAILED (some other unspecified error occurred) - - """ - # 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. - model.path.update({'TargetOperatingSystem': None, 'Version': None, - 'SoftwareElementState': None, 'Name': None, - 'SoftwareElementID': None}) - - with YumDB.getInstance() as ydb: - # get all packages - pkglist = ydb.get_package_list('all', - allow_duplicates=True, sort=True) - for pkg in pkglist: - yield SoftwarePackage.pkg2model(pkg, - keys_only=keys_only, model=model) - - @cmpi_logging.trace_method - 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 - 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. - - Possible Errors: - CIM_ERR_ACCESS_DENIED - CIM_ERR_NOT_SUPPORTED - CIM_ERR_INVALID_PARAMETER (including missing, duplicate, unrecognized - or otherwise incorrect parameters) - 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 - if modify_existing is True, indicating that the operation - was ModifyInstance) - CIM_ERR_FAILED (some other unspecified error occurred) - - """ - raise pywbem.CIMError(pywbem.CIM_ERR_NOT_SUPPORTED) - - @cmpi_logging.trace_method - def delete_instance(self, env, instance_name): - """Delete an instance. - - Keyword arguments: - env -- Provider Environment (pycimmb.ProviderEnvironment) - 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 - or otherwise incorrect parameters) - 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 - Instance does not exist in the specified namespace) - CIM_ERR_FAILED (some other unspecified error occurred) - - """ - raise pywbem.CIMError(pywbem.CIM_ERR_NOT_SUPPORTED) - - @cmpi_logging.trace_method - def cim_method_install(self, env, object_name): - """Implements LMI_SoftwarePackage.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() - should be invoked. - - Returns a two-tuple containing the return value ( - type pywbem.Uint32 SoftwarePackage.Values.Install) - and a list of CIMParameter objects representing the output parameters - - Output parameters: - Installed -- (type REF (pywbem.CIMInstanceName( - classname='LMI_SoftwareInstalledPackage', ...)) - 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, - 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) - - """ - with YumDB.getInstance() as ydb: - # get available packages - pkg_info = SoftwarePackage.object_path2pkg_search(object_name) - out_params = [ pywbem.CIMParameter('Installed', type='reference') ] - if pkg_info.installed: - out_params[0].value = SoftwarePackage.pkg2model( - pkg_info, keys_only=True) - return ( SoftwarePackage.Values.Install.Already_installed - , out_params) - - cmpi_logging.logger.info('installing package %s' % pkg_info) - installed_pkg = ydb.install_package(pkg_info) - cmpi_logging.logger.info('package %s installed' % pkg_info) - - out_params[0].value = SoftwarePackage.pkg2model( - installed_pkg, keys_only=True) - return ( SoftwarePackage.Values.Install.Successful_installation - , out_params) - - @cmpi_logging.trace_method - def cim_method_remove(self, env, object_name): - """Implements LMI_SoftwarePackage.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 SoftwarePackage.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) - - """ - with YumDB.getInstance() as ydb: - pkg_info = SoftwarePackage.object_path2pkg(object_name, 'all') - if pkg_info.installed: - cmpi_logging.logger.info('removing package %s' % pkg_info) - ydb.remove_package(pkg_info) - cmpi_logging.logger.info('package %s removed' % pkg_info) - rval = SoftwarePackage.Values.Remove.Successful_removal - else: - rval = SoftwarePackage.Values.Remove.Not_installed - return (rval, []) - |