7. WBEM subscription manager

New in pywbem 0.9 as experimental and finalized in 0.10.

The WBEM subscription manager API supports viewing and managing subscriptions for indications on a WBEM server.

See WBEM indication listener for the API for creating and managing a WBEM listener.

7.1. WBEMSubscriptionManager

New in pywbem 0.9 as experimental and finalized in 0.10.

The WBEMSubscriptionManager class is a subscription manager that provides for creating and removing indication subscriptions (including indication filters and listener destinations) for multiple WBEM servers and multiple WBEM listeners and for getting information about existing indication subscriptions.

The WBEM listener is identified through its URL, so it may be the pywbem listener (that is, a WBEMListener object) or any other WBEM listener.

This subscription manager supports three types of ownership of the CIM instances in WBEM servers that represent subscriptions, filters and listener destinations:

  • Owned

    Owned CIM instances are created via the subscription manager and their life cycle is bound to the life cycle of the registration of that WBEM server with the subscription manager via add_server().

    Owned CIM instances are deleted automatically when their WBEM server is deregistered from the subscription manager via remove_server() or remove_all_servers(). In addition, they can be deleted by the user via the removal methods of the WBEMSubscriptionManager class.

  • Permanent

    Permanent CIM instances are created via the subscription manager and their life cycle is independent of the life cycle of the registration of that WBEM server with the subscription manager.

    Permanent CIM instances are not deleted automatically when their WBEM server is deregistered from the subscription manager. The user is responsible for their lifetime management: They can be deleted via the removal methods of the WBEMSubscriptionManager class.

  • Static

    Static CIM instances pre-exist in the WBEM server and cannot be deleted (or created) by a WBEM client.

If a client creates a subscription between a filter and a listener destination, the types of ownership of these three CIM instances may be arbitrarily mixed, with one exception:

  • A permanent subscription cannot be created on an owned filter or an owned listener destination. Allowing that would prevent the automatic life cycle management of the owned filter or listener destination by the subscription manager. This restriction is enforced by the WBEMSubscriptionManager class.

The WBEMSubscriptionManager object remembers owned subscriptions, filters, and listener destinations. If for some reason that object gets deleted before all servers could be removed (e.g. because the Python program aborts), the corresponding CIM instances in the WBEM server still exist, but the knowledge is lost that these instances were owned by that subscription manager. Therefore, the subscription manager discovers owned subscriptions, filters, and listener destinations when a server is added. For filters, this discovery is based upon the Name property. Therefore, if the Name property is set by the user (e.g. because a management profile requires a particular name), the filter must be permanent and cannot be owned.

7.1.1. Examples

The following example code demonstrates the use of a subscription manager to subscribe for a CIM alert indication on a WBEM server. The WBEM listener is assumed to exist somewhere and is identified by its URL:

from pywbem import WBEMConnection, WBEMServer, WBEMSubscriptionManager

server_url = 'http://myserver'
server_credentials = ('myuser', 'mypassword')

listener_url = 'http://mylistener'

conn = WBEMConnection(server_url, server_credentials)
server = WBEMServer(conn)
sub_mgr = WBEMSubscriptionManager(subscription_manager_id='fred')

# Register the server in the subscription manager:
server_id = sub_mgr.add_server(server)

# Add a listener destination in the server:
dest_inst = sub_mgr.add_listener_destinations(server_id, listener_url)

# Subscribe to a static filter of a given name:
filter1_name = "DMTF:Indications:GlobalAlertIndicationFilter"
filter1_insts = sub_mgr.get_all_filters(server_id)
for inst in filter1_insts:
    if inst['Name'] == filter1_name:
        sub_mgr.add_subscriptions(server_id, inst.path, dest_inst.path)
        break

# Create a dynamic alert filter and subscribe to it:
filter2_source_ns = "root/cimv2"
filter2_query = "SELECT * FROM CIM_AlertIndication " \
                "WHERE OwningEntity = 'DMTF' " \
                "AND MessageID LIKE 'SVPC0123|SVPC0124|SVPC0125'"
