summaryrefslogtreecommitdiffstats
path: root/src/python/openlmi/common
diff options
context:
space:
mode:
authorPeter Schiffer <pschiffe@redhat.com>2013-04-26 17:02:26 +0200
committerPeter Schiffer <pschiffe@redhat.com>2013-04-26 17:02:26 +0200
commit8de6807e5017fd5f8be76d6b70d1eb1387c24a62 (patch)
tree9f81978d61ae9a7f160537221a806d665f1c00a5 /src/python/openlmi/common
parent6c60ed63585024726dd43e35130d6cf2679e16fc (diff)
parent338851a8fe5b9dfec1e9695602d501e1fe918912 (diff)
downloadopenlmi-providers-8de6807e5017fd5f8be76d6b70d1eb1387c24a62.tar.gz
openlmi-providers-8de6807e5017fd5f8be76d6b70d1eb1387c24a62.tar.xz
openlmi-providers-8de6807e5017fd5f8be76d6b70d1eb1387c24a62.zip
Merge branch 'master' of ssh://git.fedorahosted.org/git/openlmi-providers
Diffstat (limited to 'src/python/openlmi/common')
-rw-r--r--src/python/openlmi/common/IndicationManager.py60
-rw-r--r--src/python/openlmi/common/JobManager.py134
2 files changed, 137 insertions, 57 deletions
diff --git a/src/python/openlmi/common/IndicationManager.py b/src/python/openlmi/common/IndicationManager.py
index ba0919d..a17703f 100644
--- a/src/python/openlmi/common/IndicationManager.py
+++ b/src/python/openlmi/common/IndicationManager.py
@@ -35,8 +35,9 @@ RE_FILTER_NAME = re.compile(r'^(?P<prefix>lmi:'
r'(?P<class_name>[a-z0-9_]+):)(?P<filter_id>.*)$', re.IGNORECASE)
FILTER_DEFAULTS = {
+ "SourceNamespace" : "root/cimv2",
"SourceNamespaces" : ["root/cimv2"],
- "QueryLanguage" : "CIM:CQL"
+ "QueryLanguage" : "CIM:CQL"
}
@cmpi_logging.trace_function
@@ -511,10 +512,19 @@ class IndicationManager(singletonmixin.Singleton):
self.ensure_filters_installed(class_name=class_name)
@cmpi_logging.trace_method
- def authorize_filter(self, _env, fltr, _ns, _classes, _owner):
+ def authorize_filter(self, _env, fltr, _class_name, _op, _owner):
"""
AuthorizeFilter callback from CIMOM. Call this method from appropriate
- CIMOM callback.
+ CIMOM callback
+
+ It asks us to verify whether this filter is allowed.
+
+ :param fltr: Contains the filter that must be authorized.
+ :param _class_name: (``String``) Contains the class name extracted
+ from the filter FROM clause.
+ :param _op: The name of the class for which monitoring is required.
+ Only the namespace part is set if className is a process indication.
+ :param _owner The owner argument is the destination owner.
"""
with self._access_lock:
res = self._get_matching_filter(fltr)
@@ -526,10 +536,24 @@ class IndicationManager(singletonmixin.Singleton):
return False
@cmpi_logging.trace_method
- def activate_filter(self, _env, fltr, _ns, _classes, first_activation):
+ def activate_filter(self, _env, fltr, _class_name, _class_path,
+ first_activation):
"""
ActivateFilter callback from CIMOM. Call this method from appropriate
CIMOM callback.
+
+ It ask us to begin monitoring a resource. The function shall begin
+ monitoring the resource according to the filter express only.
+
+ :param fltr: The filter argument contains the filter specification
+ for this subscription to become active.
+ :param _class_name: (``String``) The class name extracted from the filter
+ FROM clause.
+ :param _class_path: (``CIMInstanceName``) The name of the class for
+ which monitoring is required. Only the namespace part is set if
+ eventType is a process indication.
+ :param first_activation: (``bool``) Set to true if this is the first
+ filter for className.
"""
with self._access_lock:
if not first_activation:
@@ -541,10 +565,23 @@ class IndicationManager(singletonmixin.Singleton):
make_filter_name(res[0], res[1]), fltr)
@cmpi_logging.trace_method
- def deactivate_filter(self, _env, fltr, _ns, _classes, last_activation):
+ def deactivate_filter(self, _env, fltr, _class_name, _class_path,
+ last_activation):
"""
DeactivateFilter callback from CIMOM. Call this method from appropriate
CIMOM callback.
+
+ Informs us that monitoring using this filter should stop.
+
+ :param fltr: The filter argument contains the filter specification for
+ this subscription to become active.
+ :param class_name: (``String``) The class name extracted from the filter
+ FROM clause.
+ :param class_path: (``CIMInstanceName``) class_path The name of the
+ class for which monitoring is required. Only the namespace part is
+ set if className is a process indication.
+ :last_activation: (``bool``) Set to true if this is the last filter for
+ className.
"""
with self._access_lock:
if not last_activation:
@@ -560,6 +597,11 @@ class IndicationManager(singletonmixin.Singleton):
"""
EnableIndications callback from CIMOM. Call this method from
appropriate CIMOM callback.
+
+ Tells us that indications can now be generated. The MB is now prepared
+ to process indications. The function is normally called by the MB after
+ having done its intialization and processing of persistent subscription
+ requests.
"""
with self._access_lock:
self._enabled = True
@@ -570,6 +612,11 @@ class IndicationManager(singletonmixin.Singleton):
"""
EnableIndications callback from CIMOM. Call this method from
appropriate CIMOM callback.
+
+ Tells us that we should stop generating indications. MB will not accept
+ any indications until enabled again. The function is normally called
+ when the MB is shutting down indication services either temporarily or
+ permanently.
"""
with self._access_lock:
self._enabled = False
@@ -603,7 +650,8 @@ class IndicationManager(singletonmixin.Singleton):
ind['SourceInstance'] = instance
ind['SourceInstanceHost'] = socket.gethostname()
ind['SourceInstanceModelPath'] = str(instance.path)
- ind['IndicationFilterName'] = make_filter_name(instance.classname, filter_id)
+ ind['IndicationFilterName'] = make_filter_name(
+ instance.classname, filter_id)
ind['PerceivedSeverity'] = self.SEVERITY_INFO
cmpi_logging.logger.info("Sending indication %s for %s" %
diff --git a/src/python/openlmi/common/JobManager.py b/src/python/openlmi/common/JobManager.py
index 5ed7830..e78967c 100644
--- a/src/python/openlmi/common/JobManager.py
+++ b/src/python/openlmi/common/JobManager.py
@@ -47,10 +47,33 @@ import threading
from Queue import Queue
import pywbem
import openlmi.common.cmpi_logging as cmpi_logging
+from openlmi.common.IndicationManager import IndicationManager
from pywbem.cim_provider2 import CIMProvider2
import socket
import traceback
+@cmpi_logging.trace_function
+def register_filters(job_clsname, indication_manager=None):
+ """
+ This function registers static indication filters at IndicationManager.
+ It should be called upon provider's initialization.
+
+ :param job_clsname: (``String``) CIM class name for asynchonous jobs.
+ Will be part of filter queries.
+ :param indication_manager: If not given, global instance will be obtained.
+ """
+ if indication_manager is None:
+ ind_manager = IndicationManager.get_instance()
+ filters = {}
+ query_args = {
+ "classname" : job_clsname,
+ "prefix" : indication_manager.nameprefix
+ }
+ for fltr_id, fltr_props in JobManager.IND_FILTERS.items():
+ filters[fltr_id] = fltr_props.copy()
+ filters[fltr_id]['Query'] = fltr_props['Query'] % query_args
+ indication_manager.add_filters(job_clsname, filters)
+
# Too many instance attributes
# pylint: disable-msg=R0902
class Job(object):
@@ -495,6 +518,23 @@ class Job(object):
return inst
@cmpi_logging.trace_method
+ def get_cim_error(self):
+ """
+ Return job error as CIMInstance of CIM_Error.
+ :returns: CIMInstance of CIM_Error
+ """
+ path = pywbem.CIMInstanceName(
+ classname="CIM_Error",
+ host=socket.gethostname(),
+ namespace=self.job_manager.namespace)
+ err = pywbem.CIMInstance(
+ classname="CIM_Error",
+ path=path)
+ err['CIMStatusCode'] = pywbem.Uint32(self.error[0])
+ err['Message'] = self.error[1]
+ return err
+
+ @cmpi_logging.trace_method
def get_post_call(self):
"""
Return indication that describes the post-execution values of the
@@ -524,15 +564,7 @@ class Job(object):
if self.return_value is not None:
inst['ReturnValue'] = str(self.return_value)
if self.error is not None:
- path = pywbem.CIMInstanceName(
- classname="CIM_Error",
- host=socket.gethostname(),
- namespace=self.job_manager.namespace)
- err = pywbem.CIMInstance(
- classname="CIM_Error",
- path=path)
- err['CIMStatusCode'] = pywbem.Uint32(self.error[0])
- err['Message'] = self.error[1]
+ err = self.get_cim_error()
inst['Error'] = [err, ]
return inst
@@ -651,6 +683,43 @@ class JobManager(object):
IND_JOB_CHANGED = "Changed"
IND_JOB_CREATED = "Created"
+ IND_FILTERS = {
+ IND_JOB_PERCENT_UPDATED: {
+ "Query" : "SELECT * FROM LMI_%(prefix)sInstModification WHERE "
+ "SourceInstance ISA %(classname)s AND "
+ "SourceInstance.CIM_ConcreteJob::PercentComplete <> "
+ "PreviousInstance.CIM_ConcreteJob::PercentComplete",
+ "Description" : "Modification of Percentage Complete for a "
+ "Concrete Job.",
+ },
+ IND_JOB_SUCCEEDED: {
+ "Query" : "SELECT * FROM LMI_%(prefix)sInstModification WHERE "
+ "SourceInstance ISA %(classname)s AND "
+ "SourceInstance.CIM_ConcreteJob::JobState = 17",
+ "Description": "Modification of Job State for a "
+ "Concrete Job to 'Complete'.",
+ },
+ IND_JOB_FAILED: {
+ "Query" : "SELECT * FROM LMI_%(prefix)sInstModification WHERE "
+ "SourceInstance ISA %(classname)s AND "
+ "SourceInstance.CIM_ConcreteJob::JobState = 10",
+ "Description": "Modification of Job State for a "
+ "Concrete Job to 'Exception'.",
+ },
+ IND_JOB_CHANGED: {
+ "Query" : "SELECT * FROM LMI_%(prefix)sInstModification WHERE "
+ "SourceInstance ISA %(classname)s AND "
+ "SourceInstance.CIM_ConcreteJob::JobState <> "
+ "PreviousInstance.CIM_ConcreteJob::JobState",
+ "Description": "Modification of Job State for a ConcreteJob.",
+ },
+ IND_JOB_CREATED: {
+ "Query" : "SELECT * FROM LMI_%(prefix)sInstCreation WHERE "
+ "SourceInstance ISA %(classname)s",
+ "Description": "Creation of a ConcreteJob.",
+ },
+ }
+
@cmpi_logging.trace_method
def __init__(self, name, namespace, indication_manager, timer_manager):
"""
@@ -701,46 +770,7 @@ class JobManager(object):
"""
Add all job-related ``IndicationFilters`` to indication manager.
"""
- filters = {
- self.IND_JOB_PERCENT_UPDATED: {
- "Query" : "SELECT * FROM CIM_InstModification WHERE "
- "SourceInstance ISA %(classname)s AND "
- "SourceInstance.CIM_ConcreteJob::PercentComplete <> "
- "PreviousInstance.CIM_ConcreteJob::PercentComplete",
- "Description" : "Modification of Percentage Complete for a "
- "Concrete Job.",
- },
- self.IND_JOB_SUCCEEDED: {
- "Query" : "SELECT * FROM CIM_InstModification WHERE "
- "SourceInstance ISA %(classname)s AND "
- "SourceInstance.CIM_ConcreteJob::JobState = 17",
- "Description": "Modification of Job State for a "
- "Concrete Job to 'Complete'.",
- },
- self.IND_JOB_FAILED: {
- "Query" : "SELECT * FROM CIM_InstModification WHERE "
- "SourceInstance ISA %(classname)s AND "
- "SourceInstance.CIM_ConcreteJob::JobState = 10",
- "Description": "Modification of Job State for a "
- "Concrete Job to 'Exception'.",
- },
- self.IND_JOB_CHANGED: {
- "Query" : "SELECT * FROM CIM_InstModification WHERE "
- "SourceInstance ISA %(classname)s AND "
- "SourceInstance.CIM_ConcreteJob::JobState <> "
- "PreviousInstance.CIM_ConcreteJob::JobState",
- "Description": "Modification of Job State for a ConcreteJob.",
- },
- self.IND_JOB_CREATED: {
- "Query" : "SELECT * FROM CIM_InstCreation WHERE "
- "SourceInstance ISA %(classname)s",
- "Description": "Creation of a ConcreteJob.",
- },
- }
- # add class name
- for f in filters.itervalues():
- f['Query'] = f['Query'] % {"classname" : self.job_classname }
- self.indication_manager.add_filters(self.job_classname, filters)
+ register_filters(self.job_classname, self.indication_manager)
@cmpi_logging.trace_method
def get_providers(self):
@@ -1139,7 +1169,8 @@ class LMI_ConcreteJob(CIMProvider2):
if job.error is None:
errors = []
else:
- errors = [job.error, ]
+ err = job.get_cim_error()
+ errors = [err, ]
out_params = [
pywbem.CIMParameter(
name='errors',
@@ -1283,9 +1314,10 @@ class LMI_ConcreteJob(CIMProvider2):
type='instance',
is_array=False)
else:
+ err = job.get_cim_error()
error = pywbem.CIMParameter(
name='error',
- value=job.error,
+ value=err,
type='instance')
rval = self.Values.GetError.Success
return (rval, [error])