Net::OpenWBEM::Provider - Perl provider interface for OpenWBEM
This is owperlprovider, a Perl provider interface for OpenWBEM. This lets you write OpenWBEM providers in Perl. There are also client side Perl bindings for OpenWBEM, but they are in a different package.
This module contains no functionality on its own, it merely imports the necessary modules when writing a provider.
Writing a provider involves implementing a number of functions that are called by the CIMOM whenever data from a certain class (or classes) is needed.
Here you will find some general information about writing a provider. This is followed by a list of specific functions that you can implement.
There is no initialize
function. Perform any initializing tasks
by putting code outside of any functions. This code will be run
immediately after the script is loaded and compiled.
To throw an exception, just use the standard Perl die
statement.
The provider interface wraps each method invocation in an eval { }
block and then checks the value of $@
upon return from the Perl
code. If the value of $@
is defined, an exception will be raised,
and the text used in the die
statement will be passed back to the
caller.
Access to OpenWBEM's logging facility is available through the Provider Environment provided as first argument to all methods ($env).
my $logger = $env->getLogger();
The logger provides the following methods:
$logger->logDebug("Message", $fileName, $lineNumber, $methodName); $logger->logInfo(...); $logger->logError(...); $logger->logFatalError(...);
Only the first parameter (the log message) is mandatory.
Log::Log4perl-Style - methods are provided for convenience - they fill out the $fileName, $lineNumber and $methodName fields automatically.
These are:
$log->debug("Message"); $log->info("Message"); $log->warn("Message"); # same as error $log->error("Message"); $log->fatal("Message"); $log->logdie("Message"); # same as $log->fatal("Message"); die "Message";
OpenWBEM has the ability to dynamically unload providers. This holds true for Net::OpenWBEM::Provider plugins, too, but you have to keep some things in mind:
This is due to the fact that perl never returns memory back to the system (well, on most platforms), but only reuses it internally. This means that unloading a Perl provider does not decrease OpenWBEM's memory usage, but just frees up space which may be (re-) used by a Perl provider loaded afterwards.
In contrast to other provider interfaces, Net::OpenWBEM::Provider does not check whether the provider has been idle for some time before unloading it.
Net::OpenWBEM::Provider will only unload Perl Providers which implement the following method:
sub canUnload { return 1; };
Returning any true value from canUnload tells the provider interface that it may unload this provider.
Net::OpenWBEM::Provider will never unload providers which do not implement this method (though it will attempt to call it).
If you have providers which may become non-unloadable after some part of work do the following:
my $CAN_UNLOAD = 1; # a GLOBAL ! sub canUnload { return $CAN_UNLOAD; } ... # somewhere else, maybe in invokeMethod or the like $CAN_UNLOAD = 0; The provider will not unload after you've set $CAN_UNLOAD to 0.
The provider interface is still considered incomplete. A C++ OpenWBEM provider has access to functions that are not documented here, because they are not currently available to Perl providers. This is not a limitation of Perl, only that the relevant calling code has not been written.
Following each function is a more detailed list of the parameters used when the function is invoked. It lists recommended names and the types of each parameter.
sub canUnload { return 1; }
When OpenWBEM is ready to unload a provider, it calls this method first, to see if it's ok to unload. Return any true value to allow OpenWBEM to proceed with the unload.
sub enumInstanceNames { my ($env, $ns, $className, $result, $cimClass) = @_; # foreach underlining object... { my $mcop = Net::OpenWBEM::CIMObjectPath->new($className, $ns); # fill key properties # ... $result->handle($mcop); } }
$result->handle($cop)
$cimClass - Net::OpenWBEM::CIMClass - contains class information
sub enumInstances { my ($env, $ns, $className, $localOnly, $deep, $includeQualifiers, $includeClassOrigin, $result, $cimClass, $requestedClass, $propertyList) = @_;
# foreach underlining object... { my $ci = $cimClass->newInstance;
# set instance properties # ...
$result->handle($ci); } }
$result->handle($newinstance)
$cimClass - Net::OpenWBEM::CIMClass - use this object to create new instances
$requestedClass - Net::OpenWBEM::CIMClass
$propertyList - array reference - if defined, returned instances should only
contain values for properties named in this array
sub getInstance { my ($env, $ns, $instanceName, $localOnly, $includeQualifiers, $includeClassOrigin, $propertyList, $cimClass) = @_;
# get key values from $instanceName my $key1 = $instanceName->getStringKeyValue('key1'); my $key2 = $instanceName->getIntegerKeyValue('key2');
my $ci = $cimClass->newInstance; # set instance properties # ... return $ci; }
To denote that the instance does not exist, just return undef.
sub createInstance { my ($env, $ns, $cimInstance) = @_;
# create the underlining object # ...
# create a path for the new instance my $cop = Net::OpenWBEM::CIMObjectPath->new($ns, $cimInstance); return $cop; }
sub modifyInstance { my ($env, $ns, $modifiedInstance, $previousInstance, $includeQualifiers, $propertyList, $theClass) = @_; # modify the underlining data # ... }
sub deleteInstance { my ($env, $ns, $cop) = @_;
# delete the underlining object # ... }
sub associators { my ($env, $result, $ns, $objectName, $assocClass, $resultClass, $role, $resultRole, $includeQualifiers, $includeClassOrigin, $propertyList) = @_;
# for each underlining associated object... { my $ci = ...
# set instance properties # ...
$result->handle($ci); } }
$result->handle($newinstance)
$ns - string
$objectName - Net::OpenWBEM::CIMObjectPath
$assocClass - string - Use this class to determine what class your
provider is handling.
$resultClass - string
$role - string
$resultRole - string
$includeQualifiers - unsigned integer
$includeClassOrigin - unsigned integer
$propertyList - array reference - if defined, returned instances should only
contain values for properties named in this array
sub associatorNames { my ($env, $result, $ns, $objectName, $assocClass, $resultClass, $role, $resultRole) = @_;
# foreach underlining associated object... { my $mcop = Net::OpenWBEM::CIMObjectPath->new($className, $ns);
# fill key properties # ...
$result->handle($mcop); } }
$result->handle($cop)
$ns - string
$objectName - Net::OpenWBEM::CIMObjectPath
$assocClass - string - Use this class to determine what class your
provider is handling.
$resultClass - string
$role - string
$resultRole - string
sub references { my ($env, $result, $ns, $objectName, $resultClass, $role, $includeQualifiers, $includeClassOrigin, $propertyList) = @_;
# for each association... { my $ci = ...
# set instance properties # ...
$result->handle($ci); } }
$result->handle($newinstance)
$ns - string
$objectName - Net::OpenWBEM::CIMObjectPath
$resultClass - string
$role - string
$includeQualifiers - unsigned integer
$includeClassOrigin - unsigned integer
$propertyList - array reference - if defined, returned instances should only
contain values for properties named in this array
sub referenceNames { my ($env, $result, $ns, $objectName, $resultClass, $role) = @_;
# for each association... { my $mcop = Net::OpenWBEM::CIMObjectPath->new($resultClass, $ns);
# fill key properties # ...
$result->handle($mcop); } }
$result->handle($mcop)
$ns - string
$objectName - Net::OpenWBEM::CIMObjectPath
$resultClass - string
$role - string
sub invokeMethod { my ($env, $ns, $objectName, $methodName, $inParams, $outParams) = @_;
# generate a value... my $value = .... return $value; }
Net::OpenWBEM Net::OpenWBEM::Client
Jason Long - jason@long.name
This file is part of owperlprovider.
Copyright (c) 2004-2005 Jason Long. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.