filter2_language = "DMTF:CQL"
filter2_inst = sub_mgr.add_filter(
    server_id, filter2_source_ns, filter2_query, filter2_language,
    owned=True, filter_id="myalert")
sub_mgr.add_subscriptions(server_id, filter2_inst.path, dest_inst.path)

The following example code briefly shows how to use a subscription manager as a context manager, in order to get automatic cleanup of owned instances:

with WBEMSubscriptionManager('fred') as sub_mgr:
    server_id = sub_mgr.add_server(server)
    . . .
# The exit method automatically calls remove_all_servers(), which deletes
# all owned subscription, filter and destination instances in the servers
# that were registered.

The Tutorial section contains a tutorial about the subscription manager.

class pywbem.WBEMSubscriptionManager(subscription_manager_id)[source]

New in pywbem 0.9 as experimental and finalized in 0.10.

A class for managing subscriptions for CIM indications in a WBEM server.

The class may be used as a Python context manager, in order to get automatic clean up (see __exit__()).

Parameters

subscription_manager_id (string) –

A subscription manager ID string that is used as a component in the value of the Name property of indication filter and listener destination instances to help the user identify these instances in a WBEM server.

Must not be None.

The string must consist of printable characters, and must not contain the character ‘:’ because that is the separator between components within the value of the Name property.

The subscription manager ID must be unique on the current host.

For example, the form of the Name property of a filter instance is (for details, see add_filter()):

"pywbemfilter:" {ownership} ":" {subscription_manager_id} ":" {filter_id} ":" {guid}

Raises
  • ValueError – Incorrect input parameter values.

  • TypeError – Incorrect input parameter types.

Methods:

__enter__()

New in pywbem 0.10.

__exit__(exc_type, exc_value, traceback)

New in pywbem 0.10.

__repr__()

Return a representation of the WBEMSubscriptionManager object with all attributes, that is suitable for debugging.

__str__()

Return a representation of the WBEMSubscriptionManager object with a subset of its attributes.

add_filter(server_id, source_namespace, query)

Add a dynamic indication filter to a WBEM server, by creating an indication filter instance (of CIM class "CIM_IndicationFilter") in the Interop namespace of the server.

add_listener_destinations(server_id, ...[, ...])

Register WBEM listeners to be the target of indications sent by a WBEM server.

add_server(server)

Register a WBEM server with the subscription manager.

add_subscriptions(server_id, filter_path[, ...])

Add subscriptions to a WBEM server for a particular set of indications defined by an indication filter and for a particular set of WBEM listeners defined by the instance paths of their listener destinations, by creating indication subscription instances (of CIM class "CIM_IndicationSubscription") in the Interop namespace of that server.

get_all_destinations(server_id)

Return all listener destinations in a WBEM server.

get_all_filters(server_id)

Return all indication filters in a WBEM server.

get_all_subscriptions(server_id)

Return all indication subscriptions in a WBEM server.

get_owned_destinations(server_id)

Return the listener destinations in a WBEM server owned by this subscription manager.

get_owned_filters(server_id)

Return the indication filters in a WBEM server owned by this subscription manager.

get_owned_subscriptions(server_id)

Return the indication subscriptions in a WBEM server owned by this subscription manager.

remove_all_servers()

Remove all registered WBEM servers from the subscription manager.

remove_destinations(server_id, destination_paths)

Remove listener destinations from a WBEM server, by deleting the listener destination instances in the server.

remove_filter(server_id, filter_path)

Remove an indication filter from a WBEM server, by deleting the indication filter instance in the WBEM server.

remove_server(server_id)

Remove a registered WBEM server from the subscription manager.

remove_subscriptions(server_id, sub_paths)

Remove indication subscription(s) from a WBEM server, by deleting the indication subscription instances in the server.

__enter__()[source]

New in pywbem 0.10.

Enter method when the class is used as a context manager. Returns the subscription manager object

__exit__(exc_type, exc_value, traceback)[source]

New in pywbem 0.10.

Exit method when the class is used as a context manager.

It cleans up by calling remove_all_servers().

__repr__()[source]

Return a representation of the WBEMSubscriptionManager object with all attributes, that is suitable for debugging.

__str__()[source]

