From 21c2aff50feab6e7c043f0166826ba9df070dfe2 Mon Sep 17 00:00:00 2001 From: Michal Minar Date: Tue, 26 Mar 2013 10:54:27 +0100 Subject: added association provider added provider: * LMI_SoftwareInstallationServiceAffectsElement associating SoftwareInstallationService to Linux_ComputerSystem and SoftwareIdentity --- mof/LMI_Software.mof | 15 ++ mof/LMI_Software.reg | 6 + ...MI_SoftwareInstallationServiceAffectsElement.py | 297 +++++++++++++++++++++ src/software/openlmi/software/cimom_entry.py | 4 + .../core/InstallationServiceAffectsElement.py | 87 ++++++ 5 files changed, 409 insertions(+) create mode 100644 src/software/openlmi/software/LMI_SoftwareInstallationServiceAffectsElement.py create mode 100644 src/software/openlmi/software/core/InstallationServiceAffectsElement.py diff --git a/mof/LMI_Software.mof b/mof/LMI_Software.mof index f00c4af..824659e 100644 --- a/mof/LMI_Software.mof +++ b/mof/LMI_Software.mof @@ -602,6 +602,21 @@ class LMI_HostedSoftwareInstallationService : CIM_HostedService { }; +[Association] +class LMI_SoftwareInstallationServiceAffectsElement : + CIM_ServiceAffectsElement { + + [Override("AffectingElement")] + LMI_SoftwareInstallationService REF AffectingElement; + + [Implemented(true), Override("ElementEffects")] + uint16 ElementEffects[]; + + [Implemented(true), Override("OtherElementEffectsDescriptions")] + string OtherElementEffectsDescriptions[]; + +}; + class LMI_SoftwareInstallationJob : LMI_ConcreteJob { [Implemented(true), Override("InstanceID")] diff --git a/mof/LMI_Software.reg b/mof/LMI_Software.reg index 3491b2a..d8e05ee 100644 --- a/mof/LMI_Software.reg +++ b/mof/LMI_Software.reg @@ -70,6 +70,12 @@ type: instance association namespace: root/cimv2 +[LMI_SoftwareInstallationServiceAffectsElement] + provider: /usr/lib/python2.7/site-packages/openlmi/software/cimom_entry.py + location: pyCmpiProvider + type: instance association + namespace: root/cimv2 + [LMI_SoftwareInstallationJob] provider: /usr/lib/python2.7/site-packages/openlmi/software/cimom_entry.py location: pyCmpiProvider diff --git a/src/software/openlmi/software/LMI_SoftwareInstallationServiceAffectsElement.py b/src/software/openlmi/software/LMI_SoftwareInstallationServiceAffectsElement.py new file mode 100644 index 0000000..4873c9e --- /dev/null +++ b/src/software/openlmi/software/LMI_SoftwareInstallationServiceAffectsElement.py @@ -0,0 +1,297 @@ +# -*- encoding: utf-8 -*- +# Software Management Providers +# +# Copyright (C) 2012-2013 Red Hat, Inc. All rights reserved. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +"""Python Provider for LMI_SoftwareInstallationServiceAffectsElement + +Instruments the CIM class LMI_SoftwareInstallationServiceAffectsElement +""" + +import pywbem +from pywbem.cim_provider2 import CIMProvider2 + +from openlmi.common import cmpi_logging +from openlmi.software.core import ComputerSystem +from openlmi.software.core import Identity +from openlmi.software.core import InstallationService +from openlmi.software.core import InstallationServiceAffectsElement +from openlmi.software.yumdb import YumDB + +def generate_service_referents(env, model, object_name, keys_only): + """ + Used in references method. + """ + InstallationService.check_path(env, object_name, "object_name") + InstallationServiceAffectsElement.fill_model_computer_system( + model, keys_only=keys_only) + yield model + + avail_model = pywbem.CIMInstanceName( + classname="LMI_SoftwareIdentity", + namespace="root/cimv2") + for pkg_info in YumDB.get_instance().get_package_list('available'): + model["AffectedElement"] = InstallationServiceAffectsElement. \ + fill_model_identity(model, pkg_info, + keys_only=keys_only, + identity_model=avail_model) + yield model + +class LMI_SoftwareInstallationServiceAffectsElement(CIMProvider2): + """Instrument the CIM class LMI_SoftwareInstallationServiceAffectsElement + + ServiceAffectsElement represents an association between a Service and + the ManagedElements that might be affected by its execution. + Instantiating this association indicates that running the service may + change, manage, provide functionality for,or pose some burden on the + ManagedElement. This burden might affect performance, throughput, + availability, and so on. + """ + + def __init__ (self, _env): + cmpi_logging.logger.debug('Initializing provider %s from %s' \ + % (self.__class__.__name__, __file__)) + self.values = InstallationServiceAffectsElement.Values + + @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) + """ + InstallationService.check_path_property( + env, model, "AffectingElement") + + ch = env.get_cimom_handle() + + affected = model["AffectedElement"] + if ch.is_subclass(affected.namespace, + sub=affected.classname, super='LMI_SoftwareIdentity'): + pkg_info = Identity.object_path2pkg(affected, kind='available') + InstallationServiceAffectsElement.fill_model_identity( + model, pkg_info, keys_only=False) + elif ch.is_subclass(affected.namespace, + sub=affected.classname, super='Linux_ComputerSystem'): + InstallationServiceAffectsElement.fill_model_computer_system( + model, keys_only=False) + else: + cmpi_logging.logger.error("Unhandled classname: %s", + affected.classname) + raise pywbem.CIMError(pywbem.CIM_ERR_INVALID_PARAMETER, + "Provided AffectedElement not affected by this service.") + + return 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) + """ + model.path.update({'AffectedElement': None, 'AffectingElement': None}) + + model['AffectingElement'] = InstallationService.get_path() + InstallationServiceAffectsElement.fill_model_computer_system( + model, keys_only=keys_only) + yield model + + avail_model = pywbem.CIMInstanceName( + classname="LMI_SoftwareIdentity", + namespace="root/cimv2") + for pkg_info in YumDB.get_instance().get_package_list('available'): + model["AffectedElement"] = InstallationServiceAffectsElement. \ + fill_model_identity(model, pkg_info, keys_only=keys_only, + identity_model=avail_model) + yield 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 references(self, env, object_name, model, result_class_name, role, + result_role, keys_only): + """Instrument Associations. + + All four association-related operations (Associators, AssociatorNames, + References, ReferenceNames) are mapped to this method. + This method is a python generator + + Keyword arguments: + env -- Provider Environment (pycimmb.ProviderEnvironment) + object_name -- A pywbem.CIMInstanceName that defines the source + CIM Object whose associated Objects are to be returned. + model -- A template pywbem.CIMInstance to serve as a model + of the objects to be returned. Only properties present on this + model need to be set. + result_class_name -- If not empty, this string acts as a filter on + the returned set of Instances by mandating that each returned + Instances MUST represent an association between object_name + and an Instance of a Class whose name matches this parameter + or a subclass. + role -- If not empty, MUST be a valid Property name. It acts as a + filter on the returned set of Instances by mandating that each + returned Instance MUST refer to object_name via a Property + whose name matches the value of this parameter. + result_role -- If not empty, MUST be a valid Property name. It acts + as a filter on the returned set of Instances by mandating that + each returned Instance MUST represent associations of + object_name to other Instances, where the other Instances play + the specified result_role in the association (i.e. the + name of the Property in the Association Class that refers to + the Object related to object_name MUST match the value of this + parameter). + keys_only -- A boolean. True if only the key properties should be + set on the generated instances. + + The following diagram may be helpful in understanding the role, + result_role, and result_class_name parameters. + +------------------------+ +-------------------+ + | object_name.classname | | result_class_name | + | ~~~~~~~~~~~~~~~~~~~~~ | | ~~~~~~~~~~~~~~~~~ | + +------------------------+ +-------------------+ + | +-----------------------------------+ | + | | [Association] model.classname | | + | object_name | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | + +--------------+ object_name.classname REF role | | + (CIMInstanceName) | result_class_name REF result_role +------+ + | |(CIMInstanceName) + +-----------------------------------+ + + 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_FAILED (some other unspecified error occurred) + """ + ch = env.get_cimom_handle() + + model.path.update({'AffectedElement': None, 'AffectingElement': None}) + try: + if ( (not role or role.lower() == 'affectingelement') + and ch.is_subclass(object_name.namespace, + sub=object_name.classname, + super="LMI_SoftwareInstallationService")): + for ref in generate_service_referents( + env, model, object_name, keys_only): + yield ref + + elif ( (not role or role.lower() == 'affectedelement') + and ch.is_subclass(object_name.namespace, + sub=object_name.classname, + super="CIM_ComputerSystem")): + ComputerSystem.check_path(env, object_name, "object_name") + model = InstallationServiceAffectsElement. \ + fill_model_computer_system(model, keys_only=keys_only) + model["AffectingElement"] = InstallationService.get_path() + yield model + + elif ( (not role or role.lower() == 'affectedelement') + and ch.is_subclass(object_name.namespace, + sub=object_name.classname, + super="LMI_SoftwareIdentity")): + pkg_info = Identity.object_path2pkg(object_name, "available") + model = InstallationServiceAffectsElement. \ + fill_model_identity(model, pkg_info, + keys_only=keys_only) + model["AffectingElement"] = InstallationService.get_path() + yield model + + except pywbem.CIMError as exc: + if exc.args[0] != pywbem.CIM_ERR_NOT_FOUND: + raise diff --git a/src/software/openlmi/software/cimom_entry.py b/src/software/openlmi/software/cimom_entry.py index b2ccf55..4aa1d44 100644 --- a/src/software/openlmi/software/cimom_entry.py +++ b/src/software/openlmi/software/cimom_entry.py @@ -49,6 +49,8 @@ from openlmi.software. \ LMI_AssociatedSoftwareInstallationServiceCapabilities from openlmi.software.LMI_HostedSoftwareInstallationService import \ LMI_HostedSoftwareInstallationService +from openlmi.software.LMI_SoftwareInstallationServiceAffectsElement import \ + LMI_SoftwareInstallationServiceAffectsElement from openlmi.software.LMI_SoftwareInstallationJob import \ LMI_SoftwareInstallationJob from openlmi.software.LMI_SoftwareMethodResult import \ @@ -86,6 +88,8 @@ def get_providers(env): LMI_AssociatedSoftwareInstallationServiceCapabilities(env), "LMI_HostedSoftwareInstallationService" : \ LMI_HostedSoftwareInstallationService(env), + "LMI_SoftwareInstallationServiceAffectsElement" : \ + LMI_SoftwareInstallationServiceAffectsElement(env), "LMI_SoftwareInstallationJob" : LMI_SoftwareInstallationJob(env), "LMI_SoftwareMethodResult" : LMI_SoftwareMethodResult(env), "LMI_AffectedSoftwareJobElement" : LMI_AffectedSoftwareJobElement(env), diff --git a/src/software/openlmi/software/core/InstallationServiceAffectsElement.py b/src/software/openlmi/software/core/InstallationServiceAffectsElement.py new file mode 100644 index 0000000..93b6c4b --- /dev/null +++ b/src/software/openlmi/software/core/InstallationServiceAffectsElement.py @@ -0,0 +1,87 @@ +# -*- encoding: utf-8 -*- +# Software Management Providers +# +# Copyright (C) 2012-2013 Red Hat, Inc. All rights reserved. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +""" +Just a common functionality related to class +LMI_SoftwareInstallationServiceAffectsElement. +""" + +import pywbem + +from openlmi.common import cmpi_logging +from openlmi.software.core import ComputerSystem +from openlmi.software.core import Identity + +class Values(object): + class ElementEffects(object): + Unknown = pywbem.Uint16(0) + Other = pywbem.Uint16(1) + Exclusive_Use = pywbem.Uint16(2) + Performance_Impact = pywbem.Uint16(3) + Element_Integrity = pywbem.Uint16(4) + Manages = pywbem.Uint16(5) + Consumes = pywbem.Uint16(6) + Enhances_Integrity = pywbem.Uint16(7) + Degrades_Integrity = pywbem.Uint16(8) + Enhances_Performance = pywbem.Uint16(9) + Degrades_Performance = pywbem.Uint16(10) + # DMTF_Reserved = .. + # Vendor_Reserved = 0x8000..0xFFFF + _reverse_map = { + 0 : 'Unknown', + 1 : 'Other', + 2 : 'Exclusive Use', + 3 : 'Performance Impact', + 4 : 'Element Integrity', + 5 : 'Manages', + 6 : 'Consumes', + 7 : 'Enhances Integrity', + 8 : 'Degrades Integrity', + 9 : 'Enhances Performance', + 10 : 'Degrades Performance' + } + +@cmpi_logging.trace_function +def fill_model_computer_system(model, keys_only=True): + """ + Fills model's AffectedElement and all non-key properties. + """ + model["AffectedElement"] = ComputerSystem.get_path() + if not keys_only: + model["ElementEffects"] = [ + Values.ElementEffects.Enhances_Integrity, + Values.ElementEffects.Degrades_Integrity, + Values.ElementEffects.Other, + Values.ElementEffects.Other] + model["OtherElementEffectsDescriptions"] = [ + "Enhances Integrity", + "Degrades Integrity", + "Enhances Functionality", + "Degrades Functionality"] + return model + +@cmpi_logging.trace_function +def fill_model_identity(model, pkg, keys_only=True, identity_model=None): + """ + Fills model's AffectedElement and all non-key properties. + """ + model["AffectedElement"] = Identity.pkg2model(pkg, model=identity_model) + if not keys_only: + model["ElementEffects"] = [Values.ElementEffects.Other] + model["OtherElementEffectsDescriptions"] = ["Allows to install"] + return model -- cgit