Package pywbem :: Module cim_provider2

[frames] | no frames]

# Module cim_provider2

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_module()
        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 CIMProvider2 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 CIMProvider2 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
                CIMProvider2 subclasses.  Note that multiple classes can be
                instrumented by the same instance of a CIMProvider2 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(CIMProvider2):
                        ...

                    def get_providers(env):
                        _fbp = Py_FooBarProvider()
                        return {'Py_Foo':_fbp, 'Py_Bar':_fbp}

            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 event occurred
                handler_instance --
                indication_instance -- The indication

            authorize_filter (env, filter, ns, classes,
                             owner):
                Allow or disallow an indication subscription request.

                Arguments:
                env -- Provider Environment (pycimmb.ProviderEnvironment)
                filter -- The WQL select statement
                namespace -- The namepace where the indication is registered for
                classes -- The classpath of the indication registered for
                owner -- The name of the principal (cimom user)

            activate_filter (env, filter, ns, classes,
                             first_activation):
                Activate an indication subscription.

                Arguments:
                env -- Provider Environment (pycimmb.ProviderEnvironment)
                filter -- The WQL select statement
                namespace -- The namepace where the indication is registered for
                classes -- The classpath of the indication registered for
                first_activation -- boolean - whether first activation

            deactivate_filter(env, filter, ns, classes,
                              last_activation):
                Deactivate an indication subscription.

                Arguments:
                env -- Provider Environment (pycimmb.ProviderEnvironment)
                filter -- The WQL select statement
                ns -- The namepace where the indication is registered for
                classes -- The classpath of the indication registered for
                last_activation -- boolean - whether last activation

            enable_indications(env):
                Enable indications.

                Arguments:
                env -- Provider Environment (pycimmb.ProviderEnvironment)

            disable_indications(env):
                Disable indications.

                Arguments:
                env -- Provider Environment (pycimmb.ProviderEnvironment)

    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.

Classes
| CIMProvider2 Base class for CIM Providers.

Functions

codegen(cc) Generate a Python Provider template. | source code

Function Details

### codegen(cc)

source code

Generate a Python Provider template.

Parameters: cc - A CIMClass to generate code for.

Returns a two-tuple containing the Python provider code stubs, and
  the provider registration MOF.