Module cim_provider
source code
Python CIM Providers (aka "nirvana")
This module is an abstraction and utility layer between a CIMOM and
Python providers. The CIMOM uses this module to load Python providers,
and route requests to those providers.
Python Provider Modules
Python Providers are implemented as Python modules. By convention
these modules are installed into /usr/lib/pycim. However, they can
be anywhere. These modules are loaded on demand using load_source()
from the imp module. The CIMOM's pycim interface stores the timestamp
of the provider modules. If the modules change, the CIMOM reloads the
modules. This is very useful while developing providers, since the
latest code will always be loaded and used.
A Python Provider Module will contain functions, attributes, and
instances that will be accessed and manipulated by this module.
Providers are often classified in the following catagories:
Instance -- Instrument the retrieval, creation, modification,
and deletion of CIM instances.
Association -- Instrument CIM associations (CIM classes with the
Association qualifier).
Method -- Instrument methods as defined on CIM instances or CIM
classes.
Indication -- Generates indications based on indication
subscriptions.
Indication Consumer -- "Consumes" (or "Handles") an indication,
possibly delivering it through some other means, such as email.
Polled -- A polled provider is allowed to run periodically (by
calling its poll function). This allows a provider to do some
periodic work, without the need to create its own thread.
An Instance, Association, and/or Method provider is created by defining
one or more subclasses of CIMProvider within the provider module, and
registering instances of the subclass(es) with CIM class names by way
of the get_providers function (described below). Refer to
the documentation for CIMProvider in this module.
Indication, Indication Consumer, and Polled providers are defined by
implementing some functions within the provider module.
Provider module functions:
init(env):
This module function is optional. It is called immediately
after the provider module is imported.
Arguments:
env -- Provider Environment (pycimmb.ProviderEnvironment)
get_providers(env):
Return a dict that maps CIM class names to instances of
CIMProvider subclasses. Note that multiple classes can be
instrumented by the same instance of a CIMProvider subclass.
The CIM class names are case-insensitive, since this dict is
converted to a NocaseDict.
Arguments:
env -- Provider Environment (pycimmb.ProviderEnvironment)
For example, a Python Provider Module may contain the following:
class Py_FooBarProvider(CIMProvider):
...
def get_providers(env):
_fbp = Py_FooBarProvider()
return {'Py_Foo':_fbp, 'Py_Bar':_fbp}
get_initial_polling_interval(env):
Return the number of seconds before the first call to poll.
If this method returns zero, then the poll method is never called.
Arguments:
env -- Provider Environment (pycimmb.ProviderEnvironment)
poll(env):
Do some work, and return the number of seconds until the next poll.
A polled provider's poll function will be called periodically by
the CIMOM. The polled provider can use this opportunity to do
some work, such as checking on some conditions, and generating
indications. The poll function returns the number of seconds the
CIMOM should wait before calling poll again. A return value of -1
indicates to the CIMOM that the previous poll value should be used.
A return value of 0 indicates that the poll function should never
be called again.
Arguments:
env -- Provider Environment (pycimmb.ProviderEnvironment)
can_unload(env):
Return True if the provider can be unloaded.
The CIMOM may try to unload a provider after a period of inactivity.
Before unloading a provider, the CIMOM asks the provider if it can
be unloaded.
Arguments:
env -- Provider Environment (pycimmb.ProviderEnvironment)
shutdown(env):
Perform any cleanup tasks prior to being unloaded.
The provider will shortly be unloaded, and is given an opportunity
to perform any needed cleanup. The provider may be unloaded after
a period of inactivity (see the documentation for can_unload), or
because the CIMOM is shutting down.
Arguments:
env -- Provider Environment (pycimmb.ProviderEnvironment)
handle_indication(env, ns, handler_instance, indication_instance):
Process an indication.
Arguments:
env -- Provider Environment (pycimmb.ProviderEnvironment)
ns -- The namespace where the even occurred
handler_instance --
indication_instance -- The indication
activate_filter (env, filter, ns, classes,
first_activation):
Arguments:
env -- Provider Environment (pycimmb.ProviderEnvironment)
filter --
namespace --
classes --
first_activation --
deactivate_filter(env, filter, ns, classes,
last_activation):
Arguments:
env -- Provider Environment (pycimmb.ProviderEnvironment)
filter --
ns --
classes --
last_activation --
Provider Environment
A pycimmb.ProviderEnvironment is passed to many functions. This is
a handle back into the CIMOM. You can use it for logging and for
making "up-calls" to the CIMOM. For example:
logger = env.get_logger()
logger.log_debug('Debug Info')
ch = env.get_cimom_handle()
other_inst = ch.GetInstance(inst_path, LocalOnly=False,
IncludeQualifiers=False,
IncludeClassOrigin=False)
The API of the pycimmb.CIMOMHandle resembles that of
pywbem.WBEMConnection.
For more information on the ProviderEnvironments, and other features
provided by pycimmb, refer to the pycimmb documentation.
CodeGen
The codegen function can be used to generate provider stub code for a
given CIM class. This is a quick way to get started writing a provider.