Return a representation of the WBEMSubscriptionManager object with a subset of its attributes.

add_filter(server_id, source_namespace, query, query_language='WQL', owned=True, filter_id=None, name=None)[source]

Add a dynamic indication filter to a WBEM server, by creating an indication filter instance (of CIM class “CIM_IndicationFilter”) in the Interop namespace of the server.

The Name property of the created filter instance can be set in one of two ways:

  • directly by specifying the name parameter.

    In this case, the Name property is set directly to the name parameter.

    This should be used in cases where the user needs to have control over the filter name (e.g. because a DMTF management profile requires a particular name), but it cannot be used for owned filters.

  • indirectly by specifying the filter_id parameter.

    In this case, the value of the Name property will be:

    "pywbemfilter:" {ownership} ":" {subscription_manager_id} ":" {filter_id} ":" {guid}

    where {ownership} is "owned" or "permanent" dependent on whether the filter is owned or permmanent; {subscription_manager_id} is the subscription manager ID; {filter_id} is the filter ID; and {guid} is a globally unique identifier.

    This can be used for both owned and permanent filters.

Owned indication filters are added or updated conditionally: If the indication filter instance to be added is already registered with this subscription manager and has the same property values, it is not created or modified. If it has the same path but different property values, it is modified to get the desired property values. If an instance with this path does not exist yet (the normal case), it is created.

Permanent indication filters are created unconditionally, and it is up to the user to ensure that such an instance does not exist yet.

Parameters
  • server_id (string) – The server ID of the WBEM server, returned by add_server().

  • source_namespace (string) – Source namespace of the indication filter.

  • query (string) – Filter query in the specified query language.

  • query_language (string) –

    Query language for the specified filter query.

    Examples: ‘WQL’, ‘DMTF:CQL’.

  • owned (bool) – Defines the ownership type of the created indication filter instance: If True, it will be owned. Otherwise, it will be permanent. See WBEMSubscriptionManager for details about these ownership types.

  • filter_id (string) –

    A filter ID string that is used as a component in the value of the Name property of filter instances to help the user identify these instances in a WBEM server, or None if the name parameter is specified.

    The string must consist of printable characters, and must not contain the character ‘:’ because that is the separator between components within the value of the Name property.

    There is no requirement that the filter ID be unique. This can be used to identify groups of filters by using the same value for multiple filters.

  • name (string) –

    New in pywbem 0.10.

    The filter name to be used directly for the Name property of the filter instance, or None if the filter_id parameter is specified.

Returns

The created indication filter instance.

Return type

CIMInstance

:raises Exceptions raised by WBEMConnection.: :raises ValueError: Incorrect input parameter values. :raises TypeError: Incorrect input parameter types.

add_listener_destinations(server_id, listener_urls, owned=True)[source]

Register WBEM listeners to be the target of indications sent by a WBEM server.

This function automatically creates a listener destination instance (of CIM class “CIM_ListenerDestinationCIMXML”) for each specified listener URL in the Interop namespace of the specified WBEM server.

The form of the Name property of the created destination instance is:

"pywbemdestination:" {ownership} ":" {subscription_manager_id} ":" {guid}

where {ownership} is "owned" or "permanent" dependent on the owned argument; {subscription_manager_id} is the subscription manager ID; and {guid} is a globally unique identifier.

Owned listener destinations are added or updated conditionally: If the listener destination instance to be added is already registered with this subscription manager and has the same property values, it is not created or modified. If it has the same path but different property values, it is modified to get the desired property values. If an instance with this path does not exist yet (the normal case), it is created.

Permanent listener destinations are created unconditionally, and it is up to the user to ensure that such an instance does not exist yet.

