Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
commit 7e24cf9306b097f6d83d399e320af165f198a777 Author: Peter Hatina phatina@redhat.com Date: Fri Nov 8 12:08:41 2013 +0100
simplify indication subscription
cli/lmi/shell/LMIConnection.py | 64 +++++++++++++++++++++++++++------------ doc/src/indications.rst | 24 +++++++++++++++ 2 files changed, 68 insertions(+), 20 deletions(-)
diff --git a/cli/lmi/shell/LMIConnection.py b/cli/lmi/shell/LMIConnection.py index 301fa52..52c9922 100644 --- a/cli/lmi/shell/LMIConnection.py +++ b/cli/lmi/shell/LMIConnection.py @@ -315,27 +315,32 @@ class LMIConnection(object):
* **Filter** (*LMIInstance*) -- if provided, the :py:class:`LMIInstance` object will be used instead of creating a new one; - optional + **optional** * **Handler** (*LMIInstance*) -- if provided, the :py:class:`LMIInstance` - object will be used instead of creating a new one; optional + object will be used instead of creating a new one; **optional** * **Query** (*string*) -- string containing a query for the indications filtering - * **QueryLanguage** (*string*) -- query language; eg. `WQL`, or `DMTF:CQL` + * **QueryLanguage** (*string*) -- query language; eg. *WQL*, or *DMTF:CQL*. + This parameter is optional, default value is *DMTF:CQL*. * **Name** (*string*) -- indication name - * **CreationNamespace** (*string*) -- creation namespace + * **CreationNamespace** (*string*) -- creation namespace. This parameter is + optional, default value is *root/interop*. * **SubscriptionCreationClassName** (*string*) -- subscription object class - name + name. This parameter is optional, default value is *CIM_IndicationSubscription*. * **Permanent** (*bool*) -- whether to preserve the created subscription on LMIShell's quit. Default value is False. * **FilterCreationClassName** (*string*) -- creation class name of the filter - object + object. This parameter is options, default value is *CIM_IndicationFilter*. * **FilterSystemCreationClassName** (*string*) -- system creation class name - of the filter object + of the filter object. This parameter is optional, default value is + *CIM_ComputerSystem*. * **FilterSourceNamespace** (*string*) -- local namespace where the - indications originate + indications originate. This parameter is optional, default value is + *root/cimv2*. * **HandlerCreationClassName** (*string*) -- creation class name of the - handler object + handler object. This parameter is optional, default value is + *CIM_IndicationHandlerCIMXML*. * **HandlerSystemCreationClassName** (*string*) -- system creation name of the - handler object + handler object. This parameter is optional, default value is *CIM_ComputerSystem*. * **Destination** (*string*) -- destination URI, where the indications should be delivered
@@ -344,6 +349,7 @@ class LMIConnection(object): set to appropriate error string. """ try: + indication_namespace = kwargs.get("CreationNamespace", "root/interop") cim_filter_provided = "Filter" in kwargs if cim_filter_provided: filt = kwargs["Filter"] @@ -358,17 +364,27 @@ class LMIConnection(object): return LMIReturnValue(rval=False, errorstr=errorstr) else: cim_filter_props = { - "CreationClassName" : kwargs["FilterCreationClassName"], - "SystemCreationClassName" : kwargs["FilterSystemCreationClassName"], - "SourceNamespace" : kwargs["FilterSourceNamespace"], + "CreationClassName" : kwargs.get( + "FilterCreationClassName", + "CIM_IndicationFilter"), + "SystemCreationClassName" : kwargs.get( + "FilterSystemCreationClassName", + "CIM_ComputerSystem"), + "SourceNamespace" : kwargs.get( + "FilterSourceNamespace", + "root/cimv2"), "SystemName" : self._client.uri, "Query" : kwargs["Query"], - "QueryLanguage" : kwargs["QueryLanguage"], + "QueryLanguage" : kwargs.get( + "QueryLanguage", + LMIBaseClient.QUERY_LANG_CQL), "Name" : kwargs["Name"] + "-filter" } (cim_filter, _, errorstr) = self._client._create_instance( - kwargs["FilterCreationClassName"], kwargs["CreationNamespace"], - cim_filter_props) + cim_filter_props["CreationClassName"], + indication_namespace, + cim_filter_props + ) if not cim_filter: lmi_raise_or_dump_exception(LMIIndicationError(errorstr)) return LMIReturnValue(rval=False, errorstr=errorstr) @@ -377,14 +393,19 @@ class LMIConnection(object): cim_handler = kwargs["Handler"]._cim_instance else: cim_handler_props = { - "CreationClassName" : kwargs["HandlerCreationClassName"], - "SystemCreationClassName" : kwargs["HandlerSystemCreationClassName"], + "CreationClassName" : kwargs.get( + "HandlerCreationClassName", + "CIM_IndicationHandlerCIMXML"), + "SystemCreationClassName" : kwargs.get( + "HandlerSystemCreationClassName", + "CIM_ComputerSystem"), "SystemName" : self._client.uri, "Destination" : kwargs["Destination"] + "/" + kwargs["Name"], "Name" : kwargs["Name"] + "-handler" } (cim_handler, _, errorstr) = self._client._create_instance( - kwargs["HandlerCreationClassName"], kwargs["CreationNamespace"], + cim_handler_props["CreationClassName"], + indication_namespace, cim_handler_props) if not cim_handler: if not "Filter" in kwargs: @@ -396,7 +417,10 @@ class LMIConnection(object): "Handler" : cim_handler.path } (cim_subscription, _, errorstr) = self._client._create_instance( - kwargs["SubscriptionCreationClassName"], kwargs["CreationNamespace"], + kwargs.get( + "SubscriptionCreationClassName", + "CIM_IndicationSubscription"), + indication_namespace, cim_subscription_props) if not cim_subscription: if not "Filter" in kwargs: diff --git a/doc/src/indications.rst b/doc/src/indications.rst index 585f82e..f0765ff 100644 --- a/doc/src/indications.rst +++ b/doc/src/indications.rst @@ -32,6 +32,30 @@ How to subscribe to an indication, please, follow the next example: LMIReturnValue(rval=True, rparams={}, errorstr="") >
+The previous code can be simplified by omitting some optional parameters: + +* *QueryLanguage*: *DMTF:CQL* +* *CreationNamespace*: *root/interop* +* *SubscriptionCreationClassName*: *CIM_IndicationSubscription* +* *FilterCreationClassName*: *CIM_IndicationFilter* +* *FilterSystemCreationClassName*: *CIM_ComputerSystem* +* *FilterSourceNamespace*: *root/cimv2* +* *HandlerCreationClassName*: *CIM_IndicationHandlerCIMXML* +* *HandlerSystemCreationClassName*: *CIM_ComputerSystem* + +Simplified subscription: + +.. code-block:: python + + > c = connect("host", "privileged_user", "password") + > c.subscribe_indication( + ... Name="cpu", + ... Query='SELECT * FROM CIM_InstModification', + ... Destination="http://192.168.122.1:5988" + ... ) + LMIReturnValue(rval=True, rparams={}, errorstr="") + > + **NOTE:** Make sure, that you are logged-in with an account, which has write privileges in the *root/interop* namespace.
cura-tools-devel@lists.fedorahosted.org