Parameters
  • server_id (string) – The server ID of the WBEM server, returned by add_server().

  • listener_urls (string or list of string) –

    The URL or URLs of the WBEM listeners to be registered.

    The WBEM listener may be a WBEMListener object or any external WBEM listener.

    Each listener URL string must have the format:

    [{scheme}://]{host}:{port}

    The following URL schemes are supported:

    • https: Causes HTTPS to be used.

    • http: Causes HTTP to be used. This is the default

    The host can be specified in any of the usual formats:

    • a short or fully qualified DNS hostname

    • a literal (= dotted) IPv4 address

    • a literal IPv6 address, formatted as defined in RFC3986 with the extensions for zone identifiers as defined in RFC6874, supporting - (minus) for the delimiter before the zone ID string, as an additional choice to %25.

    Note that the port is required in listener URLs.

    See WBEMConnection for examples of valid URLs, with the caveat that the port in server URLs is optional.

  • owned (bool) – Defines the ownership type of the created listener destination instances: If True, they will be owned. Otherwise, they will be permanent. See WBEMSubscriptionManager for details about these ownership types.

Returns

The created listener destination instances for the defined listener URLs.

Return type

py:list of CIMInstance

:raises Exceptions raised by WBEMConnection.:

add_server(server)[source]

Register a WBEM server with the subscription manager. This is a prerequisite for adding listener destinations, indication filters and indication subscriptions to the server.

This method discovers listener destination, indication filter, and subscription instances in the WBEM server owned by this subscription manager, and registers them in the subscription manager as if they had been created through it.

In this discovery process, listener destination and indication filter instances are matched based upon the value of their Name property. Subscription instances are matched based upon the ownership of the referenced destination and filter instances: If a subscription references a filter or a destination that is owned by this subscription manager, it is considered owned by this subscription manager as well.

Parameters

server (WBEMServer) – The WBEM server.

Returns

An ID for the WBEM server, for use by other methods of this class.

Return type

string

:raises Exceptions raised by WBEMConnection.: :raises ValueError: Incorrect input parameter values. :raises TypeError: Incorrect input parameter types.

add_subscriptions(server_id, filter_path, destination_paths=None, owned=True)[source]

Add subscriptions to a WBEM server for a particular set of indications defined by an indication filter and for a particular set of WBEM listeners defined by the instance paths of their listener destinations, by creating indication subscription instances (of CIM class “CIM_IndicationSubscription”) in the Interop namespace of that server.

The specified indication filter may be owned, permanent or static.

The specified listener destinations may be owned, permanent or static.

When creating permanent subscriptions, the indication filter and the listener destinations must not be owned.

Owned subscriptions are added or updated conditionally: If the subscription instance to be added is already registered with this subscription manager and has the same property values, it is not created or modified. If it has the same path but different property values, it is modified to get the desired property values. If an instance with this path does not exist yet (the normal case), it is created.

Permanent subscriptions are created unconditionally, and it is up to the user to ensure that such an instance does not exist yet.

Upon successful return of this method, the added subscriptions are active, so that the specified WBEM listeners may immediately receive indications.

Parameters
  • server_id (string) – The server ID of the WBEM server, returned by add_server().

  • filter_path (CIMInstanceName) – Instance path of the indication filter instance in the WBEM server that specifies the indications to be sent.

  • destination_paths (CIMInstanceName or list of CIMInstanceName) –

    Instance paths of the listener destination instances in the WBEM server that specify the target WBEM listener.

    If None, subscriptions will be created for all owned listener destinations registered to this subscription manager.

  • owned (bool) – Defines the ownership type of the created subscription instances: If True, they will be owned. Otherwise, they will be permanent. See WBEMSubscriptionManager for details about these ownership types.

Returns

The indication subscription instances created in the WBEM server.

Return type

py:list of CIMInstance

:raises Exceptions raised by WBEMConnection.: :raises ValueError: Incorrect input parameter values.

get_all_destinations(server_id)[source]

Return all listener destinations in a WBEM server.

This function contacts the WBEM server and retrieves the listener destinations by enumerating the instances of CIM class “CIM_ListenerDestinationCIMXML” in the Interop namespace of the WBEM server.

Parameters

server_id (string) – The server ID of the WBEM server, returned by add_server().

Returns

The listener destination instances.

Return type

py:list of CIMInstance

:raises Exceptions raised by WBEMConnection.:

get_all_filters(server_id)[source]

Return all indication filters in a WBEM server.

This function contacts the WBEM server and retrieves the indication filters by enumerating the instances of CIM class “CIM_IndicationFilter” in the Interop namespace of the WBEM server.

Parameters

server_id (string) – The server ID of the WBEM server, returned by add_server().

Returns

The indication filter instances.

Return type

py:list of CIMInstance

:raises Exceptions raised by WBEMConnection.:

get_all_subscriptions(server_id)[source]

Return all indication subscriptions in a WBEM server.

This function contacts the WBEM server and retrieves the indication subscriptions by enumerating the instances of CIM class “CIM_IndicationSubscription” in the Interop namespace of the WBEM server.

Parameters

server_id (string) – The server ID of the WBEM server, returned by add_server().

Returns

The indication subscription instances.

Return type

py:list of CIMInstance

:raises Exceptions raised by WBEMConnection.:

get_owned_destinations(server_id)[source]

Return the listener destinations in a WBEM server owned by this subscription manager.

This function accesses only the local list of owned destinations; it does not contact the WBEM server. The local list of owned destinations is discovered from the WBEM server when the server is registered with the subscription manager, and is maintained from then on as changes happen through this subscription manager.

Parameters

server_id (string) – The server ID of the WBEM server, returned by add_server().

Returns

The listener destination instances.

Return type

py:list of CIMInstance

get_owned_filters(server_id)[source]

Return the indication filters in a WBEM server owned by this subscription manager.

This function accesses only the local list of owned filters; it does not contact the WBEM server. The local list of owned filters is discovered from the WBEM server when the server is registered with the the subscription manager, and is maintained from then on as changes happen through this subscription manager.

Parameters

server_id (string) – The server ID of the WBEM server, returned by add_server().

Returns

The indication filter instances.

Return type

py:list of CIMInstance

get_owned_subscriptions(server_id)[source]

Return the indication subscriptions in a WBEM server owned by this subscription manager.

This function accesses only the local list of owned subscriptions; it does not contact the WBEM server. The local list of owned subscriptions is discovered from the WBEM server when the server is registered with the subscription manager, and is maintained from then on as changes happen through this subscription manager.

Parameters

server_id (string) – The server ID of the WBEM server, returned by add_server().

Returns

The indication subscription instances.

Return type

py:list of CIMInstance

remove_all_servers()[source]

Remove all registered WBEM servers from the subscription manager. This also unregisters listeners from these servers and removes all owned indication subscriptions, owned indication filters, and owned listener destinations.

:raises Exceptions raised by WBEMConnection.:

remove_destinations(server_id, destination_paths)[source]

Remove listener destinations from a WBEM server, by deleting the listener destination instances in the server.

The listener destinations must be owned or permanent (i.e. not static).

This method verifies that there are not currently any subscriptions on the listener destinations to be removed, in order to handle server implementations that do not ensure that on the server side as required by DSP1054.

Parameters

:raises Exceptions raised by WBEMConnection.: :raises CIMError: CIM_ERR_FAILED, if there are referencing subscriptions.

remove_filter(server_id, filter_path)[source]

Remove an indication filter from a WBEM server, by deleting the indication filter instance in the WBEM server.

The indication filter must be owned or permanent (i.e. not static).

This method verifies that there are not currently any subscriptions on the specified indication filter, in order to handle server implementations that do not ensure that on the server side as required by DSP1054.

Parameters
  • server_id (string) – The server ID of the WBEM server, returned by add_server().

  • filter_path (CIMInstanceName) – Instance path of the indication filter instance in the WBEM server.

:raises Exceptions raised by WBEMConnection.: :raises CIMError: CIM_ERR_FAILED, if there are referencing subscriptions.

remove_server(server_id)[source]

Remove a registered WBEM server from the subscription manager. This also unregisters listeners from that server and removes all owned indication subscriptions, owned indication filters and owned listener destinations.

Parameters

server_id (string) – The server ID of the WBEM server, returned by add_server().

:raises Exceptions raised by WBEMConnection.:

remove_subscriptions(server_id, sub_paths)[source]

Remove indication subscription(s) from a WBEM server, by deleting the indication subscription instances in the server.

The indication subscriptions must be owned or permanent (i.e. not static).

Parameters

:raises Exceptions raised by WBEMConnection.: