You can subscribe to this list here.
2006 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(26) |
Dec
(13) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2007 |
Jan
(5) |
Feb
(16) |
Mar
(5) |
Apr
(5) |
May
(13) |
Jun
(12) |
Jul
(1) |
Aug
(2) |
Sep
(13) |
Oct
(6) |
Nov
(1) |
Dec
(29) |
2008 |
Jan
(2) |
Feb
(2) |
Mar
(2) |
Apr
(57) |
May
(35) |
Jun
(45) |
Jul
(132) |
Aug
(87) |
Sep
(141) |
Oct
(86) |
Nov
(17) |
Dec
(2) |
2009 |
Jan
(3) |
Feb
(2) |
Mar
(3) |
Apr
(3) |
May
(1) |
Jun
|
Jul
|
Aug
(1) |
Sep
|
Oct
|
Nov
(1) |
Dec
|
2010 |
Jan
(2) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(1) |
Sep
|
Oct
|
Nov
|
Dec
|
From: <ba...@us...> - 2008-09-10 16:29:59
|
Revision: 932 http://omc.svn.sourceforge.net/omc/?rev=932&view=rev Author: bartw Date: 2008-09-10 16:30:11 +0000 (Wed, 10 Sep 2008) Log Message: ----------- fixed concurrency problem in get_key_at Modified Paths: -------------- cmpi-bindings/trunk/swig/cmpi_types.i Modified: cmpi-bindings/trunk/swig/cmpi_types.i =================================================================== --- cmpi-bindings/trunk/swig/cmpi_types.i 2008-09-10 15:59:54 UTC (rev 931) +++ cmpi-bindings/trunk/swig/cmpi_types.i 2008-09-10 16:30:11 UTC (rev 932) @@ -411,11 +411,13 @@ #endif #if defined (SWIGPYTHON) #TODO memory leak alert (clone_data) + SWIG_PYTHON_THREAD_BEGIN_BLOCK; PyObject* pydata = SWIG_NewPointerObj((void*) clone_data(&data), SWIGTYPE_p__CMPIData, 0); PyObject* pl = PyTuple_New(2); PyTuple_SetItem(pl, 0, pydata); PyTuple_SetItem(pl, 1, PyString_FromString(CMGetCharPtr(s))); + SWIG_PYTHON_THREAD_END_BLOCK; return pl; #endif } @@ -626,9 +628,9 @@ #endif #if defined (SWIGPYTHON) #TODO memory leak alert (clone_data) + SWIG_PYTHON_THREAD_BEGIN_BLOCK; PyObject* pydata = SWIG_NewPointerObj((void*) clone_data(&data), SWIGTYPE_p__CMPIData, 0); - SWIG_PYTHON_THREAD_BEGIN_BLOCK; PyObject* pl = PyTuple_New(2); PyTuple_SetItem(pl, 0, pydata); PyTuple_SetItem(pl, 1, PyString_FromString(CMGetCharPtr(s))); @@ -724,9 +726,9 @@ #endif #if defined (SWIGPYTHON) #TODO memory leak alert (clone_data) + SWIG_PYTHON_THREAD_BEGIN_BLOCK; PyObject* pydata = SWIG_NewPointerObj((void*) clone_data(&data), SWIGTYPE_p__CMPIData, 0); - SWIG_PYTHON_THREAD_BEGIN_BLOCK; PyObject* pl = PyTuple_New(2); PyTuple_SetItem(pl, 0, pydata); PyTuple_SetItem(pl, 1, PyString_FromString(CMGetCharPtr(s))); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ba...@us...> - 2008-09-10 15:59:45
|
Revision: 931 http://omc.svn.sourceforge.net/omc/?rev=931&view=rev Author: bartw Date: 2008-09-10 15:59:54 +0000 (Wed, 10 Sep 2008) Log Message: ----------- rigged cmake to show the compilation commands, added -g to C_FLAGS for symbols Modified Paths: -------------- cmpi-bindings/trunk/CMakeLists.txt cmpi-bindings/trunk/swig/python/CMakeLists.txt Modified: cmpi-bindings/trunk/CMakeLists.txt =================================================================== --- cmpi-bindings/trunk/CMakeLists.txt 2008-09-10 13:23:35 UTC (rev 930) +++ cmpi-bindings/trunk/CMakeLists.txt 2008-09-10 15:59:54 UTC (rev 931) @@ -35,6 +35,7 @@ INCLUDE(${CMAKE_SOURCE_DIR}/VERSION.cmake) +SET(CMAKE_VERBOSE_MAKEFILE TRUE) SET( PACKAGE "cmpi-bindings" ) SET( VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}" ) Modified: cmpi-bindings/trunk/swig/python/CMakeLists.txt =================================================================== --- cmpi-bindings/trunk/swig/python/CMakeLists.txt 2008-09-10 13:23:35 UTC (rev 930) +++ cmpi-bindings/trunk/swig/python/CMakeLists.txt 2008-09-10 15:59:54 UTC (rev 931) @@ -30,7 +30,7 @@ DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/../../src/*.c ) -SET( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC" ) +SET( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC -g" ) INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR}/.. ) INCLUDE_DIRECTORIES( ${PYTHON_INCLUDE_PATH} ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <kk...@us...> - 2008-09-10 13:23:28
|
Revision: 930 http://omc.svn.sourceforge.net/omc/?rev=930&view=rev Author: kkaempf Date: 2008-09-10 13:23:35 +0000 (Wed, 10 Sep 2008) Log Message: ----------- add remark about missing symlink Modified Paths: -------------- cmpi-bindings/trunk/swig/python/CMakeLists.txt Modified: cmpi-bindings/trunk/swig/python/CMakeLists.txt =================================================================== --- cmpi-bindings/trunk/swig/python/CMakeLists.txt 2008-09-10 13:07:21 UTC (rev 929) +++ cmpi-bindings/trunk/swig/python/CMakeLists.txt 2008-09-10 13:23:35 UTC (rev 930) @@ -53,7 +53,9 @@ INSTALL(TARGETS ${NAME} LIBRARY DESTINATION ${CMPI_LIBRARY_DIR}) # .py: swig generated INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/cmpi.py DESTINATION ${PYTHON_LIB_DIR}/site-packages ) +#!! needs symlink ${PYTHON_LIB_DIR}/site-packages/_cmpi.so -> ${CMPI_LIBRARY_DIR}/lib${NAME}.so + # # cmpi_bindings.py: provider implementation # This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <kk...@us...> - 2008-09-10 13:07:11
|
Revision: 929 http://omc.svn.sourceforge.net/omc/?rev=929&view=rev Author: kkaempf Date: 2008-09-10 13:07:21 +0000 (Wed, 10 Sep 2008) Log Message: ----------- remove, unneeded since rev 884 Revision Links: -------------- http://omc.svn.sourceforge.net/omc/?rev=884&view=rev Removed Paths: ------------- cmpi-bindings/trunk/src/cmpi_provider.c Deleted: cmpi-bindings/trunk/src/cmpi_provider.c =================================================================== --- cmpi-bindings/trunk/src/cmpi_provider.c 2008-09-10 04:59:41 UTC (rev 928) +++ cmpi-bindings/trunk/src/cmpi_provider.c 2008-09-10 13:07:21 UTC (rev 929) @@ -1,1431 +0,0 @@ -/***************************************************************************** -* Copyright (C) 2008 Novell Inc. All rights reserved. -* Copyright (C) 2008 SUSE Linux Products GmbH. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are met: -* -* - Redistributions of source code must retain the above copyright notice, -* this list of conditions and the following disclaimer. -* -* - Redistributions in binary form must reproduce the above copyright notice, -* this list of conditions and the following disclaimer in the documentation -* and/or other materials provided with the distribution. -* -* - Neither the name of Novell Inc. nor of SUSE Linux Products GmbH nor the -* names of its contributors may be used to endorse or promote products -* derived from this software without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' -* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -* ARE DISCLAIMED. IN NO EVENT SHALL Novell Inc. OR SUSE Linux Products GmbH OR -* THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*****************************************************************************/ - -#ifdef SWIGRUBY -static char _CLASSNAME[] = "CmpiInstanceRuby"; -#endif -#ifdef SWIGPYTHON -static char _CLASSNAME[] = "CmpiInstanceSwig"; -#endif - -#include <stdio.h> -#include <stdarg.h> - -/* Include the required CMPI macros, data types, and API function headers */ -#include <cmpidt.h> -#include <cmpift.h> -#include <cmpimacs.h> - -// Needed to obtain errno of failed system calls -#include <errno.h> - -/* Needed for kill() */ -#include <signal.h> - - -#ifdef SWIGRUBY -#include <ruby.h> -#endif - -#ifdef SWIGPYTHON -#include <Python.h> -#endif - -/* A simple stderr logging/tracing facility. */ -#ifndef _SBLIM_TRACE -#define _SBLIM_TRACE(tracelevel,args) _logstderr args -void _logstderr(char *fmt,...) -{ - va_list ap; - va_start(ap,fmt); - vfprintf(stderr,fmt,ap); - va_end(ap); - fprintf(stderr,"\n"); -} -#endif - -/* Global handle to the CIM broker. This is initialized by the CIMOM when the provider is loaded */ -static const CMPIBroker * _BROKER = NULL; -static char* _MINAME = NULL; -#ifdef SWIGPYTHON -PyObject* _PYPROVMOD = NULL; -#endif - -static char* fmtstr(const char* fmt, ...) -{ - va_list ap; - int len; - va_start(ap, fmt); - len = vsnprintf(NULL, 0, fmt, ap); - va_end(ap); - if (len <= 0) - { - return NULL; - } - char* str = (char*)malloc(len+1); - if (str == NULL) - { - return NULL; - } - va_start(ap, fmt); - vsnprintf(str, len+1, fmt, ap); - va_end(ap); - return str; -} - -#ifdef SWIGRUBY -static int RBInitialize(CMPIInstanceMI * self, CMPIStatus* st); -#endif - -#ifdef SWIGPYTHON -static int PyInitialize(PyObject** self, CMPIStatus* st); -#define PY_CMPI_INIT { if (self->hdl == NULL) if (PyInitialize((PyObject**)&(self->hdl), &status) != 0) return status; } -#endif - -#ifdef SWIGRUBY -static VALUE -properties2ruby( const char ** properties ) -{ - if (properties) { - VALUE rproperties = rb_ary_new(); - while (*properties) - rb_ary_push( rproperties, rb_str_new2(*properties++) ); - return rproperties; - } - return Qnil; -} -#endif - -#ifdef SWIGPYTHON -static PyObject* proplist2py(const char** cplist) -{ - if (cplist == NULL) - { - Py_RETURN_NONE; - } - PyObject* pl = PyList_New(0); - for (; *cplist != NULL; ++cplist) - { - PyList_Append(pl, PyString_FromString(*cplist)); - } - return pl; -} - - - -#define TB_ERROR(str) {tbstr = str; goto cleanup;} -static CMPIString* get_exc_trace() -{ - char *tbstr = NULL; - - PyObject *iostrmod = NULL; - PyObject *tbmod = NULL; - PyObject *iostr = NULL; - PyObject *obstr = NULL; - PyObject *args = NULL; - PyObject *newstr = NULL; - PyObject *func = NULL; - CMPIString* rv = NULL; - - PyObject *type, *value, *traceback; - _SBLIM_TRACE(1, ("PyErr_Occurred() %d", PyErr_Occurred())); - PyErr_Fetch(&type, &value, &traceback); - _SBLIM_TRACE(1,("** type %p, value %p, traceback %p", type, value, traceback)); - PyErr_Print(); - PyErr_Clear(); - PyErr_NormalizeException(&type, &value, &traceback); - _SBLIM_TRACE(1,("** type %p, value %p, traceback %p", type, value, traceback)); - - iostrmod = PyImport_ImportModule("StringIO"); - if (iostrmod==NULL) - TB_ERROR("can't import StringIO"); - - iostr = PyObject_CallMethod(iostrmod, "StringIO", NULL); - - if (iostr==NULL) - TB_ERROR("cStringIO.StringIO() failed"); - - tbmod = PyImport_ImportModule("traceback"); - if (tbmod==NULL) - TB_ERROR("can't import traceback"); - - obstr = PyObject_CallMethod(tbmod, "print_exception", - "(OOOOO)", - type ? type : Py_None, - value ? value : Py_None, - traceback ? traceback : Py_None, - Py_None, - iostr); - - if (obstr==NULL) - { - PyErr_Print(); - TB_ERROR("traceback.print_exception() failed"); - } - - Py_DecRef(obstr); - - obstr = PyObject_CallMethod(iostr, "getvalue", NULL); - if (obstr==NULL) - TB_ERROR("getvalue() failed."); - - if (!PyString_Check(obstr)) - TB_ERROR("getvalue() did not return a string"); - - args = PyTuple_New(2); - PyTuple_SetItem(args, 0, PyString_FromString("\n")); - PyTuple_SetItem(args, 1, PyString_FromString("<br>")); - - func = PyObject_GetAttrString(obstr, "replace"); - //newstr = PyObject_CallMethod(obstr, "replace", args); - newstr = PyObject_CallObject(func, args); - - tbstr = PyString_AsString(newstr); - - char* tmp = fmtstr("cmpi:%s", tbstr); - rv = _BROKER->eft->newString(_BROKER, tmp, NULL); - free(tmp); - -cleanup: - PyErr_Restore(type, value, traceback); - - if (rv == NULL) - { - rv = _BROKER->eft->newString(_BROKER, tbstr ? tbstr : "", NULL); - } - - Py_DecRef(func); - Py_DecRef(args); - Py_DecRef(newstr); - Py_DecRef(iostr); - Py_DecRef(obstr); - Py_DecRef(iostrmod); - Py_DecRef(tbmod); - - - return rv; -} - - - -static int -call_py_provider(PyObject* hdl, CMPIStatus* st, - const char* opname, int nargs, ...) -{ - int rc = 1; - va_list vargs; - PyObject *pyargs = NULL; - PyObject *pyfunc = NULL; - PyObject *prv = NULL; - pyargs = PyTuple_New(nargs); - pyfunc = PyObject_GetAttrString(hdl, opname); - if (pyfunc == NULL) - { - PyErr_Print(); - PyErr_Clear(); - char* str = fmtstr("Python module does not contain \"%s\"", opname); - _SBLIM_TRACE(1,(str)); - st->rc = CMPI_RC_ERR_FAILED; - st->msg = _BROKER->eft->newString(_BROKER, str, NULL); - free(str); - rc = 1; - goto cleanup; - } - if (! PyCallable_Check(pyfunc)) - { - char* str = fmtstr("Python module attribute \"%s\" is not callable", - opname); - _SBLIM_TRACE(1,(str)); - st->rc = CMPI_RC_ERR_FAILED; - st->msg = _BROKER->eft->newString(_BROKER, str, NULL); - free(str); - rc = 1; - goto cleanup; - } - - va_start(vargs, nargs); - int i; - for (i = 0; i < nargs; ++i) - { - PyObject* arg = va_arg(vargs, PyObject*); - if (arg == NULL) - { - arg = Py_None; - Py_IncRef(arg); - } - PyTuple_SET_ITEM(pyargs, i, arg); - } - va_end(vargs); - prv = PyObject_CallObject(pyfunc, pyargs); - if (PyErr_Occurred()) - { - st->rc = CMPI_RC_ERR_FAILED; - st->msg = get_exc_trace(); - PyErr_Clear(); - rc = 1; - goto cleanup; - } - - if (! PyTuple_Check(prv) || - (PyTuple_Size(prv) != 2 && PyTuple_Size(prv) != 1)) - { - char* str = fmtstr("Python function \"%s\" didn't return a two-tuple", - opname); - _SBLIM_TRACE(1,(str)); - st->rc = CMPI_RC_ERR_FAILED; - st->msg = _BROKER->eft->newString(_BROKER, str, NULL); - free(str); - rc = 1; - goto cleanup; - } - PyObject* prc = PyTuple_GetItem(prv, 0); - PyObject* prstr = Py_None; - if (PyTuple_Size(prv) == 2) - { - prstr = PyTuple_GetItem(prv, 1); - } - - if (! PyInt_Check(prc) || (! PyString_Check(prstr) && prstr != Py_None)) - { - char* str = fmtstr("Python function \"%s\" didn't return a {<int>, <str>) two-tuple", opname); - _SBLIM_TRACE(1,(str)); - st->rc = CMPI_RC_ERR_FAILED; - st->msg = _BROKER->eft->newString(_BROKER, str, NULL); - free(str); - rc = 1; - goto cleanup; - } - long pi = PyInt_AsLong(prc); - st->rc = (CMPIrc)pi; - if (prstr == Py_None) - { - st->msg = _BROKER->eft->newString(_BROKER, "", NULL); - } - else - { - st->msg = _BROKER->eft->newString(_BROKER, PyString_AsString(prstr), NULL); - } - rc = pi != 0; -cleanup: - Py_DecRef(pyargs); - Py_DecRef(pyfunc); - Py_DecRef(prv); - return rc; -} -#endif - - -// ---------------------------------------------------------------------------- -// CMPI INSTANCE PROVIDER FUNCTIONS -// ---------------------------------------------------------------------------- - -static CMPIStatus Cleanup( - const CMPIContext * context, - CMPIBoolean terminating) -{ - CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */ - - _SBLIM_TRACE(1,("Cleanup() called")); - -#ifdef SWIGRUBY - ruby_finalize(); - _SBLIM_TRACE(1,("Cleanup(Ruby) called")); -#endif - -#ifdef SWIGPYTHON - Py_DecRef(_PYPROVMOD); - Py_Finalize(); - _SBLIM_TRACE(1,("Cleanup(Python) called")); -#endif - - if (_MINAME != NULL) - { - free(_MINAME); - _MINAME = NULL; - } - - /* Finished. */ -exit: - _SBLIM_TRACE(1,("Cleanup() %s", (status.rc == CMPI_RC_OK)? "succeeded":"failed")); - return status; -} - -static CMPIStatus InstCleanup( - CMPIInstanceMI * self, - const CMPIContext * context, - CMPIBoolean terminating) -{ - return Cleanup(context, terminating); -} - -static CMPIStatus AssocCleanup( - CMPIAssociationMI * self, - const CMPIContext * context, - CMPIBoolean terminating) -{ - return Cleanup(context, terminating); -} - -static CMPIStatus MethodCleanup( - CMPIMethodMI * self, - const CMPIContext * context, - CMPIBoolean terminating) -{ - return Cleanup(context, terminating); -} - -static CMPIStatus IndicationCleanup( - CMPIIndicationMI * self, - const CMPIContext * context, - CMPIBoolean terminating) -{ - return Cleanup(context, terminating); -} - -// ---------------------------------------------------------------------------- - - -/* EnumInstanceNames() - return a list of all the instances names (i.e. return their object paths only) */ -static CMPIStatus EnumInstanceNames( - CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self') */ - const CMPIContext * context, /* [in] Additional context info, if any */ - const CMPIResult * result, /* [in] Contains the CIM namespace and classname */ - const CMPIObjectPath * reference) /* [in] Contains the CIM namespace and classname */ -{ - CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations */ - - _SBLIM_TRACE(1,("EnumInstanceNames() called")); - -#ifdef SWIGRUBY - _SBLIM_TRACE(1,("EnumInstanceNames(Ruby) called, context %p, result %p, reference %p", context, result, reference)); - VALUE klass = (VALUE)self->hdl; - VALUE rcontext = SWIG_NewPointerObj((void*) context, SWIGTYPE_p__CMPIContext, 0); - VALUE rresult = SWIG_NewPointerObj((void*) result, SWIGTYPE_p__CMPIResult, 0); - VALUE rreference = SWIG_NewPointerObj((void*) reference, SWIGTYPE_p__CMPIObjectPath, 0); - - /* enum_instance_names instead of EnumInstanceNames to follow Ruby naming convention */ - VALUE r = rb_funcall( klass, rb_intern( "enum_instance_names" ), 3, rcontext, rresult, rreference ); - _SBLIM_TRACE(1,("r %p", r)); -#endif -#ifdef SWIGPYTHON - _SBLIM_TRACE(1,("EnumInstancesNames(Python) called, context %p, result %p, reference %p", context, result, reference)); - - PY_CMPI_INIT - - PyObject *pycontext = SWIG_NewPointerObj((void*) context, SWIGTYPE_p__CMPIContext, 0); - PyObject *pyresult = SWIG_NewPointerObj((void*) result, SWIGTYPE_p__CMPIResult, 0); - PyObject *pyreference = SWIG_NewPointerObj((void*) reference, SWIGTYPE_p__CMPIObjectPath, 0); - - call_py_provider((PyObject*)self->hdl, &status, "enum_instance_names", 3, - pycontext, - pyresult, - pyreference); -#endif - -exit: - _SBLIM_TRACE(1,("EnumInstanceNames() %s", (status.rc == CMPI_RC_OK)? "succeeded":"failed")); - return status; -} - - -// ---------------------------------------------------------------------------- - - -/* EnumInstances() - return a list of all the instances (i.e. return all the instance data) */ -static CMPIStatus EnumInstances( - CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self') */ - const CMPIContext * context, /* [in] Additional context info, if any */ - const CMPIResult * result, /* [in] Contains the CIM namespace and classname */ - const CMPIObjectPath * reference, /* [in] Contains the CIM namespace and classname */ - const char ** properties) /* [in] List of desired properties (NULL=all) */ -{ - CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations */ -/* char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); Our current CIM namespace */ - -#ifdef SWIGRUBY - _SBLIM_TRACE(1,("EnumInstances(Ruby) called, context %p, result %p, reference %p, properties %p", context, result, reference, properties)); - VALUE klass = (VALUE)self->hdl; - VALUE rcontext = SWIG_NewPointerObj((void*) context, SWIGTYPE_p__CMPIContext, 0); - VALUE rresult = SWIG_NewPointerObj((void*) result, SWIGTYPE_p__CMPIResult, 0); - VALUE rreference = SWIG_NewPointerObj((void*) reference, SWIGTYPE_p__CMPIObjectPath, 0); - VALUE rproperties = properties2ruby( properties ); - /* enum_instances instead of EnumInstances to follow Ruby naming convention */ - VALUE r = rb_funcall( klass, rb_intern( "enum_instances" ), 4, rcontext, rresult, rreference, rproperties ); - _SBLIM_TRACE(1,("r %p", r)); -#endif -#ifdef SWIGPYTHON - _SBLIM_TRACE(1,("EnumInstances(Python) called, context %p, result %p, reference %p, properties %p", context, result, reference, properties)); - - PY_CMPI_INIT - - PyObject *pycontext = SWIG_NewPointerObj((void*) context, SWIGTYPE_p__CMPIContext, 0); - PyObject *pyresult = SWIG_NewPointerObj((void*) result, SWIGTYPE_p__CMPIResult, 0); - PyObject *pyreference = SWIG_NewPointerObj((void*) reference, SWIGTYPE_p__CMPIObjectPath, 0); - PyObject *pyproperties = proplist2py(properties); - - call_py_provider((PyObject*)self->hdl, &status, "enum_instances", 4, - pycontext, - pyresult, - pyreference, - pyproperties); -#endif - -exit: - _SBLIM_TRACE(1,("EnumInstances() %s", (status.rc == CMPI_RC_OK)? "succeeded":"failed")); - return status; -} - - -// ---------------------------------------------------------------------------- - - -/* GetInstance() - return the instance data for the specified instance only */ -static CMPIStatus GetInstance( - CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self') */ - const CMPIContext * context, /* [in] Additional context info, if any */ - const CMPIResult * results, /* [out] Results of this operation */ - const CMPIObjectPath * reference, /* [in] Contains the CIM namespace, classname and desired object path */ - const char ** properties) /* [in] List of desired properties (NULL=all) */ -{ - CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations */ - -#ifdef SWIGRUBY - _SBLIM_TRACE(1,("GetInstance(Ruby) called, context %p, results %p, reference %p, properties %p", context, results, reference, properties)); - VALUE klass = (VALUE)self->hdl; - VALUE rcontext = SWIG_NewPointerObj((void*) context, SWIGTYPE_p__CMPIContext, 0); - VALUE rresults = SWIG_NewPointerObj((void*) results, SWIGTYPE_p__CMPIResult, 0); - VALUE rreference = SWIG_NewPointerObj((void*) reference, SWIGTYPE_p__CMPIObjectPath, 0); - VALUE rproperties = properties2ruby( properties ); - /* get_instance instead of GetInstance to follow Ruby naming convention */ - VALUE r = rb_funcall( klass, rb_intern( "get_instance" ), 4, rcontext, rresults, rreference, rproperties ); - _SBLIM_TRACE(1,("r %p", r)); -#endif -#ifdef SWIGPYTHON - _SBLIM_TRACE(1,("GetInstance(Python) called, context %p, results %p, reference %p, properties %p", context, results, reference, properties)); - - PY_CMPI_INIT - - PyObject *pycontext = SWIG_NewPointerObj((void*) context, SWIGTYPE_p__CMPIContext, 0); - PyObject *pyresult = SWIG_NewPointerObj((void*) results, SWIGTYPE_p__CMPIResult, 0); - PyObject *pyreference = SWIG_NewPointerObj((void*) reference, SWIGTYPE_p__CMPIObjectPath, 0); - PyObject *pyproperties = proplist2py(properties); - - call_py_provider((PyObject*)self->hdl, &status, "get_instance", 4, - pycontext, - pyresult, - pyreference, - pyproperties); -#endif - -exit: - _SBLIM_TRACE(1,("GetInstance() %s", (status.rc == CMPI_RC_OK)? "succeeded":"failed")); - return status; -} - - -// ---------------------------------------------------------------------------- - - -/* CreateInstance() - create a new instance from the specified instance data. */ -static CMPIStatus CreateInstance( - CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self') */ - const CMPIContext * context, /* [in] Additional context info, if any. */ - const CMPIResult * results, /* [out] Results of this operation */ - const CMPIObjectPath * reference, /* [in] Contains the target namespace, classname and objectpath. */ - const CMPIInstance * newinstance) /* [in] Contains all the new instance data. */ -{ - CMPIStatus status = {CMPI_RC_ERR_NOT_SUPPORTED, NULL}; /* Return status of CIM operations. */ - - /* Creating new instances is not supported for this class. */ - -#ifdef SWIGRUBY - _SBLIM_TRACE(1,("CreateInstance(Ruby) called, context %p, results %p, reference %p, instance %p, properties %p", context, results, reference, newinstance)); - VALUE klass = (VALUE)self->hdl; - VALUE rcontext = SWIG_NewPointerObj((void*) context, SWIGTYPE_p__CMPIContext, 0); - VALUE rresults = SWIG_NewPointerObj((void*) results, SWIGTYPE_p__CMPIResult, 0); - VALUE rreference = SWIG_NewPointerObj((void*) reference, SWIGTYPE_p__CMPIObjectPath, 0); - VALUE rinstance = SWIG_NewPointerObj((void*) newinstance, SWIGTYPE_p__CMPIInstance, 0); - /* create_instance instead of CreateInstance to follow Ruby naming convention */ - VALUE r = rb_funcall( klass, rb_intern( "create_instance" ), 4, rcontext, rresults, rreference, rinstance ); - _SBLIM_TRACE(1,("r %p", r)); -#endif -#ifdef SWIGPYTHON - _SBLIM_TRACE(1,("CreateInstance(Python) called, context %p, results %p, reference %p, newinstance %p", context, results, reference, newinstance)); - - PY_CMPI_INIT - - PyObject *pycontext = SWIG_NewPointerObj((void*) context, SWIGTYPE_p__CMPIContext, 0); - PyObject *pyresult = SWIG_NewPointerObj((void*) results, SWIGTYPE_p__CMPIResult, 0); - PyObject *pyreference = SWIG_NewPointerObj((void*) reference, SWIGTYPE_p__CMPIObjectPath, 0); - PyObject *pynewinst = SWIG_NewPointerObj((void*) newinstance, SWIGTYPE_p__CMPIInstance, 0); - - call_py_provider((PyObject*)self->hdl, &status, "create_instance", 4, - pycontext, - pyresult, - pyreference, - pynewinst); -#endif - - /* Finished. */ -exit: - _SBLIM_TRACE(1,("CreateInstance() %s", (status.rc == CMPI_RC_OK)? "succeeded":"failed")); - return status; -} - - -// ---------------------------------------------------------------------------- - -#ifdef CMPI_VER_100 -#define SetInstance ModifyInstance -#endif - -/* SetInstance() - save modified instance data for the specified instance. */ -static CMPIStatus SetInstance( - CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */ - const CMPIContext * context, /* [in] Additional context info, if any. */ - const CMPIResult * results, /* [out] Results of this operation. */ - const CMPIObjectPath * reference, /* [in] Contains the target namespace, classname and objectpath. */ - const CMPIInstance * newinstance, /* [in] Contains all the new instance data. */ - const char ** properties) /* [in] List of desired properties (NULL=all) */ -{ - CMPIStatus status = {CMPI_RC_ERR_NOT_SUPPORTED, NULL}; /* Return status of CIM operations. */ - - /* Modifying existing instances is not supported for this class. */ - -#ifdef SWIGRUBY - _SBLIM_TRACE(1,("SetInstance(Ruby) called, context %p, results %p, reference %p, instance %p, properties %p", context, results, reference, newinstance, properties)); - VALUE klass = (VALUE)self->hdl; - VALUE rcontext = SWIG_NewPointerObj((void*) context, SWIGTYPE_p__CMPIContext, 0); - VALUE rresults = SWIG_NewPointerObj((void*) results, SWIGTYPE_p__CMPIResult, 0); - VALUE rreference = SWIG_NewPointerObj((void*) reference, SWIGTYPE_p__CMPIObjectPath, 0); - VALUE rinstance = SWIG_NewPointerObj((void*) newinstance, SWIGTYPE_p__CMPIInstance, 0); - VALUE rproperties = properties2ruby( properties ); - /* set_instance instead of SetInstance to follow Ruby naming convention */ - VALUE r = rb_funcall( klass, rb_intern( "set_instance" ), 5, rcontext, rresults, rreference, rinstance, rproperties ); - _SBLIM_TRACE(1,("r %p", r)); -#endif -#ifdef SWIGPYTHON - _SBLIM_TRACE(1,("SetInstance(Python) called, context %p, results %p, reference %p, newinstance %p, properties %p", context, results, reference, newinstance, properties)); - - PY_CMPI_INIT - - PyObject *pycontext = SWIG_NewPointerObj((void*) context, SWIGTYPE_p__CMPIContext, 0); - PyObject *pyresult = SWIG_NewPointerObj((void*) results, SWIGTYPE_p__CMPIResult, 0); - PyObject *pyreference = SWIG_NewPointerObj((void*) reference, SWIGTYPE_p__CMPIObjectPath, 0); - PyObject *pynewinst = SWIG_NewPointerObj((void*) newinstance, SWIGTYPE_p__CMPIInstance, 0); - PyObject *plist = proplist2py(properties); - - call_py_provider((PyObject*)self->hdl, &status, "set_instance", 5, - pycontext, - pyresult, - pyreference, - pynewinst, - plist); -#endif - - /* Finished. */ -exit: - _SBLIM_TRACE(1,("SetInstance() %s", (status.rc == CMPI_RC_OK)? "succeeded":"failed")); - return status; -} - -// ---------------------------------------------------------------------------- - - -/* DeleteInstance() - delete/remove the specified instance. */ -static CMPIStatus DeleteInstance( - CMPIInstanceMI * self, - const CMPIContext * context, - const CMPIResult * results, - const CMPIObjectPath * reference) -{ - CMPIStatus status = {CMPI_RC_OK, NULL}; - -#ifdef SWIGRUBY - _SBLIM_TRACE(1,("DeleteInstance(Ruby) called, context %p, results %p, reference %p", context, results, reference)); - VALUE klass = (VALUE)self->hdl; - VALUE rcontext = SWIG_NewPointerObj((void*) context, SWIGTYPE_p__CMPIContext, 0); - VALUE rresults = SWIG_NewPointerObj((void*) results, SWIGTYPE_p__CMPIResult, 0); - VALUE rreference = SWIG_NewPointerObj((void*) reference, SWIGTYPE_p__CMPIObjectPath, 0); - /* delete_instance instead of DeleteInstance to follow Ruby naming convention */ - VALUE r = rb_funcall( klass, rb_intern( "delete_instance" ), 3, rcontext, rresults, rreference ); - _SBLIM_TRACE(1,("r %p", r)); -#endif -#ifdef SWIGPYTHON - _SBLIM_TRACE(1,("DeleteInstance(Python) called, context %p, results %p, reference %p", context, results, reference)); - - PY_CMPI_INIT - - PyObject *pycontext = SWIG_NewPointerObj((void*) context, SWIGTYPE_p__CMPIContext, 0); - PyObject *pyresult = SWIG_NewPointerObj((void*) results, SWIGTYPE_p__CMPIResult, 0); - PyObject *pyreference = SWIG_NewPointerObj((void*) reference, SWIGTYPE_p__CMPIObjectPath, 0); - - call_py_provider((PyObject*)self->hdl, &status, "delete_instance", 3, - pycontext, - pyresult, - pyreference); -#endif - - /* Finished. */ -exit: - _SBLIM_TRACE(1,("DeleteInstance() %s", (status.rc == CMPI_RC_OK)? "succeeded":"failed")); - return status; -} - -// ---------------------------------------------------------------------------- - - -/* ExecQuery() - return a list of all the instances that satisfy the desired query filter. */ -static CMPIStatus ExecQuery( - CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */ - const CMPIContext * context, /* [in] Additional context info, if any. */ - const CMPIResult * results, /* [out] Results of this operation. */ - const CMPIObjectPath * reference, /* [in] Contains the target namespace and classname. */ - const char * query, /* [in] Text of the query, written in the query language. */ - const char * language) /* [in] Name of the query language (e.g. "WQL"). */ -{ - CMPIStatus status = {CMPI_RC_ERR_NOT_SUPPORTED, NULL}; /* Return status of CIM operations. */ - -#ifdef SWIGRUBY - _SBLIM_TRACE(1,("ExecQuery(Ruby) called, context %p, results %p, reference %p, query %s, language %s", context, results, reference, query, language)); - VALUE klass = (VALUE)self->hdl; - VALUE rcontext = SWIG_NewPointerObj((void*) context, SWIGTYPE_p__CMPIContext, 0); - VALUE rresults = SWIG_NewPointerObj((void*) results, SWIGTYPE_p__CMPIResult, 0); - VALUE rreference = SWIG_NewPointerObj((void*) reference, SWIGTYPE_p__CMPIObjectPath, 0); - VALUE rquery = rb_str_new2( query ); - VALUE rlanguage = rb_str_new2( language ); - /* exec_query instead of ExecQuery to follow Ruby naming convention */ - VALUE r = rb_funcall( klass, rb_intern( "exec_query" ), 5, rcontext, rresults, rreference, query, language ); - _SBLIM_TRACE(1,("r %p", r)); -#endif -#ifdef SWIGPYTHON - _SBLIM_TRACE(1,("ExecQuery(Python) called, context %p, results %p, reference %p, query %s, language %s", context, results, reference, query, language)); - - PY_CMPI_INIT - - PyObject *pycontext = SWIG_NewPointerObj((void*) context, SWIGTYPE_p__CMPIContext, 0); - PyObject *pyresult = SWIG_NewPointerObj((void*) results, SWIGTYPE_p__CMPIResult, 0); - PyObject *pyreference = SWIG_NewPointerObj((void*) reference, SWIGTYPE_p__CMPIObjectPath, 0); - PyObject *pyquery = PyString_FromString(query); - PyObject *pylang = PyString_FromString(language); - - call_py_provider((PyObject*)self->hdl, &status, "exec_query", 5, - pycontext, - pyresult, - pyreference, - pyquery, - pylang); -#endif - - /* Query filtering is not supported for this class. */ - - /* Finished. */ -exit: - _SBLIM_TRACE(1,("ExecQuery() %s", (status.rc == CMPI_RC_OK)? "succeeded":"failed")); - return status; -} - - -// ---------------------------------------------------------------------------- - -#ifdef SWIGRUBY -static VALUE load_code() -{ - _SBLIM_TRACE(1,("Ruby: require 'rcmpi_instance'...")); - - rb_require("rcmpi_instance"); - - _SBLIM_TRACE(1,("Ruby: ... done")); -} - -static VALUE create_cmpi(VALUE args) -{ - VALUE *values = (VALUE *)args; - _SBLIM_TRACE(1,("Ruby: Cmpi_Instance.new ...")); - VALUE klass = rb_class_new_instance(1, values, rb_const_get(rb_cObject, rb_intern("Cmpi_Instance"))); - _SBLIM_TRACE(1,("Ruby: ... done")); - return klass; -} -#endif - -#ifdef SWIGRUBY -/* Initialize() - perform any necessary initialization immediately after this provider is loaded. */ -static int RBInitialize( - CMPIInstanceMI * self, CMPIStatus* st) /* [in] Handle to this provider (i.e. 'self'). */ -{ - int rc = 0; - if (st != NULL) - { - st->rc = CMPI_RC_OK; - st->msg = NULL; - } - int error = 0; - VALUE cmpiInstance; - SWIGEXPORT void SWIG_init(void); - - _SBLIM_TRACE(1,("Initialize() called")); - - _SBLIM_TRACE(1,("Ruby: Loading")); - ruby_init(); - ruby_init_loadpath(); - ruby_script("rcmpi_instance"); - SWIG_init(); - - rb_protect(load_code, Qnil, &error); - if (error) { - _SBLIM_TRACE(1,("Ruby: FAILED loading rcmpi_instance.rb")); - if (st != NULL) - { - st->rc = CMPI_RC_ERR_FAILED; - } - } - else { - _SBLIM_TRACE(1,("Ruby: loaded rcmpi_instance.rb")); - VALUE args[1]; - args[0] = rb_str_new2(_CLASSNAME); - cmpiInstance = rb_protect(create_cmpi, (VALUE)args, &error); - if (error) { - _SBLIM_TRACE(1,("Ruby: FAILED creating Cmpi")); - if (st != NULL) - { - st->rc = CMPI_RC_ERR_FAILED; - } - } - else { - _SBLIM_TRACE(1,("Ruby: cmpi at %p", cmpiInstance)); - self->hdl = (void *)cmpiInstance; - } - } - - /* Finished. */ -exit: - _SBLIM_TRACE(1,("Initialize() %s", (rc == 0)? "succeeded":"failed")); - return rc; -} -#endif - -#ifdef SWIGPYTHON -#define PY_CMPI_SETFAIL(msgstr) {if (st != NULL) st->rc = CMPI_RC_ERR_FAILED; st->msg = msgstr; } -static int PyInitialize(PyObject** self, CMPIStatus* st) -{ - int rc = 0; - SWIGEXPORT void SWIG_init(void); - - _SBLIM_TRACE(1,("PyInitialize() called")); - - - _SBLIM_TRACE(1,("Python: Loading")); - Py_SetProgramName("cmpi_swig"); - Py_Initialize(); - SWIG_init(); - - _PYPROVMOD = PyImport_ImportModule("pycmpi_provider"); - if (_PYPROVMOD == NULL) - { - _SBLIM_TRACE(1,("Python: _PYPROVMOD at %p", _PYPROVMOD)); - PY_CMPI_SETFAIL(get_exc_trace()); - return -1; - } - _SBLIM_TRACE(1,("Python: _PYPROVMOD at %p", _PYPROVMOD)); - PyObject* provclass = PyObject_GetAttrString(_PYPROVMOD, - "CMPIProvider"); - if (provclass == NULL) - { - PY_CMPI_SETFAIL(get_exc_trace()); - return -1; - } - PyObject* broker = SWIG_NewPointerObj((void*) _BROKER, SWIGTYPE_p__CMPIBroker, 0); - PyObject* args = PyTuple_New(2); - PyTuple_SetItem(args, 0, PyString_FromString(_MINAME)); - PyTuple_SetItem(args, 1, broker); - PyObject* provinst = PyObject_CallObject(provclass, args); - Py_DecRef(args); - Py_DecRef(provclass); - if (provinst == NULL) - { - PY_CMPI_SETFAIL(get_exc_trace()); - return -1; - } - - *self = provinst; - - _SBLIM_TRACE(1,("PyInitialize() succeeded")); - return 0; -} -#endif - - - -// associatorMIFT -// - -CMPIStatus associatorNames( - CMPIAssociationMI* self, - const CMPIContext* ctx, - const CMPIResult* rslt, - const CMPIObjectPath* objName, - const char* assocClass, - const char* resultClass, - const char* role, - const char* resultRole) -{ - CMPIStatus status = {CMPI_RC_ERR_NOT_SUPPORTED, NULL}; - -#ifdef SWIGPYTHON - _SBLIM_TRACE(1,("associatorNames(Python) called, ctx %p, rslt %p, objName %p, assocClass %s, resultClass %s, role %s, resultRole %s", ctx, rslt, objName, assocClass, resultClass, role, resultRole)); - - PY_CMPI_INIT - - PyObject *pyctx = SWIG_NewPointerObj((void*) ctx, SWIGTYPE_p__CMPIContext, 0); - PyObject *pyrslt = SWIG_NewPointerObj((void*) rslt, SWIGTYPE_p__CMPIResult, 0); - PyObject *pyobjName = SWIG_NewPointerObj((void*) objName, SWIGTYPE_p__CMPIObjectPath, 0); - PyObject *pyassocClass = NULL; - PyObject *pyresultClass = NULL; - PyObject* pyrole = NULL; - PyObject* pyresultRole = NULL; - if (assocClass != NULL) - { - pyassocClass = PyString_FromString(assocClass); - } - if (resultClass != NULL) - { - pyresultClass = PyString_FromString(resultClass); - } - if (role != NULL) - { - pyrole = PyString_FromString(role); - } - if (resultRole != NULL) - { - pyresultRole = PyString_FromString(resultRole); - } - - call_py_provider((PyObject*)self->hdl, &status, "associator_names", 7, - pyctx, - pyrslt, - pyobjName, - pyassocClass, - pyresultClass, - pyrole, - pyresultRole); -#endif - - /* Query filtering is not supported for this class. */ - - /* Finished. */ -exit: - _SBLIM_TRACE(1,("associatorNames() %s", (status.rc == CMPI_RC_OK)? "succeeded":"failed")); - return status; -} - -/***************************************************************************/ -CMPIStatus associators( - CMPIAssociationMI* self, - const CMPIContext* ctx, - const CMPIResult* rslt, - const CMPIObjectPath* objName, - const char* assocClass, - const char* resultClass, - const char* role, - const char* resultRole, - const char** properties) -{ - CMPIStatus status = {CMPI_RC_ERR_NOT_SUPPORTED, NULL}; - -#ifdef SWIGPYTHON - _SBLIM_TRACE(1,("associators(Python) called, ctx %p, rslt %p, objName %p, assocClass %s, resultClass %s, role %s, resultRole %s", ctx, rslt, objName, assocClass, resultClass, role, resultRole)); - - PY_CMPI_INIT - - PyObject *pyctx = SWIG_NewPointerObj((void*) ctx, SWIGTYPE_p__CMPIContext, 0); - PyObject *pyrslt = SWIG_NewPointerObj((void*) rslt, SWIGTYPE_p__CMPIResult, 0); - PyObject *pyobjName = SWIG_NewPointerObj((void*) objName, SWIGTYPE_p__CMPIObjectPath, 0); - PyObject *pyprops = proplist2py(properties); - PyObject *pyassocClass = NULL; - PyObject *pyresultClass = NULL; - PyObject* pyrole = NULL; - PyObject* pyresultRole = NULL; - if (assocClass != NULL) - { - pyassocClass = PyString_FromString(assocClass); - } - if (resultClass != NULL) - { - pyresultClass = PyString_FromString(resultClass); - } - if (role != NULL) - { - pyrole = PyString_FromString(role); - } - if (resultRole != NULL) - { - pyresultRole = PyString_FromString(resultRole); - } - - call_py_provider((PyObject*)self->hdl, &status, "associators", 8, - pyctx, - pyrslt, - pyobjName, - pyassocClass, - pyresultClass, - pyrole, - pyresultRole, - pyprops); -#endif - - /* Query filtering is not supported for this class. */ - - /* Finished. */ -exit: - _SBLIM_TRACE(1,("associators() %s", (status.rc == CMPI_RC_OK)? "succeeded":"failed")); - return status; -} - -/***************************************************************************/ -CMPIStatus referenceNames( - CMPIAssociationMI* self, - const CMPIContext* ctx, - const CMPIResult* rslt, - const CMPIObjectPath* objName, - const char* resultClass, - const char* role) -{ - CMPIStatus status = {CMPI_RC_ERR_NOT_SUPPORTED, NULL}; - -#ifdef SWIGPYTHON - _SBLIM_TRACE(1,("referenceNames(Python) called, ctx %p, rslt %p, objName %p, resultClass %s, role %s", ctx, rslt, objName, resultClass, role)); - - PY_CMPI_INIT - - PyObject *pyctx = SWIG_NewPointerObj((void*) ctx, SWIGTYPE_p__CMPIContext, 0); - PyObject *pyrslt = SWIG_NewPointerObj((void*) rslt, SWIGTYPE_p__CMPIResult, 0); - PyObject *pyobjName = SWIG_NewPointerObj((void*) objName, SWIGTYPE_p__CMPIObjectPath, 0); - PyObject* pyresultClass = NULL; - PyObject* pyrole = NULL; - if (role != NULL) - { - pyrole = PyString_FromString(role); - } - if (resultClass != NULL) - { - pyresultClass = PyString_FromString(resultClass); - } - - call_py_provider((PyObject*)self->hdl, &status, "reference_names", 5, - pyctx, - pyrslt, - pyobjName, - pyresultClass, - pyrole); -#endif - - /* Query filtering is not supported for this class. */ - - /* Finished. */ -exit: - _SBLIM_TRACE(1,("referenceNames() %s", (status.rc == CMPI_RC_OK)? "succeeded":"failed")); - return status; -} - - -/***************************************************************************/ -CMPIStatus references( - CMPIAssociationMI* self, - const CMPIContext* ctx, - const CMPIResult* rslt, - const CMPIObjectPath* objName, - const char* resultClass, - const char* role, - const char** properties) -{ - CMPIStatus status = {CMPI_RC_ERR_NOT_SUPPORTED, NULL}; - -#ifdef SWIGPYTHON - _SBLIM_TRACE(1,("references(Python) called, ctx %p, rslt %p, objName %p, resultClass %s, role %s, properties %p", ctx, rslt, objName, resultClass, role, properties)); - - PY_CMPI_INIT - - PyObject *pyctx = SWIG_NewPointerObj((void*) ctx, SWIGTYPE_p__CMPIContext, 0); - PyObject *pyrslt = SWIG_NewPointerObj((void*) rslt, SWIGTYPE_p__CMPIResult, 0); - PyObject *pyobjName = SWIG_NewPointerObj((void*) objName, SWIGTYPE_p__CMPIObjectPath, 0); - PyObject* pyrole = NULL; - PyObject* pyresultClass = NULL; - if (role != NULL) - { - pyrole = PyString_FromString(role); - } - if (resultClass != NULL) - { - pyresultClass = PyString_FromString(resultClass); - } - PyObject *pyprops = proplist2py(properties); - - call_py_provider((PyObject*)self->hdl, &status, "references", 6, - pyctx, - pyrslt, - pyobjName, - pyresultClass, - pyrole, - pyprops); -#endif - - /* Finished. */ -exit: - _SBLIM_TRACE(1,("references() %s", (status.rc == CMPI_RC_OK)? "succeeded":"failed")); - return status; -} - -/***************************************************************************/ -CMPIStatus invokeMethod( - CMPIMethodMI* self, - const CMPIContext* ctx, - const CMPIResult* rslt, - const CMPIObjectPath* objName, - const char* method, - const CMPIArgs* in, - CMPIArgs* out) -{ - CMPIStatus status = {CMPI_RC_ERR_NOT_SUPPORTED, NULL}; - -#ifdef SWIGPYTHON - _SBLIM_TRACE(1,("invokeMethod(Python) called, ctx %p, rslt %p, objName %p, method %s, in %p, out %p", ctx, rslt, objName, method, in, out)); - - PY_CMPI_INIT - - PyObject *pyctx = SWIG_NewPointerObj((void*) ctx, SWIGTYPE_p__CMPIContext, 0); - PyObject *pyrslt = SWIG_NewPointerObj((void*) rslt, SWIGTYPE_p__CMPIResult, 0); - PyObject *pyobjName = SWIG_NewPointerObj((void*) objName, SWIGTYPE_p__CMPIObjectPath, 0); - PyObject *pymethod = PyString_FromString(method); - PyObject *pyin = SWIG_NewPointerObj((void*) in, SWIGTYPE_p__CMPIArgs, 0); - PyObject *pyout = SWIG_NewPointerObj((void*) out, SWIGTYPE_p__CMPIArgs, 0); - - call_py_provider((PyObject*)self->hdl, &status, "invoke_method", 6, - pyctx, - pyrslt, - pyobjName, - pymethod, - pyin, - pyout); -#endif - - /* Finished. */ -exit: - _SBLIM_TRACE(1,("invokeMethod() %s", (status.rc == CMPI_RC_OK)? "succeeded":"failed")); - return status; -} - -/***************************************************************************/ -CMPIStatus authorizeFilter( - CMPIIndicationMI* self, - const CMPIContext* ctx, - const CMPISelectExp* filter, - const char* className, - const CMPIObjectPath* classPath, - const char* owner) -{ - CMPIStatus status = {CMPI_RC_ERR_NOT_SUPPORTED, NULL}; - -#ifdef SWIGPYTHON - _SBLIM_TRACE(1,("authorizeFilter(Python) called, ctx %p, filter %p, className %s, classPath %p, owner %s", ctx, filter, className, classPath, owner)); - - PY_CMPI_INIT - - PyObject *pyctx = SWIG_NewPointerObj((void*) ctx, SWIGTYPE_p__CMPIContext, 0); - PyObject *pyfilter = SWIG_NewPointerObj((void*) filter, SWIGTYPE_p__CMPISelectExp, 0); - PyObject *pyclassPath = SWIG_NewPointerObj((void*) classPath, SWIGTYPE_p__CMPIObjectPath, 0); - PyObject *pyclassName = PyString_FromString(className); - PyObject *pyowner = PyString_FromString(owner); - - call_py_provider((PyObject*)self->hdl, &status, "authorize_filter", 5, - pyctx, - pyfilter, - pyclassName, - pyclassPath, - pyowner); -#endif - - /* Finished. */ -exit: - _SBLIM_TRACE(1,("authorizeFilter() %s", (status.rc == CMPI_RC_OK)? "succeeded":"failed")); - return status; -} - -/***************************************************************************/ -CMPIStatus activateFilter( - CMPIIndicationMI* self, - const CMPIContext* ctx, - const CMPISelectExp* filter, - const char* className, - const CMPIObjectPath* classPath, - CMPIBoolean firstActivation) -{ - CMPIStatus status = {CMPI_RC_ERR_NOT_SUPPORTED, NULL}; - -#ifdef SWIGPYTHON - _SBLIM_TRACE(1,("activateFilter(Python) called, ctx %p, filter %p, className %s, classPath %p, firstActivation %d", ctx, filter, className, classPath, firstActivation)); - - PY_CMPI_INIT - - PyObject *pyctx = SWIG_NewPointerObj((void*) ctx, SWIGTYPE_p__CMPIContext, 0); - PyObject *pyfilter = SWIG_NewPointerObj((void*) filter, SWIGTYPE_p__CMPISelectExp, 0); - PyObject *pyclassPath = SWIG_NewPointerObj((void*) classPath, SWIGTYPE_p__CMPIObjectPath, 0); - PyObject *pyclassName = PyString_FromString(className); - PyObject *pyfirstActivation = PyBool_FromLong(firstActivation); - - call_py_provider((PyObject*)self->hdl, &status, "activate_filter", 5, - pyctx, - pyfilter, - pyclassName, - pyclassPath, - pyfirstActivation); -#endif - - /* Finished. */ -exit: - _SBLIM_TRACE(1,("activateFilter() %s", (status.rc == CMPI_RC_OK)? "succeeded":"failed")); - return status; -} - -/***************************************************************************/ -CMPIStatus deActivateFilter( - CMPIIndicationMI* self, - const CMPIContext* ctx, - const CMPISelectExp* filter, - const char* className, - const CMPIObjectPath* classPath, - CMPIBoolean lastActivation) -{ - CMPIStatus status = {CMPI_RC_ERR_NOT_SUPPORTED, NULL}; - -#ifdef SWIGPYTHON - _SBLIM_TRACE(1,("deActivateFilter(Python) called, ctx %p, filter %p, className %s, classPath %p, lastActivation %d", ctx, filter, className, classPath, lastActivation)); - - PY_CMPI_INIT - - PyObject *pyctx = SWIG_NewPointerObj((void*) ctx, SWIGTYPE_p__CMPIContext, 0); - PyObject *pyfilter = SWIG_NewPointerObj((void*) filter, SWIGTYPE_p__CMPISelectExp, 0); - PyObject *pyclassPath = SWIG_NewPointerObj((void*) classPath, SWIGTYPE_p__CMPIObjectPath, 0); - PyObject *pyclassName = PyString_FromString(className); - PyObject *pylastActivation = PyBool_FromLong(lastActivation); - - call_py_provider((PyObject*)self->hdl, &status, "deactivate_filter", 5, - pyctx, - pyfilter, - pyclassName, - pyclassPath, - pylastActivation); -#endif - - /* Finished. */ -exit: - _SBLIM_TRACE(1,("deActivateFilter() %s", (status.rc == CMPI_RC_OK)? "succeeded":"failed")); - return status; -} - - -/***************************************************************************/ -// Note: sfcb doesn't support mustPoll. :( -// http://sourceforge.net/mailarchive/message.php?msg_id=OFF38FF3F9.39FD2E1F-ONC1257385.004A7122-C1257385.004BB0AF%40de.ibm.com -CMPIStatus mustPoll( - CMPIIndicationMI* self, - const CMPIContext* ctx, - //const CMPIResult* rslt, TODO: figure out who is right: spec. vs. sblim - const CMPISelectExp* filter, - const char* className, - const CMPIObjectPath* classPath) -{ - CMPIStatus status = {CMPI_RC_ERR_NOT_SUPPORTED, NULL}; - -#ifdef SWIGPYTHON - //_SBLIM_TRACE(1,("mustPoll(Python) called, ctx %p, rslt %p, filter %p, className %s, classPath %p", ctx, rslt, filter, className, classPath)); - _SBLIM_TRACE(1,("mustPoll(Python) called, ctx %p, filter %p, className %s, classPath %p", ctx, filter, className, classPath)); - - PY_CMPI_INIT - - PyObject *pyctx = SWIG_NewPointerObj((void*) ctx, SWIGTYPE_p__CMPIContext, 0); - //PyObject *pyrslt = SWIG_NewPointerObj((void*) rslt, SWIGTYPE_p__CMPIResult, 0); - PyObject *pyfilter = SWIG_NewPointerObj((void*) filter, SWIGTYPE_p__CMPISelectExp, 0); - PyObject *pyclassPath = SWIG_NewPointerObj((void*) classPath, SWIGTYPE_p__CMPIObjectPath, 0); - PyObject *pyclassName = PyString_FromString(className); - - call_py_provider((PyObject*)self->hdl, &status, "must_poll", 4, - pyctx, - //pyrslt, - pyfilter, - pyclassName, - pyclassPath); -#endif - - /* Finished. */ -exit: - _SBLIM_TRACE(1,("mustPoll() %s", (status.rc == CMPI_RC_OK)? "succeeded":"failed")); - return status; -} - - -/***************************************************************************/ -CMPIStatus enableIndications( - CMPIIndicationMI* self, - const CMPIContext* ctx) -{ - CMPIStatus status = {CMPI_RC_ERR_NOT_SUPPORTED, NULL}; - -#ifdef SWIGPYTHON - _SBLIM_TRACE(1,("enableIndications(Python) called, ctx %p", ctx)); - - PY_CMPI_INIT - - PyObject *pyctx = SWIG_NewPointerObj((void*) ctx, SWIGTYPE_p__CMPIContext, 0); - - call_py_provider((PyObject*)self->hdl, &status, "enable_indications", 1, pyctx); -#endif - - /* Finished. */ -exit: - _SBLIM_TRACE(1,("enableIndications() %s", (status.rc == CMPI_RC_OK)? "succeeded":"failed")); - return status; - -} - -/***************************************************************************/ -CMPIStatus disableIndications( - CMPIIndicationMI* self, - const CMPIContext* ctx) -{ - CMPIStatus status = {CMPI_RC_ERR_NOT_SUPPORTED, NULL}; - -#ifdef SWIGPYTHON - _SBLIM_TRACE(1,("disableIndications(Python) called, ctx %p", ctx)); - - PY_CMPI_INIT - - PyObject *pyctx = SWIG_NewPointerObj((void*) ctx, SWIGTYPE_p__CMPIContext, 0); - - call_py_provider((PyObject*)self->hdl, &status, "disable_indications", 1, pyctx); -#endif - - /* Finished. */ -exit: - _SBLIM_TRACE(1,("disableIndications() %s", (status.rc == CMPI_RC_OK)? "succeeded":"failed")); - return status; - -} - - -/***************************************************************************/ - - - - - - - - - -static CMPIMethodMIFT MethodMIFT__={ - CMPICurrentVersion, - CMPICurrentVersion, - "methodCmpi_Swig", // miName - MethodCleanup, - invokeMethod, -}; - - -static CMPIIndicationMIFT IndicationMIFT__={ - CMPICurrentVersion, - CMPICurrentVersion, - "indicationCmpi_Swig", // miName - IndicationCleanup, - authorizeFilter, - mustPoll, - activateFilter, - deActivateFilter, - enableIndications, - disableIndications, -}; - - -static CMPIAssociationMIFT AssociationMIFT__={ - CMPICurrentVersion, - CMPICurrentVersion, - "instanceCmpi_Swig", // miName - AssocCleanup, - associators, - associatorNames, - references, - referenceNames, -}; - - -static CMPIInstanceMIFT InstanceMIFT__={ - CMPICurrentVersion, - CMPICurrentVersion, - "associatorCmpi_Swig", // miName - InstCleanup, - EnumInstanceNames, - EnumInstances, - GetInstance, - CreateInstance, - SetInstance, - DeleteInstance, - ExecQuery, -}; - -static void createInit(const CMPIBroker* broker, - const CMPIContext* context, const char* miname, CMPIStatus* st) -{ - _BROKER = broker; - _MINAME = strdup(miname); - /* - * We can't initialize Python here and load Python modules, because - * SFCB passes a NULL CMPIStatus* st, which means we can't report - * back error strings. Instead, we'll check and initialize in each - * MIFT function - */ -} - -#define SWIG_CMPI_MI_FACTORY(ptype) \ -CMPI##ptype##MI* _Generic_Create_##ptype##MI(const CMPIBroker* broker, \ - const CMPIContext* context, const char* miname, CMPIStatus* st)\ -{ \ - static CMPI##ptype##MI mi={ \ - NULL, \ - &ptype##MIFT__, \ - }; \ - createInit(broker, context, miname, st); \ - return &mi; \ -} - -SWIG_CMPI_MI_FACTORY(Instance) -SWIG_CMPI_MI_FACTORY(Method) -SWIG_CMPI_MI_FACTORY(Association) -SWIG_CMPI_MI_FACTORY(Indication) - This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ba...@us...> - 2008-09-10 04:59:31
|
Revision: 928 http://omc.svn.sourceforge.net/omc/?rev=928&view=rev Author: bartw Date: 2008-09-10 04:59:41 +0000 (Wed, 10 Sep 2008) Log Message: ----------- some cleanup Modified Paths: -------------- cmpi-bindings/trunk/src/cmpi_provider_python.c cmpi-bindings/trunk/swig/cmpi_types.i cmpi-bindings/trunk/swig/python/cmpi_bindings.py cmpi-bindings/trunk/test/python/TestAssocProvider.py Modified: cmpi-bindings/trunk/src/cmpi_provider_python.c =================================================================== --- cmpi-bindings/trunk/src/cmpi_provider_python.c 2008-09-09 20:42:18 UTC (rev 927) +++ cmpi-bindings/trunk/src/cmpi_provider_python.c 2008-09-10 04:59:41 UTC (rev 928) @@ -29,9 +29,6 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *****************************************************************************/ -static char _CLASSNAME[] = "CmpiInstanceSwig"; - - #include <stdio.h> #include <stdarg.h> #include <pthread.h> @@ -68,8 +65,7 @@ static int _PY_INIT = 0; // acts as a boolean - is Python Initialized static int _MI_COUNT = 0; static PyThreadState* cmpiMainPyThreadState = NULL; -//static char* _MINAME = NULL; -PyObject* _PYPROVMOD = NULL; +static PyObject* _PYPROVMOD = NULL; typedef struct __PyProviderMIHandle @@ -101,30 +97,6 @@ } -static int PyInitialize(PyProviderMIHandle* hdl, CMPIStatus* st); -#define PY_CMPI_INIT { if (((PyProviderMIHandle*)(self->hdl))->pyMod == NULL) if (PyInitialize(((PyProviderMIHandle*)(self->hdl)), &status) != 0) return status; } - -static PyObject* -proplist2py(const char** cplist) -{ - if (cplist == NULL) - { - Py_RETURN_NONE; - } - PyObject* pl; - SWIG_PYTHON_THREAD_BEGIN_BLOCK; - - pl = PyList_New(0); - for (; *cplist != NULL; ++cplist) - { - PyList_Append(pl, PyString_FromString(*cplist)); - } - SWIG_PYTHON_THREAD_END_BLOCK; - - return pl; -} - - static PyObject * string2py(const char *s) { @@ -138,6 +110,7 @@ } + #define TB_ERROR(str) {tbstr = str; goto cleanup;} static CMPIString* get_exc_trace() @@ -234,7 +207,124 @@ } +SWIGEXPORT void SWIG_init(void); +#define PY_CMPI_SETFAIL(msgstr) {if (st != NULL) st->rc = CMPI_RC_ERR_FAILED; st->msg = msgstr; } +static int PyGlobalInitialize(CMPIStatus* st) +{ + int rc = 0; + _SBLIM_TRACE(1,("<%d/0x%x> PyGlobalInitialize() called", getpid(), pthread_self())); + + if (_PY_INIT) + { + _SBLIM_TRACE(1,("<%d/0x%x> PyGlobalInitialize() returning: already initialized", getpid(), pthread_self())); + return 0; + } + _PY_INIT=1;//true + + _SBLIM_TRACE(1,("<%d/0x%x> Python: Loading", getpid(), pthread_self())); + + Py_SetProgramName("cmpi_swig"); + Py_Initialize(); + SWIG_init(); + cmpiMainPyThreadState = PyGILState_GetThisThreadState(); + PyEval_ReleaseThread(cmpiMainPyThreadState); + + SWIG_PYTHON_THREAD_BEGIN_BLOCK; + _PYPROVMOD = PyImport_ImportModule("cmpi_bindings"); + if (_PYPROVMOD == NULL) + { + SWIG_PYTHON_THREAD_END_BLOCK; + _SBLIM_TRACE(1,("<%d/0x%x> Python: _PYPROVMOD at %p", getpid(), pthread_self(), _PYPROVMOD)); + PY_CMPI_SETFAIL(get_exc_trace()); + return -1; + } + _SBLIM_TRACE(1,("<%d/0x%x> Python: _PYPROVMOD at %p", getpid(), pthread_self(), _PYPROVMOD)); + + SWIG_PYTHON_THREAD_END_BLOCK; + _SBLIM_TRACE(1,("<%d/0x%x> PyGlobalInitialize() succeeded", getpid(), pthread_self())); + return 0; +} + + +static int PyInitialize(PyProviderMIHandle* hdl, CMPIStatus* st) +{ + int rc = 0; + /* Set _CMPI_INIT, protected by _CMPI_INIT_MUTEX + * so we call Py_Finalize() only once. + */ + if (pthread_mutex_lock(&_CMPI_INIT_MUTEX)) + { + perror("Can't lock _CMPI_INIT_MUTEX"); + abort(); + } + rc = PyGlobalInitialize(st); + pthread_mutex_unlock(&_CMPI_INIT_MUTEX); + if (rc != 0) + { + return rc; + } + + _SBLIM_TRACE(1,("<%d/0x%x> PyInitialize() called", getpid(), pthread_self())); + + SWIG_PYTHON_THREAD_BEGIN_BLOCK; + PyObject* provclass = PyObject_GetAttrString(_PYPROVMOD, + "CMPIProvider"); + if (provclass == NULL) + { + SWIG_PYTHON_THREAD_END_BLOCK; + PY_CMPI_SETFAIL(get_exc_trace()); + return -1; + } + PyObject* broker = SWIG_NewPointerObj((void*) _BROKER, SWIGTYPE_p__CMPIBroker, 0); + PyObject* args = PyTuple_New(2); + _SBLIM_TRACE(1,("\n<%d/0x%x> >>>>> PyInitialize(Python) called, MINAME=%s\n", + getpid(), pthread_self(), hdl->miName)); + PyTuple_SetItem(args, 0, string2py(hdl->miName)); + PyTuple_SetItem(args, 1, broker); + PyObject* provinst = PyObject_CallObject(provclass, args); + Py_DecRef(args); + Py_DecRef(provclass); + if (provinst == NULL) + { + SWIG_PYTHON_THREAD_END_BLOCK; + PY_CMPI_SETFAIL(get_exc_trace()); + return -1; + } + + hdl->pyMod = provinst; + + SWIG_PYTHON_THREAD_END_BLOCK; + _SBLIM_TRACE(1,("<%d/0x%x> PyInitialize() succeeded", getpid(), pthread_self())); + return 0; +} + + +#define PY_CMPI_INIT { if (((PyProviderMIHandle*)(self->hdl))->pyMod == NULL) if (PyInitialize(((PyProviderMIHandle*)(self->hdl)), &status) != 0) return status; } + +static PyObject* +proplist2py(const char** cplist) +{ + SWIG_PYTHON_THREAD_BEGIN_BLOCK; + if (cplist == NULL) + { + Py_INCREF(Py_None); + SWIG_PYTHON_THREAD_END_BLOCK; + return Py_None; + } + PyObject* pl; + + pl = PyList_New(0); + for (; *cplist != NULL; ++cplist) + { + PyList_Append(pl, PyString_FromString(*cplist)); + } + SWIG_PYTHON_THREAD_END_BLOCK; + + return pl; +} + + static int call_py_provider(PyProviderMIHandle* hdl, CMPIStatus* st, const char* opname, int nargs, ...) @@ -298,6 +388,7 @@ if (! PyTuple_Check(prv) || (PyTuple_Size(prv) != 2 && PyTuple_Size(prv) != 1)) { + SWIG_PYTHON_THREAD_BEGIN_ALLOW; char* str = fmtstr("Python function \"%s\" didn't return a two-tuple", opname); _SBLIM_TRACE(1,(str)); @@ -305,6 +396,7 @@ st->msg = _BROKER->eft->newString(_BROKER, str, NULL); free(str); rc = 1; + SWIG_PYTHON_THREAD_END_ALLOW; goto cleanup; } PyObject* prc = PyTuple_GetItem(prv, 0); @@ -316,19 +408,23 @@ if (! PyInt_Check(prc) || (! PyString_Check(prstr) && prstr != Py_None)) { + SWIG_PYTHON_THREAD_BEGIN_ALLOW; char* str = fmtstr("Python function \"%s\" didn't return a {<int>, <str>) two-tuple", opname); _SBLIM_TRACE(1,(str)); st->rc = CMPI_RC_ERR_FAILED; st->msg = _BROKER->eft->newString(_BROKER, str, NULL); free(str); rc = 1; + SWIG_PYTHON_THREAD_END_ALLOW; goto cleanup; } long pi = PyInt_AsLong(prc); st->rc = (CMPIrc)pi; if (prstr == Py_None) { + SWIG_PYTHON_THREAD_BEGIN_ALLOW; st->msg = _BROKER->eft->newString(_BROKER, "", NULL); + SWIG_PYTHON_THREAD_END_ALLOW; } else { @@ -345,9 +441,6 @@ } -// ---------------------------------------------------------------------------- -// CMPI INSTANCE PROVIDER FUNCTIONS -// ---------------------------------------------------------------------------- static CMPIStatus Cleanup( PyProviderMIHandle * miHdl, @@ -356,10 +449,6 @@ { CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */ - SWIG_PYTHON_THREAD_BEGIN_BLOCK; - Py_DecRef(_PYPROVMOD); - SWIG_PYTHON_THREAD_END_BLOCK; - if (miHdl != NULL) { free(miHdl->miName); @@ -384,22 +473,20 @@ pthread_mutex_unlock(&_CMPI_INIT_MUTEX); return status; } - pthread_mutex_unlock(&_CMPI_INIT_MUTEX); + SWIG_PYTHON_THREAD_BEGIN_BLOCK; + Py_DecRef(_PYPROVMOD); + SWIG_PYTHON_THREAD_END_BLOCK; + PyEval_AcquireLock(); PyThreadState_Swap(cmpiMainPyThreadState); if (_PY_INIT) // if PY is initialized and _MI_COUNT == 0, call Py_Finalize { _SBLIM_TRACE(1,("Calling Py_Finalize()")); Py_Finalize(); - if (pthread_mutex_lock(&_CMPI_INIT_MUTEX)) - { - perror("Can't lock _CMPI_INIT_MUTEX"); - abort(); - } _PY_INIT=0; // false - pthread_mutex_unlock(&_CMPI_INIT_MUTEX); } + pthread_mutex_unlock(&_CMPI_INIT_MUTEX); /* Finished. */ exit: @@ -448,12 +535,12 @@ /* EnumInstanceNames() - return a list of all the instances names (i.e. return their object paths only) */ static CMPIStatus EnumInstanceNames( - CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self') */ - const CMPIContext * context, /* [in] Additional context info, if any */ - const CMPIResult * result, /* [in] Contains the CIM namespace and classname */ - const CMPIObjectPath * reference) /* [in] Contains the CIM namespace and classname */ + CMPIInstanceMI * self, + const CMPIContext * context, + const CMPIResult * result, + const CMPIObjectPath * reference) { - CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations */ + CMPIStatus status = {CMPI_RC_OK, NULL}; _SBLIM_TRACE(1,("EnumInstanceNames() called")); @@ -461,9 +548,11 @@ PY_CMPI_INIT + SWIG_PYTHON_THREAD_BEGIN_BLOCK; PyObject *pycontext = SWIG_NewPointerObj((void*) context, SWIGTYPE_p__CMPIContext, 0); PyObject *pyresult = SWIG_NewPointerObj((void*) result, SWIGTYPE_p__CMPIResult, 0); PyObject *pyreference = SWIG_NewPointerObj((void*) reference, SWIGTYPE_p__CMPIObjectPath, 0); + SWIG_PYTHON_THREAD_END_BLOCK; call_py_provider((PyProviderMIHandle*)self->hdl, &status, "enum_instance_names", 3, pycontext, @@ -481,11 +570,11 @@ /* EnumInstances() - return a list of all the instances (i.e. return all the instance data) */ static CMPIStatus EnumInstances( - CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self') */ - const CMPIContext * context, /* [in] Additional context info, if any */ - const CMPIResult * result, /* [in] Contains the CIM namespace and classname */ - const CMPIObjectPath * reference, /* [in] Contains the CIM namespace and classname */ - const char ** properties) /* [in] List of desired properties (NULL=all) */ + CMPIInstanceMI * self, + const CMPIContext * context, + const CMPIResult * result, + const CMPIObjectPath * reference, + const char ** properties) { CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations */ /* char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); Our current CIM namespace */ @@ -494,9 +583,11 @@ PY_CMPI_INIT + SWIG_PYTHON_THREAD_BEGIN_BLOCK; PyObject *pycontext = SWIG_NewPointerObj((void*) context, SWIGTYPE_p__CMPIContext, 0); PyObject *pyresult = SWIG_NewPointerObj((void*) result, SWIGTYPE_p__CMPIResult, 0); PyObject *pyreference = SWIG_NewPointerObj((void*) reference, SWIGTYPE_p__CMPIObjectPath, 0); + SWIG_PYTHON_THREAD_END_BLOCK; PyObject *pyproperties = proplist2py(properties); call_py_provider((PyProviderMIHandle*)self->hdl, &status, "enum_instances", 4, @@ -516,11 +607,11 @@ /* GetInstance() - return the instance data for the specified instance only */ static CMPIStatus GetInstance( - CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self') */ - const CMPIContext * context, /* [in] Additional context info, if any */ - const CMPIResult * results, /* [out] Results of this operation */ - const CMPIObjectPath * reference, /* [in] Contains the CIM namespace, classname and desired object path */ - const char ** properties) /* [in] List of desired properties (NULL=all) */ + CMPIInstanceMI * self, + const CMPIContext * context, + const CMPIResult * results, + const CMPIObjectPath * reference, + const char ** properties) { CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations */ @@ -528,9 +619,15 @@ PY_CMPI_INIT + SWIG_PYTHON_THREAD_BEGIN_BLOCK; + { + SWIG_PYTHON_THREAD_BEGIN_BLOCK; + SWIG_PYTHON_THREAD_END_BLOCK; + } PyObject *pycontext = SWIG_NewPointerObj((void*) context, SWIGTYPE_p__CMPIContext, 0); PyObject *pyresult = SWIG_NewPointerObj((void*) results, SWIGTYPE_p__CMPIResult, 0); PyObject *pyreference = SWIG_NewPointerObj((void*) reference, SWIGTYPE_p__CMPIObjectPath, 0); + SWIG_PYTHON_THREAD_END_BLOCK; PyObject *pyproperties = proplist2py(properties); call_py_provider((PyProviderMIHandle*)self->hdl, &status, "get_instance", 4, @@ -550,11 +647,11 @@ /* CreateInstance() - create a new instance from the specified instance data. */ static CMPIStatus CreateInstance( - CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self') */ - const CMPIContext * context, /* [in] Additional context info, if any. */ - const CMPIResult * results, /* [out] Results of this operation */ - const CMPIObjectPath * reference, /* [in] Contains the target namespace, classname and objectpath. */ - const CMPIInstance * newinstance) /* [in] Contains all the new instance data. */ + CMPIInstanceMI * self, + const CMPIContext * context, + const CMPIResult * results, + const CMPIObjectPath * reference, + const CMPIInstance * newinstance) { CMPIStatus status = {CMPI_RC_ERR_NOT_SUPPORTED, NULL}; /* Return status of CIM operations. */ @@ -564,10 +661,12 @@ PY_CMPI_INIT + SWIG_PYTHON_THREAD_BEGIN_BLOCK; PyObject *pycontext = SWIG_NewPointerObj((void*) context, SWIGTYPE_p__CMPIContext, 0); PyObject *pyresult = SWIG_NewPointerObj((void*) results, SWIGTYPE_p__CMPIResult, 0); PyObject *pyreference = SWIG_NewPointerObj((void*) reference, SWIGTYPE_p__CMPIObjectPath, 0); PyObject *pynewinst = SWIG_NewPointerObj((void*) newinstance, SWIGTYPE_p__CMPIInstance, 0); + SWIG_PYTHON_THREAD_END_BLOCK; call_py_provider((PyProviderMIHandle*)self->hdl, &status, "create_instance", 4, pycontext, @@ -590,12 +689,12 @@ /* SetInstance() - save modified instance data for the specified instance. */ static CMPIStatus SetInstance( - CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */ - const CMPIContext * context, /* [in] Additional context info, if any. */ - const CMPIResult * results, /* [out] Results of this operation. */ - const CMPIObjectPath * reference, /* [in] Contains the target namespace, classname and objectpath. */ - const CMPIInstance * newinstance, /* [in] Contains all the new instance data. */ - const char ** properties) /* [in] List of desired properties (NULL=all) */ + CMPIInstanceMI * self, + const CMPIContext * context, + const CMPIResult * results, + const CMPIObjectPath * reference, + const CMPIInstance * newinstance, + const char ** properties) { CMPIStatus status = {CMPI_RC_ERR_NOT_SUPPORTED, NULL}; /* Return status of CIM operations. */ @@ -605,10 +704,12 @@ PY_CMPI_INIT + SWIG_PYTHON_THREAD_BEGIN_BLOCK; PyObject *pycontext = SWIG_NewPointerObj((void*) context, SWIGTYPE_p__CMPIContext, 0); PyObject *pyresult = SWIG_NewPointerObj((void*) results, SWIGTYPE_p__CMPIResult, 0); PyObject *pyreference = SWIG_NewPointerObj((void*) reference, SWIGTYPE_p__CMPIObjectPath, 0); PyObject *pynewinst = SWIG_NewPointerObj((void*) newinstance, SWIGTYPE_p__CMPIInstance, 0); + SWIG_PYTHON_THREAD_END_BLOCK; PyObject *plist = proplist2py(properties); call_py_provider((PyProviderMIHandle*)self->hdl, &status, "set_instance", 5, @@ -640,9 +741,11 @@ PY_CMPI_INIT + SWIG_PYTHON_THREAD_BEGIN_BLOCK; PyObject *pycontext = SWIG_NewPointerObj((void*) context, SWIGTYPE_p__CMPIContext, 0); PyObject *pyresult = SWIG_NewPointerObj((void*) results, SWIGTYPE_p__CMPIResult, 0); PyObject *pyreference = SWIG_NewPointerObj((void*) reference, SWIGTYPE_p__CMPIObjectPath, 0); + SWIG_PYTHON_THREAD_END_BLOCK; call_py_provider((PyProviderMIHandle*)self->hdl, &status, "delete_instance", 3, pycontext, @@ -660,12 +763,12 @@ /* ExecQuery() - return a list of all the instances that satisfy the desired query filter. */ static CMPIStatus ExecQuery( - CMPIInstanceMI * self, /* [in] Handle to this provider (i.e. 'self'). */ - const CMPIContext * context, /* [in] Additional context info, if any. */ - const CMPIResult * results, /* [out] Results of this operation. */ - const CMPIObjectPath * reference, /* [in] Contains the target namespace and classname. */ - const char * query, /* [in] Text of the query, written in the query language. */ - const char * language) /* [in] Name of the query language (e.g. "WQL"). */ + CMPIInstanceMI * self, + const CMPIContext * context, + const CMPIResult * results, + const CMPIObjectPath * reference, + const char * query, + const char * language) { CMPIStatus status = {CMPI_RC_ERR_NOT_SUPPORTED, NULL}; /* Return status of CIM operations. */ @@ -673,9 +776,11 @@ PY_CMPI_INIT + SWIG_PYTHON_THREAD_BEGIN_BLOCK; PyObject *pycontext = SWIG_NewPointerObj((void*) context, SWIGTYPE_p__CMPIContext, 0); PyObject *pyresult = SWIG_NewPointerObj((void*) results, SWIGTYPE_p__CMPIResult, 0); PyObject *pyreference = SWIG_NewPointerObj((void*) reference, SWIGTYPE_p__CMPIObjectPath, 0); + SWIG_PYTHON_THREAD_END_BLOCK; PyObject *pyquery = string2py(query); PyObject *pylang = string2py(language); @@ -697,102 +802,6 @@ // ---------------------------------------------------------------------------- - -#define PY_CMPI_SETFAIL(msgstr) {if (st != NULL) st->rc = CMPI_RC_ERR_FAILED; st->msg = msgstr; } -static int PyGlobalInitialize(CMPIStatus* st) -{ - int rc = 0; - - _SBLIM_TRACE(1,("<%d/0x%x> PyGlobalInitialize() called", getpid(), pthread_self())); - - /* Set _CMPI_INIT, protected by _CMPI_INIT_MUTEX - * so we call Py_Finalize() only once. - */ - if (pthread_mutex_lock(&_CMPI_INIT_MUTEX)) - { - perror("Can't lock _CMPI_INIT_MUTEX"); - abort(); - } - if (_PY_INIT) - { - pthread_mutex_unlock(&_CMPI_INIT_MUTEX); - _SBLIM_TRACE(1,("<%d/0x%x> PyGlobalInitialize() returning: already initialized", getpid(), pthread_self())); - return 0; - } - _PY_INIT=1;//true - pthread_mutex_unlock(&_CMPI_INIT_MUTEX); - - SWIGEXPORT void SWIG_init(void); - _SBLIM_TRACE(1,("<%d/0x%x> Python: Loading", getpid(), pthread_self())); - - Py_SetProgramName("cmpi_swig"); - Py_Initialize(); - PyEval_InitThreads(); - cmpiMainPyThreadState = PyGILState_GetThisThreadState(); - PyEval_ReleaseThread(cmpiMainPyThreadState); - - SWIG_PYTHON_THREAD_BEGIN_BLOCK; - SWIG_init(); - _PYPROVMOD = PyImport_ImportModule("cmpi_bindings"); - if (_PYPROVMOD == NULL) - { - SWIG_PYTHON_THREAD_END_BLOCK; - _SBLIM_TRACE(1,("<%d/0x%x> Python: _PYPROVMOD at %p", getpid(), pthread_self(), _PYPROVMOD)); - PY_CMPI_SETFAIL(get_exc_trace()); - return -1; - } - _SBLIM_TRACE(1,("<%d/0x%x> Python: _PYPROVMOD at %p", getpid(), pthread_self(), _PYPROVMOD)); - - SWIG_PYTHON_THREAD_END_BLOCK; - _SBLIM_TRACE(1,("<%d/0x%x> PyGlobalInitialize() succeeded", getpid(), pthread_self())); - return 0; -} - - -static int PyInitialize(PyProviderMIHandle* hdl, CMPIStatus* st) -{ - int rc = 0; - rc = PyGlobalInitialize(st); - if (rc != 0) - { - return rc; - } - - _SBLIM_TRACE(1,("<%d/0x%x> PyInitialize() called", getpid(), pthread_self())); - - SWIG_PYTHON_THREAD_BEGIN_BLOCK; - PyObject* provclass = PyObject_GetAttrString(_PYPROVMOD, - "CMPIProvider"); - if (provclass == NULL) - { - SWIG_PYTHON_THREAD_END_BLOCK; - PY_CMPI_SETFAIL(get_exc_trace()); - return -1; - } - PyObject* broker = SWIG_NewPointerObj((void*) _BROKER, SWIGTYPE_p__CMPIBroker, 0); - PyObject* args = PyTuple_New(2); - _SBLIM_TRACE(1,("\n<%d/0x%x> >>>>> PyInitialize(Python) called, MINAME=%s\n", getpid(), pthread_self(), hdl->miName)); - PyTuple_SetItem(args, 0, string2py(hdl->miName)); - PyTuple_SetItem(args, 1, broker); - PyObject* provinst = PyObject_CallObject(provclass, args); - Py_DecRef(args); - Py_DecRef(provclass); - if (provinst == NULL) - { - SWIG_PYTHON_THREAD_END_BLOCK; - PY_CMPI_SETFAIL(get_exc_trace()); - return -1; - } - - hdl->pyMod = provinst; - - SWIG_PYTHON_THREAD_END_BLOCK; - _SBLIM_TRACE(1,("<%d/0x%x> PyInitialize() succeeded", getpid(), pthread_self())); - return 0; -} - - - // associatorMIFT // @@ -812,9 +821,11 @@ PY_CMPI_INIT + SWIG_PYTHON_THREAD_BEGIN_BLOCK; PyObject *pyctx = SWIG_NewPointerObj((void*) ctx, SWIGTYPE_p__CMPIContext, 0); PyObject *pyrslt = SWIG_NewPointerObj((void*) rslt, SWIGTYPE_p__CMPIResult, 0); PyObject *pyobjName = SWIG_NewPointerObj((void*) objName, SWIGTYPE_p__CMPIObjectPath, 0); + SWIG_PYTHON_THREAD_END_BLOCK; PyObject *pyassocClass = NULL; PyObject *pyresultClass = NULL; PyObject* pyrole = NULL; @@ -871,9 +882,11 @@ PY_CMPI_INIT + SWIG_PYTHON_THREAD_BEGIN_BLOCK; PyObject *pyctx = SWIG_NewPointerObj((void*) ctx, SWIGTYPE_p__CMPIContext, 0); PyObject *pyrslt = SWIG_NewPointerObj((void*) rslt, SWIGTYPE_p__CMPIResult, 0); PyObject *pyobjName = SWIG_NewPointerObj((void*) objName, SWIGTYPE_p__CMPIObjectPath, 0); + SWIG_PYTHON_THREAD_END_BLOCK; PyObject *pyprops = proplist2py(properties); PyObject *pyassocClass = NULL; PyObject *pyresultClass = NULL; @@ -929,9 +942,11 @@ PY_CMPI_INIT + SWIG_PYTHON_THREAD_BEGIN_BLOCK; PyObject *pyctx = SWIG_NewPointerObj((void*) ctx, SWIGTYPE_p__CMPIContext, 0); PyObject *pyrslt = SWIG_NewPointerObj((void*) rslt, SWIGTYPE_p__CMPIResult, 0); PyObject *pyobjName = SWIG_NewPointerObj((void*) objName, SWIGTYPE_p__CMPIObjectPath, 0); + SWIG_PYTHON_THREAD_END_BLOCK; PyObject* pyresultClass = NULL; PyObject* pyrole = NULL; if (role != NULL) @@ -975,9 +990,11 @@ PY_CMPI_INIT + SWIG_PYTHON_THREAD_BEGIN_BLOCK; PyObject *pyctx = SWIG_NewPointerObj((void*) ctx, SWIGTYPE_p__CMPIContext, 0); PyObject *pyrslt = SWIG_NewPointerObj((void*) rslt, SWIGTYPE_p__CMPIResult, 0); PyObject *pyobjName = SWIG_NewPointerObj((void*) objName, SWIGTYPE_p__CMPIObjectPath, 0); + SWIG_PYTHON_THREAD_END_BLOCK; PyObject* pyrole = NULL; PyObject* pyresultClass = NULL; if (role != NULL) @@ -1020,12 +1037,14 @@ PY_CMPI_INIT + SWIG_PYTHON_THREAD_BEGIN_BLOCK; PyObject *pyctx = SWIG_NewPointerObj((void*) ctx, SWIGTYPE_p__CMPIContext, 0); PyObject *pyrslt = SWIG_NewPointerObj((void*) rslt, SWIGTYPE_p__CMPIResult, 0); PyObject *pyobjName = SWIG_NewPointerObj((void*) objName, SWIGTYPE_p__CMPIObjectPath, 0); - PyObject *pymethod = string2py(method); PyObject *pyin = SWIG_NewPointerObj((void*) in, SWIGTYPE_p__CMPIArgs, 0); PyObject *pyout = SWIG_NewPointerObj((void*) out, SWIGTYPE_p__CMPIArgs, 0); + SWIG_PYTHON_THREAD_END_BLOCK; + PyObject *pymethod = string2py(method); call_py_provider((PyProviderMIHandle*)self->hdl, &status, "invoke_method", 6, pyctx, @@ -1056,9 +1075,11 @@ PY_CMPI_INIT + SWIG_PYTHON_THREAD_BEGIN_BLOCK; PyObject *pyctx = SWIG_NewPointerObj((void*) ctx, SWIGTYPE_p__CMPIContext, 0); PyObject *pyfilter = SWIG_NewPointerObj((void*) filter, SWIGTYPE_p__CMPISelectExp, 0); PyObject *pyclassPath = SWIG_NewPointerObj((void*) classPath, SWIGTYPE_p__CMPIObjectPath, 0); + SWIG_PYTHON_THREAD_END_BLOCK; PyObject *pyclassName = string2py(className); PyObject *pyowner = string2py(owner); @@ -1090,11 +1111,13 @@ PY_CMPI_INIT + SWIG_PYTHON_THREAD_BEGIN_BLOCK; PyObject *pyctx = SWIG_NewPointerObj((void*) ctx, SWIGTYPE_p__CMPIContext, 0); PyObject *pyfilter = SWIG_NewPointerObj((void*) filter, SWIGTYPE_p__CMPISelectExp, 0); PyObject *pyclassPath = SWIG_NewPointerObj((void*) classPath, SWIGTYPE_p__CMPIObjectPath, 0); + PyObject *pyfirstActivation = PyBool_FromLong(firstActivation); + SWIG_PYTHON_THREAD_END_BLOCK; PyObject *pyclassName = string2py(className); - PyObject *pyfirstActivation = PyBool_FromLong(firstActivation); call_py_provider((PyProviderMIHandle*)self->hdl, &status, "activate_filter", 5, pyctx, @@ -1124,11 +1147,13 @@ PY_CMPI_INIT + SWIG_PYTHON_THREAD_BEGIN_BLOCK; PyObject *pyctx = SWIG_NewPointerObj((void*) ctx, SWIGTYPE_p__CMPIContext, 0); PyObject *pyfilter = SWIG_NewPointerObj((void*) filter, SWIGTYPE_p__CMPISelectExp, 0); PyObject *pyclassPath = SWIG_NewPointerObj((void*) classPath, SWIGTYPE_p__CMPIObjectPath, 0); + PyObject *pylastActivation = PyBool_FromLong(lastActivation); + SWIG_PYTHON_THREAD_END_BLOCK; PyObject *pyclassName = string2py(className); - PyObject *pylastActivation = PyBool_FromLong(lastActivation); call_py_provider((PyProviderMIHandle*)self->hdl, &status, "deactivate_filter", 5, pyctx, @@ -1162,10 +1187,12 @@ PY_CMPI_INIT + SWIG_PYTHON_THREAD_BEGIN_BLOCK; PyObject *pyctx = SWIG_NewPointerObj((void*) ctx, SWIGTYPE_p__CMPIContext, 0); //PyObject *pyrslt = SWIG_NewPointerObj((void*) rslt, SWIGTYPE_p__CMPIResult, 0); PyObject *pyfilter = SWIG_NewPointerObj((void*) filter, SWIGTYPE_p__CMPISelectExp, 0); PyObject *pyclassPath = SWIG_NewPointerObj((void*) classPath, SWIGTYPE_p__CMPIObjectPath, 0); + SWIG_PYTHON_THREAD_END_BLOCK; PyObject *pyclassName = string2py(className); call_py_provider((PyProviderMIHandle*)self->hdl, &status, "must_poll", 4, @@ -1193,7 +1220,9 @@ PY_CMPI_INIT + SWIG_PYTHON_THREAD_BEGIN_BLOCK; PyObject *pyctx = SWIG_NewPointerObj((void*) ctx, SWIGTYPE_p__CMPIContext, 0); + SWIG_PYTHON_THREAD_END_BLOCK; call_py_provider((PyProviderMIHandle*)self->hdl, &status, "enable_indications", 1, pyctx); @@ -1215,7 +1244,9 @@ PY_CMPI_INIT + SWIG_PYTHON_THREAD_BEGIN_BLOCK; PyObject *pyctx = SWIG_NewPointerObj((void*) ctx, SWIGTYPE_p__CMPIContext, 0); + SWIG_PYTHON_THREAD_END_BLOCK; call_py_provider((PyProviderMIHandle*)self->hdl, &status, "disable_indications", 1, pyctx); @@ -1288,7 +1319,11 @@ _BROKER = broker; } else if (_BROKER != broker) + { fprintf(stderr, "createInit broker %p, _BROKER %p\n", broker, _BROKER); + fprintf(stderr, "aborting\n"); + abort(); + } //_MINAME = strdup(miname); /* Modified: cmpi-bindings/trunk/swig/cmpi_types.i =================================================================== --- cmpi-bindings/trunk/swig/cmpi_types.i 2008-09-09 20:42:18 UTC (rev 927) +++ cmpi-bindings/trunk/swig/cmpi_types.i 2008-09-10 04:59:41 UTC (rev 928) @@ -300,8 +300,8 @@ %extend _CMPIObjectPath { /* nm: namespace */ - CMPIObjectPath( const char *nm ) { - CMPIObjectPath *path = CMNewObjectPath(_BROKER, nm, _CLASSNAME, NULL); + CMPIObjectPath( const char *nm, const char* classname ) { + CMPIObjectPath *path = CMNewObjectPath(_BROKER, nm, classname, NULL); /* fprintf( stderr, "CMNewObjectPath: %p\n", path ); */ return path; } Modified: cmpi-bindings/trunk/swig/python/cmpi_bindings.py =================================================================== --- cmpi-bindings/trunk/swig/python/cmpi_bindings.py 2008-09-09 20:42:18 UTC (rev 927) +++ cmpi-bindings/trunk/swig/python/cmpi_bindings.py 2008-09-10 04:59:41 UTC (rev 928) @@ -110,9 +110,9 @@ self.env = ProviderEnvironment(self.broker) self.proxy = ProviderProxy(self.env, '/usr/lib/pycim/'+miname+'.py') - print '*** broker.name()', broker.name() - print '*** broker.capabilities()', broker.capabilities() - print '*** broker.version()', broker.version() + #print '*** broker.name()', broker.name() + #print '*** broker.capabilities()', broker.capabilities() + #print '*** broker.version()', broker.version() broker.LogMessage(1, 'LogID', '** This should go through broker.LogMessage()') @@ -358,8 +358,7 @@ return rv def pywbem2cmpi_instname(iname): - cop = cmpi.CMPIObjectPath(iname.namespace) - cop.set_classname(str(iname.classname)) + cop = cmpi.CMPIObjectPath(iname.namespace, str(iname.classname)) for name, val in iname.keybindings.items(): data, _type = pywbem2cmpi_value(val) cop.add_key(str(name), data, _pywbem2cmpi_typemap[_type]) Modified: cmpi-bindings/trunk/test/python/TestAssocProvider.py =================================================================== --- cmpi-bindings/trunk/test/python/TestAssocProvider.py 2008-09-09 20:42:18 UTC (rev 927) +++ cmpi-bindings/trunk/test/python/TestAssocProvider.py 2008-09-10 04:59:41 UTC (rev 928) @@ -164,7 +164,6 @@ def references(self, env, object_name, model, assoc_class_name, result_class_name, role, result_role, keys_only): - print '!!!!!!! in TestAssoc_MemberOfGroup.references()' self._logger.log_debug("\n%s: References called for class %s" % (self.__class__.__name__.upper(), object_name)) model.path.keybindings['antecedent'] = None model.path.keybindings['dependent'] = None This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jc...@us...> - 2008-09-09 20:42:07
|
Revision: 927 http://omc.svn.sourceforge.net/omc/?rev=927&view=rev Author: jcarey Date: 2008-09-09 20:42:18 +0000 (Tue, 09 Sep 2008) Log Message: ----------- Corrected comments on ExtraInstallArgs property Modified Paths: -------------- contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderVirtualSystemCreationData.mof Modified: contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderVirtualSystemCreationData.mof =================================================================== --- contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderVirtualSystemCreationData.mof 2008-09-09 04:54:20 UTC (rev 926) +++ contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderVirtualSystemCreationData.mof 2008-09-09 20:42:18 UTC (rev 927) @@ -87,7 +87,9 @@ "key:value pairs within each element of the array, if the user so desires.")] String ExtraConfigInfo[]; - [Description("Extra arguments used for the VM Install. May not need.")] + [Description("Additional arguments to pass to the paravirtualized OS. " + "Note that the tool will automatically generate the necessary " + "OS-specific arguments to bootstrap the installation.")] string ExtraInstallArgs; [Description("A string containing the URL where the install source " This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ba...@us...> - 2008-09-09 04:54:09
|
Revision: 926 http://omc.svn.sourceforge.net/omc/?rev=926&view=rev Author: bartw Date: 2008-09-09 04:54:20 +0000 (Tue, 09 Sep 2008) Log Message: ----------- extrinsic method and association improvements Modified Paths: -------------- cmpi-bindings/trunk/swig/python/cim_provider.py Modified: cmpi-bindings/trunk/swig/python/cim_provider.py =================================================================== --- cmpi-bindings/trunk/swig/python/cim_provider.py 2008-09-09 04:53:12 UTC (rev 925) +++ cmpi-bindings/trunk/swig/python/cim_provider.py 2008-09-09 04:54:20 UTC (rev 926) @@ -199,6 +199,8 @@ 'is_subclass', 'codegen'] +class _NotImplemented(Exception): + pass def _path_equals_ignore_host(lhs, rhs): """If one object path doesn't inlcude a host, don't include the hosts @@ -433,7 +435,7 @@ CIM_ERR_FAILED (some other unspecified error occurred) """ - pass + raise _NotImplemented() def _set_filter_results(self, value): self._filter_results = value @@ -575,6 +577,7 @@ ''' model = pywbem.CIMInstance(classname=instanceName.classname, path=instanceName) + model.update(model.path.keybindings) ''' for k, v in instanceName.keybindings.items(): type = cimClass.properties[k].type @@ -925,9 +928,11 @@ new_inputs = dict([('param_%s' % k.lower(), v) \ for k, v in inputParams.items()]) (rval, outs) = method(env=env, object_name=objectName, - method=methodName, **new_inputs) + **new_inputs) def add_type(v): + if isinstance(v, pywbem.CIMParameter): + return (v.type, v.value) lv = v if type(v) == list and len(v) > 0: lv = v[0] @@ -938,17 +943,16 @@ elif isinstance(lv, pywbem.CIMInstanceName): tp = 'reference' elif v is None or (type(v) == list and len(v) == 0): - assert(None == 'TODO') + assert(None == 'This should not happen') else: tp = pywbem.cimtype(v) return (tp, v) - for k, v in outs.items(): - if hasattr(v, 'namespace') and v.namespace is None: - v.namespace = objectName.namespace - outs[k] = add_type(v) + louts = {} + for op in outs: + louts[op.name] = (op.type, op.value) rval = add_type(rval) - rval = (rval, outs) + rval = (rval, louts) else: raise pywbem.CIMError(pywbem.CIM_ERR_METHOD_NOT_FOUND, "%s:%s"%(objectName.classname, methodName)) @@ -1566,7 +1570,7 @@ if hasattr(self.provmod, 'get_providers'): self.provregs = pywbem.NocaseDict(self.provmod.get_providers(env)) - def _get_callable (self, classname, cname): + def _get_callable (self, classname, cname, is_assoc = False): """Return a function or method object appropriate to fulfill a request classname -- The CIM class name associated with the request. @@ -1579,9 +1583,9 @@ provClass = self.provregs[classname] if hasattr(provClass, cname): callable = getattr(provClass, cname) - elif hasattr(self.provmod, cname): + elif not is_assoc and hasattr(self.provmod, cname): callable = getattr(self.provmod, cname) - if callable is None: + if callable is None and not is_assoc: raise pywbem.CIMError(pywbem.CIM_ERR_FAILED, "No callable for %s:%s on provider %s"%(classname, cname, @@ -1688,11 +1692,41 @@ # and propertyList logger = env.get_logger() logger.log_debug('CIMProvider MI_associators called. assocClass: %s' % (assocClassName)) + cname = assocClassName - for i in self._get_callable(cname, 'MI_associators') \ - (env, objectName, assocClassName, resultClassName, - role, resultRole, propertyList): - yield i + if not cname and hasattr(self.provmod, 'MI_associators'): + for i in self.provmod.MI_associators( + env, + objectName, + assocClassName, + resultClassName, + role, + resultRole, + propertyList): + yield i + return + + lcnames = [] + is_assoc = not cname + if cname: + lcnames = [cname] + else: + lcnames = self.provregs.keys() + + for lcname in lcnames: + fn = self._get_callable(lcname, 'MI_associators', is_assoc) + if fn is not None: + try: + for i in fn(env, + objectName, + lcname, + resultClassName, + role, + resultRole, + propertyList): + yield i + except _NotImplemented: + continue logger.log_debug('CIMProvider MI_associators returning') ############################################################################## @@ -1708,10 +1742,38 @@ logger = env.get_logger() logger.log_debug('CIMProvider MI_associatorNames called. assocClass: %s' % (assocClassName)) cname = assocClassName - for i in self._get_callable(cname, 'MI_associatorNames') \ - (env, objectName, assocClassName, resultClassName, - role, resultRole): - yield i + if not cname and hasattr(self.provmod, 'MI_associatorNames'): + for i in self.provmod.MI_associatorNames( + env, + objectName, + assocClassName, + resultClassName, + role, + resultRole): + yield i + return + + lcnames = [] + is_assoc = not cname + if cname: + lcnames = [cname] + else: + lcnames = self.provregs.keys() + + for lcname in lcnames: + fn = self._get_callable(lcname, 'MI_associatorNames', is_assoc) + if fn is not None: + try: + for i in fn(env, + objectName, + lcname, + resultClassName, + role, + resultRole): + yield i + except _NotImplemented: + continue + logger.log_debug('CIMProvider MI_associatorNames returning') ############################################################################## @@ -1726,15 +1788,32 @@ logger = env.get_logger() logger.log_debug('CIMProvider MI_references called. resultClass: %s' % (resultClassName)) cname = resultClassName - if not cname: + if not cname and hasattr(self.provmod, 'MI_references'): + for i in self.provmod.MI_references(env, objectName, + resultClassName, role, propertyList): + yield i return - for i in self._get_callable(cname, 'MI_references') \ - (env, - objectName, - resultClassName, - role, - propertyList): - yield i + + lcnames = [] + is_assoc = not cname + if cname: + lcnames = [cname] + else: + lcnames = self.provregs.keys() + + for lcname in lcnames: + fn = self._get_callable(lcname, 'MI_references', is_assoc) + if fn is not None: + try: + for i in fn(env, + objectName, + lcname, + role, + propertyList): + yield i + except _NotImplemented: + continue + logger.log_debug('CIMProvider MI_references returning') ############################################################################## @@ -1747,15 +1826,33 @@ role): logger = env.get_logger() logger.log_debug('CIMProvider MI_referenceNames <1> called. resultClass: %s' % (resultClassName)) + cname = resultClassName - if not cname: + if not cname and hasattr(self.provmod, 'MI_referenceNames'): + for i in self.provmod.MI_referenceNames(env, objectName, + resultClassName, role): + yield i return - for i in self._get_callable(cname, 'MI_referenceNames') \ - (env, - objectName, - resultClassName, - role): - yield i + + lcnames = [] + is_assoc = not cname + if cname: + lcnames = [cname] + else: + lcnames = self.provregs.keys() + + for lcname in lcnames: + fn = self._get_callable(lcname, 'MI_referenceNames', is_assoc) + if fn is not None: + try: + for i in fn(env, + objectName, + lcname, + role): + yield i + except _NotImplemented: + continue + logger.log_debug('CIMProvider MI_referenceNames returning') ############################################################################## This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ba...@us...> - 2008-09-09 04:53:02
|
Revision: 925 http://omc.svn.sourceforge.net/omc/?rev=925&view=rev Author: bartw Date: 2008-09-09 04:53:12 +0000 (Tue, 09 Sep 2008) Log Message: ----------- removed a line that was causing a crash Modified Paths: -------------- cmpi-bindings/trunk/src/cmpi_provider_python.c Modified: cmpi-bindings/trunk/src/cmpi_provider_python.c =================================================================== --- cmpi-bindings/trunk/src/cmpi_provider_python.c 2008-09-09 04:52:30 UTC (rev 924) +++ cmpi-bindings/trunk/src/cmpi_provider_python.c 2008-09-09 04:53:12 UTC (rev 925) @@ -154,7 +154,6 @@ CMPIString* rv = NULL; PyObject *type, *value, *traceback; - _SBLIM_TRACE(1, ("PyErr_Occurred() %d", PyErr_Occurred())); SWIG_PYTHON_THREAD_BEGIN_BLOCK; PyErr_Fetch(&type, &value, &traceback); _SBLIM_TRACE(1,("** type %p, value %p, traceback %p", type, value, traceback)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ba...@us...> - 2008-09-09 04:52:19
|
Revision: 924 http://omc.svn.sourceforge.net/omc/?rev=924&view=rev Author: bartw Date: 2008-09-09 04:52:30 +0000 (Tue, 09 Sep 2008) Log Message: ----------- prime model with knowledge of keybindings Modified Paths: -------------- cmpi-bindings/trunk/test/python/TestAssocProvider.py Modified: cmpi-bindings/trunk/test/python/TestAssocProvider.py =================================================================== --- cmpi-bindings/trunk/test/python/TestAssocProvider.py 2008-09-09 04:52:03 UTC (rev 923) +++ cmpi-bindings/trunk/test/python/TestAssocProvider.py 2008-09-09 04:52:30 UTC (rev 924) @@ -166,6 +166,8 @@ result_class_name, role, result_role, keys_only): print '!!!!!!! in TestAssoc_MemberOfGroup.references()' self._logger.log_debug("\n%s: References called for class %s" % (self.__class__.__name__.upper(), object_name)) + model.path.keybindings['antecedent'] = None + model.path.keybindings['dependent'] = None if object_name.classname.lower() == 'testassoc_user': if role and role.lower() == 'antecedent': return This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ba...@us...> - 2008-09-09 04:51:53
|
Revision: 923 http://omc.svn.sourceforge.net/omc/?rev=923&view=rev Author: bartw Date: 2008-09-09 04:52:03 +0000 (Tue, 09 Sep 2008) Log Message: ----------- ported to new method provider interface Modified Paths: -------------- cmpi-bindings/trunk/test/python/TestMethod.py Modified: cmpi-bindings/trunk/test/python/TestMethod.py =================================================================== --- cmpi-bindings/trunk/test/python/TestMethod.py 2008-09-09 04:51:13 UTC (rev 922) +++ cmpi-bindings/trunk/test/python/TestMethod.py 2008-09-09 04:52:03 UTC (rev 923) @@ -33,9 +33,11 @@ try: inst = g_insts[model['id']] + #inst = g_insts[model.path['id']] except KeyError: raise pywbem.CIMError(pywbem.CIM_ERR_NOT_FOUND) + #model['id'] = model.path['id'] model['p_sint32']=inst[1] model['p_str']=inst[0] return model @@ -89,7 +91,7 @@ except KeyError: raise pywbem.CIMError(pywbem.CIM_ERR_NOT_FOUND) - def cim_method_mkunichar(self, env, object_name, method, + def cim_method_mkunichar(self, env, object_name, param_c): logger = env.get_logger() @@ -102,7 +104,7 @@ rval = None # TODO (type pywbem.Char16) return (rval, out_params) - def cim_method_mkunistr_char16(self, env, object_name, method, + def cim_method_mkunistr_char16(self, env, object_name, param_carr): logger = env.get_logger() logger.log_debug('Entering %s.cim_method_mkunistr_char16()' \ @@ -114,7 +116,7 @@ rval = None # TODO (type unicode) return (rval, out_params) - def cim_method_strsplit(self, env, object_name, method, + def cim_method_strsplit(self, env, object_name, param_str, param_sep): logger = env.get_logger() @@ -122,13 +124,14 @@ % self.__class__.__name__) elems = param_str.split(param_sep) - out_params = {} - out_params['nelems'] = pywbem.Sint32(len(elems)) - out_params['elems'] = elems + out_params = [ + pywbem.CIMParameter('nelems', 'sint32', + value=pywbem.Sint32(len(elems))), + pywbem.CIMParameter('elems', 'string', value=elems) ] rval = True return (rval, out_params) - def cim_method_strcat(self, env, object_name, method, + def cim_method_strcat(self, env, object_name, param_strs, param_sep): logger = env.get_logger() @@ -139,7 +142,7 @@ rval = param_sep.join(param_strs) return (rval, out_params) - def cim_method_mkunichararray(self, env, object_name, method, + def cim_method_mkunichararray(self, env, object_name, param_inarr): logger = env.get_logger() logger.log_debug('Entering %s.cim_method_mkunichararray()' \ @@ -152,7 +155,7 @@ rval = None # TODO (type bool) return (rval, out_params) - def cim_method_mkunistr_sint8(self, env, object_name, method, + def cim_method_mkunistr_sint8(self, env, object_name, param_carr): logger = env.get_logger() logger.log_debug('Entering %s.cim_method_mkunistr_sint8()' \ @@ -164,104 +167,111 @@ out_params = {} return (rval, out_params) - def minmedmax(self, dt, env, object_name, method, param_numlist): + def minmedmax(self, dt, env, object_name, param_numlist): l = param_numlist l.sort() - out_params = {} - out_params['max'] = l[-1] - out_params['min'] = l[0] + + lmin = l[0] + lmax = l[-1] ln = len(l) if ln % 2 == 0: - out_params['med'] = dt((l[(ln / 2) - 1] + l[(ln / 2)]) / 2) + lmed = dt((l[(ln / 2) - 1] + l[(ln / 2)]) / 2) else: - out_params['med'] = dt(l[ln / 2]) + lmed = dt(l[ln / 2]) + + out_params = [ + pywbem.CIMParameter('max', lmax.cimtype, value=lmax), + pywbem.CIMParameter('min', lmin.cimtype, value=lmin), + pywbem.CIMParameter('med', lmed.cimtype, value=lmed) + ] + rval = True return (rval, out_params) - def cim_method_minmedmax_real64(self, env, object_name, method, + def cim_method_minmedmax_real64(self, env, object_name, param_numlist): logger = env.get_logger() logger.log_debug('Entering %s.cim_method_minmedmax_real64()' \ % self.__class__.__name__) - return self.minmedmax(pywbem.Real64, env, object_name, method, param_numlist) + return self.minmedmax(pywbem.Real64, env, object_name, param_numlist) - def cim_method_minmedmax_real32(self, env, object_name, method, + def cim_method_minmedmax_real32(self, env, object_name, param_numlist): logger = env.get_logger() logger.log_debug('Entering %s.cim_method_minmedmax_real32()' \ % self.__class__.__name__) - return self.minmedmax(pywbem.Real32, env, object_name, method, param_numlist) + return self.minmedmax(pywbem.Real32, env, object_name, param_numlist) - def cim_method_minmedmax_uint8(self, env, object_name, method, + def cim_method_minmedmax_uint8(self, env, object_name, param_numlist): logger = env.get_logger() logger.log_debug('Entering %s.cim_method_minmedmax_uint8()' \ % self.__class__.__name__) - return self.minmedmax(pywbem.Uint8, env, object_name, method, param_numlist) + return self.minmedmax(pywbem.Uint8, env, object_name, param_numlist) - def cim_method_minmedmax_sint64(self, env, object_name, method, + def cim_method_minmedmax_sint64(self, env, object_name, param_numlist): logger = env.get_logger() logger.log_debug('Entering %s.cim_method_minmedmax_sint64()' \ % self.__class__.__name__) - return self.minmedmax(pywbem.Sint64, env, object_name, method, param_numlist) + return self.minmedmax(pywbem.Sint64, env, object_name, param_numlist) - def cim_method_minmedmax_sint16(self, env, object_name, method, + def cim_method_minmedmax_sint16(self, env, object_name, param_numlist): logger = env.get_logger() logger.log_debug('Entering %s.cim_method_minmedmax_sint16()' \ % self.__class__.__name__) - return self.minmedmax(pywbem.Sint16, env, object_name, method, param_numlist) + return self.minmedmax(pywbem.Sint16, env, object_name, param_numlist) - def cim_method_minmedmax_uint16(self, env, object_name, method, + def cim_method_minmedmax_uint16(self, env, object_name, param_numlist): logger = env.get_logger() logger.log_debug('Entering %s.cim_method_minmedmax_uint16()' \ % self.__class__.__name__) - return self.minmedmax(pywbem.Uint16, env, object_name, method, param_numlist) + return self.minmedmax(pywbem.Uint16, env, object_name, param_numlist) - def cim_method_minmedmax_uint64(self, env, object_name, method, + def cim_method_minmedmax_uint64(self, env, object_name, param_numlist): logger = env.get_logger() logger.log_debug('Entering %s.cim_method_minmedmax_uint64()' \ % self.__class__.__name__) - return self.minmedmax(pywbem.Uint64, env, object_name, method, param_numlist) + return self.minmedmax(pywbem.Uint64, env, object_name, param_numlist) - def cim_method_minmedmax_sint8(self, env, object_name, method, + def cim_method_minmedmax_sint8(self, env, object_name, param_numlist): logger = env.get_logger() logger.log_debug('Entering %s.cim_method_minmedmax_sint8()' \ % self.__class__.__name__) - return self.minmedmax(pywbem.Sint8, env, object_name, method, param_numlist) + return self.minmedmax(pywbem.Sint8, env, object_name, param_numlist) - def cim_method_minmedmax_sint32(self, env, object_name, method, + def cim_method_minmedmax_sint32(self, env, object_name, param_numlist): logger = env.get_logger() logger.log_debug('Entering %s.cim_method_minmedmax_sint32()' \ % self.__class__.__name__) - return self.minmedmax(pywbem.Sint32, env, object_name, method, param_numlist) + return self.minmedmax(pywbem.Sint32, env, object_name, param_numlist) - def cim_method_minmedmax_uint32(self, env, object_name, method, + def cim_method_minmedmax_uint32(self, env, object_name, param_numlist): logger = env.get_logger() logger.log_debug('Entering %s.cim_method_minmedmax_uint32()' \ % self.__class__.__name__) - return self.minmedmax(pywbem.Uint32, env, object_name, method, param_numlist) + return self.minmedmax(pywbem.Uint32, env, object_name, param_numlist) - def cim_method_getdate(self, env, object_name, method, + def cim_method_getdate(self, env, object_name, param_datestr): logger = env.get_logger() logger.log_debug('Entering %s.cim_method_getdate()' \ @@ -271,7 +281,7 @@ rval = pywbem.CIMDateTime(param_datestr) return (rval, out_params) - def cim_method_getdates(self, env, object_name, method, + def cim_method_getdates(self, env, object_name, param_datestrs): logger = env.get_logger() @@ -280,12 +290,15 @@ out_params = {} elems = [pywbem.CIMDateTime(s) for s in param_datestrs] - out_params['nelems'] = pywbem.Sint32(len(elems)) - out_params['elems'] = elems + out_params = [ + pywbem.CIMParameter('nelems', 'sint32', + value=pywbem.Sint32(len(elems))), + pywbem.CIMParameter('elems','datetime', value=elems) + ] rval = True return (rval, out_params) - def cim_method_getintprop(self, env, object_name, method): + def cim_method_getintprop(self, env, object_name): logger = env.get_logger() logger.log_debug('Entering %s.cim_method_getintprop()' \ % self.__class__.__name__) @@ -300,7 +313,7 @@ rval = inst[1] return (rval, out_params) - def cim_method_getstrprop(self, env, object_name, method): + def cim_method_getstrprop(self, env, object_name): logger = env.get_logger() logger.log_debug('Entering %s.cim_method_getstrprop()' \ @@ -316,7 +329,7 @@ rval = inst[0] return (rval, out_params) - def cim_method_setstrprop(self, env, object_name, method, + def cim_method_setstrprop(self, env, object_name, param_value): logger = env.get_logger() logger.log_debug('Entering %s.cim_method_setstrprop()' \ @@ -334,7 +347,7 @@ out_params = {} return (rval, out_params) - def cim_method_setintprop(self, env, object_name, method, + def cim_method_setintprop(self, env, object_name, param_value): logger = env.get_logger() @@ -353,7 +366,7 @@ out_params = {} return (rval, out_params) - def genrandlist_i(self, dt, env, object_name, method, param_nelems, + def genrandlist_i(self, dt, env, object_name, param_nelems, param_lo, param_hi): cnt = 0 l = [] @@ -364,96 +377,99 @@ except ValueError: # Range was probably zero l.append(dt(param_lo)) - out_params = {} - out_params['lo'] = param_lo - out_params['hi'] = param_hi - out_params['nlist'] = l + out_params = [] + out_params.append(pywbem.CIMParameter('lo', param_lo.cimtype, + value=param_lo)) + out_params.append(pywbem.CIMParameter('hi', param_hi.cimtype, + value=param_hi)) + tmpt = dt(0) + out_params.append(pywbem.CIMParameter('nlist', tmpt.cimtype, value=l)) rval = True return (rval, out_params) - def cim_method_genrandlist_sint64(self, env, object_name, method, + def cim_method_genrandlist_sint64(self, env, object_name, param_nelems, param_lo, param_hi): logger = env.get_logger() logger.log_debug('Entering %s.cim_method_genrandlist_sint64()' \ % self.__class__.__name__) - return self.genrandlist_i(pywbem.Sint64, env, object_name, method, + return self.genrandlist_i(pywbem.Sint64, env, object_name, param_nelems, param_lo, param_hi) - def cim_method_genrandlist_uint16(self, env, object_name, method, + def cim_method_genrandlist_uint16(self, env, object_name, param_nelems, param_lo, param_hi): logger = env.get_logger() logger.log_debug('Entering %s.cim_method_genrandlist_uint16()' \ % self.__class__.__name__) - return self.genrandlist_i(pywbem.Uint16, env, object_name, method, + return self.genrandlist_i(pywbem.Uint16, env, object_name, param_nelems, param_lo, param_hi) - def cim_method_genrandlist_uint32(self, env, object_name, method, + def cim_method_genrandlist_uint32(self, env, object_name, param_nelems, param_lo, param_hi): logger = env.get_logger() logger.log_debug('Entering %s.cim_method_genrandlist_uint32()' \ % self.__class__.__name__) - return self.genrandlist_i(pywbem.Uint32, env, object_name, method, + return self.genrandlist_i(pywbem.Uint32, env, object_name, param_nelems, param_lo, param_hi) - def cim_method_genrandlist_sint8(self, env, object_name, method, + def cim_method_genrandlist_sint8(self, env, object_name, param_nelems, param_lo, param_hi): logger = env.get_logger() logger.log_debug('Entering %s.cim_method_genrandlist_sint8()' \ % self.__class__.__name__) - return self.genrandlist_i(pywbem.Sint8, env, object_name, method, + return self.genrandlist_i(pywbem.Sint8, env, object_name, param_nelems, param_lo, param_hi) - def cim_method_genrandlist_uint8(self, env, object_name, method, + def cim_method_genrandlist_uint8(self, env, object_name, param_nelems, param_lo, param_hi): logger = env.get_logger() logger.log_debug('Entering %s.cim_method_genrandlist_uint8()' \ % self.__class__.__name__) - return self.genrandlist_i(pywbem.Uint8, env, object_name, method, + return self.genrandlist_i(pywbem.Uint8, env, object_name, param_nelems, param_lo, param_hi) - def cim_method_genrandlist_uint64(self, env, object_name, method, + def cim_method_genrandlist_uint64(self, env, object_name, param_nelems, param_lo, param_hi): logger = env.get_logger() logger.log_debug('Entering %s.cim_method_genrandlist_uint64()' \ % self.__class__.__name__) - return self.genrandlist_i(pywbem.Uint64, env, object_name, method, + return self.genrandlist_i(pywbem.Uint64, env, object_name, param_nelems, param_lo, param_hi) - def cim_method_genrandlist_sint32(self, env, object_name, method, + def cim_method_genrandlist_sint32(self, env, object_name, param_nelems, param_lo, param_hi): logger = env.get_logger() logger.log_debug('Entering %s.cim_method_genrandlist_sint32()' \ % self.__class__.__name__) - return self.genrandlist_i(pywbem.Sint32, env, object_name, method, + return self.genrandlist_i(pywbem.Sint32, env, object_name, param_nelems, param_lo, param_hi) - def cim_method_genrandlist_sint16(self, env, object_name, method, + def cim_method_genrandlist_sint16(self, env, object_name, param_nelems, param_lo, param_hi): logger = env.get_logger() logger.log_debug('Entering %s.cim_method_genrandlist_sint16()' \ % self.__class__.__name__) - return self.genrandlist_i(pywbem.Sint16, env, object_name, method, + return self.genrandlist_i(pywbem.Sint16, env, object_name, param_nelems, param_lo, param_hi) - def genrandlist_r(self, dt, env, object_name, method, param_nelems, + def genrandlist_r(self, dt, env, object_name, param_nelems, param_lo, param_hi): cnt = 0 l = [] @@ -461,14 +477,18 @@ while cnt < param_nelems: cnt+= 1 l.append(dt(random.random() * range + param_lo)) - out_params = {} - out_params['lo'] = param_lo - out_params['hi'] = param_hi - out_params['nlist'] = l + out_params = [] + out_params.append(pywbem.CIMParameter('lo', param_lo.cimtype, + value=param_lo)) + out_params.append(pywbem.CIMParameter('hi', param_hi.cimtype, + value=param_hi)) + tmpt = dt(0) + out_params.append(pywbem.CIMParameter('nlist', tmpt.cimtype, + value=l)) rval = True return (rval, out_params) - def cim_method_genrandlist_real64(self, env, object_name, method, + def cim_method_genrandlist_real64(self, env, object_name, param_nelems, param_lo, param_hi): @@ -476,31 +496,31 @@ logger = env.get_logger() logger.log_debug('Entering %s.cim_method_genrandlist_real64()' \ % self.__class__.__name__) - return self.genrandlist_r(pywbem.Real64, env, object_name, method, + return self.genrandlist_r(pywbem.Real64, env, object_name, param_nelems, param_lo, param_hi) - def cim_method_genrandlist_real32(self, env, object_name, method, + def cim_method_genrandlist_real32(self, env, object_name, param_nelems, param_lo, param_hi): logger = env.get_logger() logger.log_debug('Entering %s.cim_method_genrandlist_real32()' \ % self.__class__.__name__) - return self.genrandlist_r(pywbem.Real32, env, object_name, method, + return self.genrandlist_r(pywbem.Real32, env, object_name, param_nelems, param_lo, param_hi) - def genrand_i(self, dt, env, object_name, method, + def genrand_i(self, dt, env, object_name, param_max, param_min): out_params = {} - out_params['success'] = True - rval = param_min - if param_min < param_max: + out_params = [pywbem.CIMParameter('success', 'boolean', value=True)] + rval = param_min + if param_min < param_max: rval = dt(random.randint(param_min, param_max)) return (rval, out_params) - def cim_method_genrand_uint64(self, env, object_name, method, + def cim_method_genrand_uint64(self, env, object_name, param_max, param_min): @@ -508,100 +528,99 @@ logger.log_debug('Entering %s.cim_method_genrand_uint64()' \ % self.__class__.__name__) - return self.genrand_i(pywbem.Uint64, env, object_name, method, + return self.genrand_i(pywbem.Uint64, env, object_name, param_max, param_min) - def cim_method_genrand_sint8(self, env, object_name, method, + def cim_method_genrand_sint8(self, env, object_name, param_max, param_min): logger = env.get_logger() logger.log_debug('Entering %s.cim_method_genrand_sint8()' \ % self.__class__.__name__) - return self.genrand_i(pywbem.Sint8, env, object_name, method, + return self.genrand_i(pywbem.Sint8, env, object_name, param_max, param_min) - def cim_method_genrand_sint32(self, env, object_name, method, + def cim_method_genrand_sint32(self, env, object_name, param_max, param_min): logger = env.get_logger() logger.log_debug('Entering %s.cim_method_genrand_sint32()' \ % self.__class__.__name__) - return self.genrand_i(pywbem.Sint32, env, object_name, method, + return self.genrand_i(pywbem.Sint32, env, object_name, param_max, param_min) - def cim_method_genrand_uint32(self, env, object_name, method, + def cim_method_genrand_uint32(self, env, object_name, param_max, param_min): logger = env.get_logger() logger.log_debug('Entering %s.cim_method_genrand_uint32()' \ % self.__class__.__name__) - return self.genrand_i(pywbem.Uint32, env, object_name, method, + return self.genrand_i(pywbem.Uint32, env, object_name, param_max, param_min) - def cim_method_genrand_sint16(self, env, object_name, method, + def cim_method_genrand_sint16(self, env, object_name, param_max, param_min): logger = env.get_logger() logger.log_debug('Entering %s.cim_method_genrand_sint16()' \ % self.__class__.__name__) - return self.genrand_i(pywbem.Sint16, env, object_name, method, + return self.genrand_i(pywbem.Sint16, env, object_name, param_max, param_min) - def cim_method_genrand_uint16(self, env, object_name, method, + def cim_method_genrand_uint16(self, env, object_name, param_max, param_min): logger = env.get_logger() logger.log_debug('Entering %s.cim_method_genrand_uint16()' \ % self.__class__.__name__) - return self.genrand_i(pywbem.Uint16, env, object_name, method, + return self.genrand_i(pywbem.Uint16, env, object_name, param_max, param_min) - def cim_method_genrand_uint8(self, env, object_name, method, + def cim_method_genrand_uint8(self, env, object_name, param_max, param_min): logger = env.get_logger() logger.log_debug('Entering %s.cim_method_genrand_uint8()' \ % self.__class__.__name__) - return self.genrand_i(pywbem.Uint8, env, object_name, method, + return self.genrand_i(pywbem.Uint8, env, object_name, param_max, param_min) - def cim_method_genrand_sint64(self, env, object_name, method, + def cim_method_genrand_sint64(self, env, object_name, param_max, param_min): logger = env.get_logger() logger.log_debug('Entering %s.cim_method_genrand_sint64()' \ % self.__class__.__name__) - return self.genrand_i(pywbem.Sint64, env, object_name, method, + return self.genrand_i(pywbem.Sint64, env, object_name, param_max, param_min) - def genrand_r(self, dt, env, object_name, method, + def genrand_r(self, dt, env, object_name, param_max, param_min): - out_params = {} - out_params['success'] = True + out_params = [pywbem.CIMParameter('success', 'boolean', value=True)] range = param_max - param_min rval = dt(random.random() * range + param_min) return (rval, out_params) - def cim_method_genrand_real32(self, env, object_name, method, + def cim_method_genrand_real32(self, env, object_name, param_max, param_min): logger = env.get_logger() logger.log_debug('Entering %s.cim_method_genrand_real32()' \ % self.__class__.__name__) - return self.genrand_r(pywbem.Real32, env, object_name, method, + return self.genrand_r(pywbem.Real32, env, object_name, param_max, param_min) - def cim_method_genrand_real64(self, env, object_name, method, + def cim_method_genrand_real64(self, env, object_name, param_max, param_min): logger = env.get_logger() logger.log_debug('Entering %s.cim_method_genrand_real64()' \ % self.__class__.__name__) - return self.genrand_r(pywbem.Real64, env, object_name, method, + return self.genrand_r(pywbem.Real64, env, object_name, param_max, param_min) - def cim_method_delobject(self, env, object_name, method, + def cim_method_delobject(self, env, object_name, param_path): logger = env.get_logger() logger.log_debug('Entering %s.cim_method_delobject()' \ @@ -615,7 +634,7 @@ rval = pywbem.Sint32(0) return (rval, {}) - def cim_method_delobjects(self, env, object_name, method, + def cim_method_delobjects(self, env, object_name, param_paths): logger = env.get_logger() logger.log_debug('Entering %s.cim_method_delobjects()' \ @@ -629,7 +648,7 @@ del g_insts[id] return (rval, {}) - def cim_method_getobjectpath(self, env, object_name, method): + def cim_method_getobjectpath(self, env, object_name): logger = env.get_logger() logger.log_debug('Entering %s.cim_method_getobjectpath()' \ % self.__class__.__name__) @@ -642,11 +661,10 @@ namespace=object_name.namespace, keybindings={'id':g_insts.keys()[0]}) rval = pywbem.Sint32(0) - out_params = {} - out_params['path'] = path + out_params = [pywbem.CIMParameter('path', 'reference', value=path)] return (rval, out_params) - def cim_method_getobjectpaths(self, env, object_name, method): + def cim_method_getobjectpaths(self, env, object_name): logger = env.get_logger() logger.log_debug('Entering %s.cim_method_getobjectpaths()' \ % self.__class__.__name__) @@ -657,11 +675,11 @@ namespace=object_name.namespace, keybindings={'id':key})) out_params = {} - out_params['paths'] = paths + out_params = [pywbem.CIMParameter('paths', 'reference', value=paths)] rval = pywbem.Sint32(0) return (rval, out_params) - def cim_method_createobject(self, env, object_name, method, inst): + def cim_method_createobject(self, env, object_name,inst): logger = env.get_logger() logger.log_debug('Entering %s.cim_method_createobject()' \ % self.__class__.__name__) @@ -672,7 +690,7 @@ rval = pywbem.Sint32(0) return (rval, out_params) - def cim_method_createobjects(self, env, object_name, method, insts): + def cim_method_createobjects(self, env, object_name,insts): logger = env.get_logger() logger.log_debug('Entering %s.cim_method_createobject()' \ % self.__class__.__name__) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ba...@us...> - 2008-09-09 04:51:03
|
Revision: 922 http://omc.svn.sourceforge.net/omc/?rev=922&view=rev Author: bartw Date: 2008-09-09 04:51:13 +0000 (Tue, 09 Sep 2008) Log Message: ----------- find resource based on properties, not path keybindings. Modified Paths: -------------- cmpi-bindings/trunk/test/python/TestAtomProvider.py Modified: cmpi-bindings/trunk/test/python/TestAtomProvider.py =================================================================== --- cmpi-bindings/trunk/test/python/TestAtomProvider.py 2008-09-08 19:57:05 UTC (rev 921) +++ cmpi-bindings/trunk/test/python/TestAtomProvider.py 2008-09-09 04:51:13 UTC (rev 922) @@ -56,7 +56,7 @@ #logger.log_debug("**** GET_INSTANCE model[name]: %s ****" % model['Name']) #print "**** GET_INSTANCE model[name]: %s ****" % str(model['Name']) #if model['Name'] in self.storage.keys(): - inst = self.storage[model.path['Name']] + inst = self.storage[model['Name']] #else: #print "This is not working.... ******* FIX ME" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jc...@us...> - 2008-09-08 19:56:55
|
Revision: 921 http://omc.svn.sourceforge.net/omc/?rev=921&view=rev Author: jcarey Date: 2008-09-08 19:57:05 +0000 (Mon, 08 Sep 2008) Log Message: ----------- changed version to 1.0.2 Modified Paths: -------------- contrib/xen-vm-builder/trunk/configure.ac Modified: contrib/xen-vm-builder/trunk/configure.ac =================================================================== --- contrib/xen-vm-builder/trunk/configure.ac 2008-09-08 19:46:23 UTC (rev 920) +++ contrib/xen-vm-builder/trunk/configure.ac 2008-09-08 19:57:05 UTC (rev 921) @@ -2,7 +2,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ(2.57) -AC_INIT(sblim-cmpi-xenvm-builder, 1.0.1) +AC_INIT(sblim-cmpi-xenvm-builder, 1.0.2) AM_INIT_AUTOMAKE AC_CONFIG_SRCDIR([src]) AC_CONFIG_HEADER([config.h]) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jc...@us...> - 2008-09-08 19:46:13
|
Revision: 920 http://omc.svn.sourceforge.net/omc/?rev=920&view=rev Author: jcarey Date: 2008-09-08 19:46:23 +0000 (Mon, 08 Sep 2008) Log Message: ----------- Added processing for on_reboot, on_crash, on_poweroff Modified Paths: -------------- contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderVirtualSystemCreationData.mof contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-service.c contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-db.c contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmcreation-data.c Modified: contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderVirtualSystemCreationData.mof =================================================================== --- contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderVirtualSystemCreationData.mof 2008-09-05 22:54:02 UTC (rev 919) +++ contrib/xen-vm-builder/trunk/mof/XEN_VMBuilderVirtualSystemCreationData.mof 2008-09-08 19:46:23 UTC (rev 920) @@ -116,5 +116,44 @@ "windowsvistax64", "opensuse", "winserver2008", "winserver2008x64" }] uint32 OSType; + + [Description("Behaviour of a domain when it is powered off. " + "Possible values: " + "Destroy: Domain is cleaned up as normal" + "Restart: Domain is started in place of the old one" + "Preserve: No clean-up s done until the domain is manually destroyed" + "Rename-Restart: Old domain is not cleaned up, but is renamed and " + "a new domain started in its place. " + "Default is 'Destroy'."), + ValueMap{"0", "1", "2", "3"}, + Values{"Destroy", "Restart", "Preserve", "Rename-Restart"}] + uint16 OnPowerOff; + + [Description("Behaviour of a domain when it is rebooted. " + "Possible values: " + "Destroy: Domain is cleaned up as normal" + "Restart: Domain is started in place of the old one" + "Preserve: No clean-up s done until the domain is manually destroyed" + "Rename-Restart: Old domain is not cleaned up, but is renamed and " + "a new domain started in its place. " + "Default is 'Restart'."), + ValueMap{"0", "1", "2", "3"}, + Values{"Destroy", "Restart", "Preserve", "Rename-Restart"}] + uint16 OnReboot; + + [Description("Behaviour of a domain when it crashes. " + "Possible values: " + "Destroy: Domain is cleaned up as normal" + "Restart: Domain is started in place of the old one" + "Preserve: No clean-up s done until the domain is manually destroyed" + "Rename-Restart: Old domain is not cleaned up, but is renamed and " + "a new domain started in its place. " + "Coredump-Destroy: Dump the crashed domain's core and then destroy. " + "Coredump-Restart: Dump the crashed domain's core and the restart. " + "Default is 'Restart'."), + ValueMap{"0", "1", "2", "3", "4", "5"}, + Values{"Destroy", "Restart", "Preserve", "Rename-Restart", + "Coredump-Destroy", "Coredump-Restart"}] + uint16 OnCrash; }; Modified: contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-service.c =================================================================== --- contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-service.c 2008-09-05 22:54:02 UTC (rev 919) +++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/builder-service.c 2008-09-08 19:46:23 UTC (rev 920) @@ -593,12 +593,18 @@ CMPIStatus* pstatus) { FILE* fd = cmpiutilCreateTempFile(filename, filename_length); + if (!fd) { + CMPIUTIL_SETSTATUS(_broker, pstatus, CMPI_RC_ERROR_SYSTEM, + "Failed to create temp file for response file"); + return NULL; + } + size_t rflen = strlen(rf); if (fwrite(rf, sizeof(char), rflen, fd) != rflen) { fclose(fd); unlink(filename); CMPIUTIL_SETSTATUS(_broker, pstatus, CMPI_RC_ERROR_SYSTEM, - "Failed to create temp file for response file"); + "Failed writing contents of response file"); return NULL; } fclose(fd); @@ -606,6 +612,56 @@ } /*****************************************************************************/ +char* +create_settings_file(cmpiutilStrArray* lines, char *filename, + size_t filename_length, CMPIStatus* pstatus) +{ + int i, sz, len; + const char* iserr = NULL; + const char* line; + const char* hdr = "<domain type='xen'>"; + const char* trlr = "</domain>"; + FILE* fd = cmpiutilCreateTempFile(filename, filename_length); + if (!fd) { + CMPIUTIL_SETSTATUS(_broker, pstatus, CMPI_RC_ERROR_SYSTEM, + "Failed to create temp file for VM settings"); + return NULL; + } + + for(;;) { + len = strlen(hdr); + if (fwrite(hdr, sizeof(char), len, fd) != len) { + iserr = "Failed to write XML to vm-settings file"; + break; + } + sz = cmpiutilStrArray_size(lines); + for(i = 0; i < sz; i++) { + line = cmpiutilStrArray_get_element(lines, i); + len = strlen(line); + if (fwrite(line, sizeof(char), len, fd) != len) { + iserr = "Failed to write XML to vm-settings file"; + break; + } + } + if (!iserr) { + len = strlen(trlr); + if (fwrite(trlr, sizeof(char), len, fd) != len) + iserr = "Failed to write XML to vm-settings file"; + } + break; + } + + fclose(fd); + if (iserr) { + unlink(filename); + CMPIUTIL_SETSTATUS(_broker, pstatus, CMPI_RC_ERROR_SYSTEM, iserr); + return NULL; + } + + return filename; +} + +/*****************************************************************************/ static CMPIObjectPath* start_create_vm( const CMPIContext* context, @@ -617,16 +673,22 @@ CMPIStatus *pstatus) { CMPIData data; - cmpiutilStrArray *pstra; + cmpiutilStrArray *pstra, *vm_settings = NULL; const char *iid = NULL; const char *os_type; char wkbfr[256]; char rspbfr[PATH_MAX]; + char settingsbfr[PATH_MAX]; char *response_file = NULL; + char *settings_file = NULL; int cc, i; size_t output_size; char* output; CMPIObjectPath *jobref = NULL; + static const char* on_actions[] = { + "destroy", "restart", "preserve", "rename-restart", + "coredump-destroy", "coredump-restart" + }; DEBUGOUT("start_create_vm() called...\n"); data = CMGetProperty(cdci, "InstanceID", NULL); @@ -819,6 +881,56 @@ } } + vm_settings = cmpiutilStrArray_create(); + if (!vm_settings) { + if (response_file) { + unlink(response_file); + } + cmpiutilStrArray_destroy(pstra); + CMPIUTIL_SETSTATUS(_broker, pstatus, CMPI_RC_ERROR_SYSTEM, + "Failed to create string array for vm settings"); + return NULL; + } + + /**** OnPowerOff ****/ + data = CMGetProperty(cdci, "OnPowerOff", NULL); + if (!CMIsNullValue(data)) { + snprintf(wkbfr, sizeof(wkbfr), "<on_poweroff>%s</on_poweroff>", on_actions[data.value.uint16]); + cmpiutilStrArray_append(vm_settings, wkbfr); + } + + /**** OnReboot ****/ + data = CMGetProperty(cdci, "OnReboot", NULL); + if (!CMIsNullValue(data)) { + snprintf(wkbfr, sizeof(wkbfr), "<on_reboot>%s</on_reboot>", on_actions[data.value.uint16]); + cmpiutilStrArray_append(vm_settings, wkbfr); + } + + /**** OnCrash ****/ + data = CMGetProperty(cdci, "OnCrash", NULL); + if (!CMIsNullValue(data)) { + snprintf(wkbfr, sizeof(wkbfr), "<on_crash>%s</on_crash>", on_actions[data.value.uint16]); + cmpiutilStrArray_append(vm_settings, wkbfr); + } + + /* If OnPowerOff/OnReboot/OnCrash specified then create a vm-settings file */ + if (cmpiutilStrArray_size(vm_settings) > 0) + { + settings_file = create_settings_file(vm_settings, settingsbfr, + sizeof(settingsbfr), pstatus); + if (!settings_file) { + if (response_file) { + unlink(response_file); + } + cmpiutilStrArray_destroy(vm_settings); + cmpiutilStrArray_destroy(pstra); + return NULL; + } + cmpiutilStrArray_append(pstra, "--vm-settings"); + cmpiutilStrArray_append(pstra, settings_file); + } + cmpiutilStrArray_destroy(vm_settings); + /* Execute vm-install with the constructed command line */ #ifdef XEN_VMBUILDER_DEBUG printf("Executing:\n"); @@ -864,49 +976,60 @@ free(output); } cmpiutilStrArray_destroy(pstra); - DEBUGOUT("checking for existence response file\n"); - if (response_file) { - DEBUGOUT("Should have response file %s\n", response_file); - if (jobref) { - DEBUGOUT("There is a job reference, so waiting for right state\n"); - /* - * Wait until Job state reaches the 'INSTALL' and then delete - * the response file. - */ - CMPIInstance *jobci; - CMPIStatus lstatus; - int fail_count = 0; - DEBUGOUT("Entering GetInstance loop for Job instance...\n"); - while(fail_count < 10) { - cmpiutilMilliSleep(1000); - jobci = CBGetInstance(_broker, context, jobref, NULL, - &lstatus); - if (jobci == NULL) { - DEBUGOUT("GetInstance for Job returned NULL. " - "Inc fail count\n"); - fail_count++; + + /* If a jobref was returned, wait for it to get beyond + * the 'SETTINGS' state before any clean up. + */ + if (jobref) { + DEBUGOUT("There is a job reference, so waiting for right state\n"); + /* + * Wait until Job state goes beyond the 'SETTINGS' state. + */ + CMPIInstance *jobci; + CMPIStatus lstatus; + int fail_count = 0; + DEBUGOUT("Entering GetInstance loop for Job instance...\n"); + while(fail_count < 10) { + cmpiutilMilliSleep(1000); + jobci = CBGetInstance(_broker, context, jobref, NULL, + &lstatus); + if (jobci == NULL) { + DEBUGOUT("GetInstance for Job returned NULL. " + "Inc fail count\n"); + fail_count++; + continue; + } + data = CMGetProperty(jobci, "JobStatus", NULL); + if (!CMIsNullValue(data)) { + const char *p = CMGetCharPtr(data.value.string); + if (strcasecmp(p, "SETTINGS") == 0) { + DEBUGOUT("Still to soon to delete Response file\n"); continue; } - data = CMGetProperty(jobci, "JobStatus", NULL); - if (!CMIsNullValue(data)) { - const char *p = CMGetCharPtr(data.value.string); - if (strcasecmp(p, "SETTINGS") == 0) { - DEBUGOUT("Still to soon to delete Response file\n"); - continue; - } - DEBUGOUT("Install state allows for response file " - "delete\n"); - break; - } else { - DEBUGOUT("Job instance has NULL JobStatus property. " - "Inc Fail count\n"); - fail_count++; - } + DEBUGOUT("Install state allows for response file " + "delete\n"); + break; + } else { + DEBUGOUT("Job instance has NULL JobStatus property. " + "Inc Fail count\n"); + fail_count++; } } + } + + DEBUGOUT("checking for existence response file\n"); + if (response_file) { + DEBUGOUT("Should have response file %s\n", response_file); DEBUGOUT("Deleting response file: %s\n", response_file); unlink(response_file); } + + DEBUGOUT("checking for existence of settings file\n"); + if (settings_file) { + DEBUGOUT("Should have settings file %s\n", settings_file); + DEBUGOUT("Deleting settings file: %s\n", settings_file); + unlink(settings_file); + } DEBUGOUT("start_create_vm() returning\n"); return jobref; } Modified: contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-db.c =================================================================== --- contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-db.c 2008-09-05 22:54:02 UTC (rev 919) +++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmbuilder-db.c 2008-09-08 19:46:23 UTC (rev 920) @@ -86,6 +86,23 @@ "VirtType INTEGER," "VirtualSystemIdentifier TEXT," "VirtualSystemType TEXT," + //-- 0: Destroy + //-- 1: Restart + //-- 2: Preserve + //-- 3: Rename-Restart + "OnPowerOff INTEGER," + //-- 0: Destroy + //-- 1: Restart + //-- 2: Preserve + //-- 3: Rename-Restart + "OnReboot INTEGER," + //-- 0: Destroy + //-- 1: Restart + //-- 2: Preserve + //-- 3: Rename-Restart + //-- 4: Coredump-Destroy + //-- 5: Coredump-Restart + "OnCrash INTEGER," "PRIMARY KEY(InstanceID COLLATE NOCASE));" "CREATE TABLE Job(" "JobName TEXT NOT NULL," Modified: contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmcreation-data.c =================================================================== --- contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmcreation-data.c 2008-09-05 22:54:02 UTC (rev 919) +++ contrib/xen-vm-builder/trunk/src/providers/vm-builder/vmcreation-data.c 2008-09-08 19:46:23 UTC (rev 920) @@ -99,7 +99,10 @@ "VNCPassword," \ "VirtType," \ "VirtualSystemIdentifier," \ - "VirtualSystemType" + "VirtualSystemType," \ + "OnPowerOff," \ + "OnReboot," \ + "OnCrash" const char* all_cd_fields_query_with_where = "SELECT "CSV_FIELDS" FROM CreationData " "WHERE InstanceID=%Q;"; @@ -145,7 +148,10 @@ CDF_VNCPassword, CDF_VirtType, CDF_VirtualSystemIdentifier, - CDF_VirtualSystemType + CDF_VirtualSystemType, + CDF_OnPowerOff, + CDF_OnReboot, + CDF_OnCrash }; /* @@ -231,6 +237,51 @@ /*****************************************************************************/ static CMPIrc +valid_on_power_off(const CMPIData *pdata, CMPIStatus* pstatus) +{ + CMSetStatus(pstatus, CMPI_RC_OK); + if (!CMIsNullValue((*pdata))) { + if (pdata->value.uint16 > 3) { + CMSetStatusWithChars(_broker, pstatus, + CMPI_RC_ERR_INVALID_PARAMETER, + "Invalid 'OnPowerOff' property"); + } + } + return pstatus->rc; +} + +/*****************************************************************************/ +static CMPIrc +valid_on_reboot(const CMPIData *pdata, CMPIStatus* pstatus) +{ + CMSetStatus(pstatus, CMPI_RC_OK); + if (!CMIsNullValue((*pdata))) { + if (pdata->value.uint16 > 3) { + CMSetStatusWithChars(_broker, pstatus, + CMPI_RC_ERR_INVALID_PARAMETER, + "Invalid 'OnReboot' property"); + } + } + return pstatus->rc; +} + +/*****************************************************************************/ +static CMPIrc +valid_on_crash(const CMPIData *pdata, CMPIStatus* pstatus) +{ + CMSetStatus(pstatus, CMPI_RC_OK); + if (!CMIsNullValue((*pdata))) { + if (pdata->value.uint16 > 5) { + CMSetStatusWithChars(_broker, pstatus, + CMPI_RC_ERR_INVALID_PARAMETER, + "Invalid 'OnCrash' property"); + } + } + return pstatus->rc; +} + +/*****************************************************************************/ +static CMPIrc valid_automatic_recovery_action(const CMPIData *pdata, CMPIStatus* pstatus) { CMSetStatus(pstatus, CMPI_RC_OK); @@ -292,19 +343,29 @@ /*****************************************************************************/ static void add_u16_prop_to_query(cmpiutilStrBuf* pstrbuf, const CMPIInstance* instance, - const char* prop_name, CMPIData *pdata) + const char* prop_name, CMPIData *pdata, int endstmt) { CMPIData data; + const char* pnnfmt; + const char* pnullfmt; if (!pdata) { pdata = &data; } + + if (endstmt) { + pnnfmt = "%d"; + pnullfmt = "NULL"; + } else { + pnnfmt = "%d,"; + pnullfmt = "NULL,"; + } *pdata = CMGetProperty(instance, prop_name, NULL); if (!CMIsNullValue((*pdata))) { char wkbfr[32]; - snprintf(wkbfr, sizeof(wkbfr), "%u,", pdata->value.uint16); + snprintf(wkbfr, sizeof(wkbfr), pnnfmt, pdata->value.uint16); cmpiutilStrBuf_cat(pstrbuf, wkbfr, 0); } else { - cmpiutilStrBuf_cat(pstrbuf, "NULL,", 0); + cmpiutilStrBuf_cat(pstrbuf, pnullfmt, 0); } } @@ -444,6 +505,9 @@ set_u32_prop(dbctx, CDF_VirtType, instance, "VirtType"); set_str_prop(dbctx, CDF_VirtualSystemIdentifier, instance, "VirtualSystemIdentifier"); set_str_prop(dbctx, CDF_VirtualSystemType, instance, "VirtualSystemType"); + set_u16_prop(dbctx, CDF_OnPowerOff, instance, "OnPowerOff"); + set_u16_prop(dbctx, CDF_OnReboot, instance, "OnReboot"); + set_u16_prop(dbctx, CDF_OnCrash, instance, "OnCrash"); } /****************************************************************************** @@ -935,6 +999,24 @@ mod_add_str_prop(pstra, modified_instance, "VirtualSystemIdentifier", properties); mod_add_str_prop(pstra, modified_instance, "VirtualSystemType", properties); + mod_add_u16_prop(pstra, modified_instance, "OnPowerOff", properties, &data); + if (valid_on_power_off(&data, &status) != CMPI_RC_OK) { + cmpiutilStrArray_destroy(pstra); + return status; + } + + mod_add_u16_prop(pstra, modified_instance, "OnReboot", properties, &data); + if (valid_on_reboot(&data, &status) != CMPI_RC_OK) { + cmpiutilStrArray_destroy(pstra); + return status; + } + + mod_add_u16_prop(pstra, modified_instance, "OnCrash", properties, &data); + if (valid_on_crash(&data, &status) != CMPI_RC_OK) { + cmpiutilStrArray_destroy(pstra); + return status; + } + pstrbuf = cmpiutilStrBuf_create(); if (!pstrbuf) { CMSetStatusWithChars(_broker, &status, CMPI_RC_ERROR_SYSTEM, @@ -1024,17 +1106,17 @@ cmpiutilStrBuf_cat(pstrbuf, ") VALUES (", 0); db_sql_insert(pstrbuf, "%Q,", iid); - add_u16_prop_to_query(pstrbuf, newinstance, "AutoMaticRecoveryAction", &data); + add_u16_prop_to_query(pstrbuf, newinstance, "AutoMaticRecoveryAction", &data, 0); if (valid_automatic_recovery_action(&data, &status) != CMPI_RC_OK) { cmpiutilStrBuf_destroy(pstrbuf); return status; } - add_u16_prop_to_query(pstrbuf, newinstance, "AutoMaticShutdownAction", &data); + add_u16_prop_to_query(pstrbuf, newinstance, "AutoMaticShutdownAction", &data, 0); if (valid_automatic_shutdown_action(&data, &status) != CMPI_RC_OK) { cmpiutilStrBuf_destroy(pstrbuf); return status; } - add_u16_prop_to_query(pstrbuf, newinstance, "AutoMaticStartupAction", &data); + add_u16_prop_to_query(pstrbuf, newinstance, "AutoMaticStartupAction", &data, 0); if (valid_automatic_startup_action(&data, &status) != CMPI_RC_OK) { cmpiutilStrBuf_destroy(pstrbuf); return status; @@ -1056,10 +1138,10 @@ cmpiutilStrBuf_cat(pstrbuf, "NULL,", 0); } - add_u16_prop_to_query(pstrbuf, newinstance, "AutoMaticStartupActionSequenceNumber", NULL); + add_u16_prop_to_query(pstrbuf, newinstance, "AutoMaticStartupActionSequenceNumber", NULL, 0); add_str_prop_to_query(pstrbuf, newinstance, "CPUArchitecture", 0); add_str_prop_to_query(pstrbuf, newinstance, "Caption", 0); - add_u16_prop_to_query(pstrbuf, newinstance, "ChangeableType", &data); + add_u16_prop_to_query(pstrbuf, newinstance, "ChangeableType", &data, 0); if (valid_changeable_type(&data, &status) != CMPI_RC_OK) { cmpiutilStrBuf_destroy(pstrbuf); return status; @@ -1126,9 +1208,26 @@ return status; } add_str_prop_to_query(pstrbuf, newinstance, "VirtualSystemIdentifier", 0); - add_str_prop_to_query(pstrbuf, newinstance, "VirtualSystemType", 1); + add_str_prop_to_query(pstrbuf, newinstance, "VirtualSystemType", 0); + add_u16_prop_to_query(pstrbuf, newinstance, "OnPowerOff", &data, 0); + if (valid_on_power_off(&data, &status) != CMPI_RC_OK) { + cmpiutilStrBuf_destroy(pstrbuf); + return status; + } + add_u16_prop_to_query(pstrbuf, newinstance, "OnReboot", &data, 0); + if (valid_on_reboot(&data, &status) != CMPI_RC_OK) { + cmpiutilStrBuf_destroy(pstrbuf); + return status; + } + add_u16_prop_to_query(pstrbuf, newinstance, "OnCrash", &data, 1); + if (valid_on_crash(&data, &status) != CMPI_RC_OK) { + cmpiutilStrBuf_destroy(pstrbuf); + return status; + } cmpiutilStrBuf_cat(pstrbuf, ");", 0); + printf("SQL: %s\n", pstrbuf->bfr); + if (db_exec(pstrbuf->bfr, wkbfr, sizeof(wkbfr)) < 0LL) { DEBUGOUT("CreateInstance(): failed inserting record into " "database: %s", wkbfr); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ba...@us...> - 2008-09-05 22:53:52
|
Revision: 919 http://omc.svn.sourceforge.net/omc/?rev=919&view=rev Author: bartw Date: 2008-09-05 22:54:02 +0000 (Fri, 05 Sep 2008) Log Message: ----------- fixed makefile for file rename and new file addition Modified Paths: -------------- cmpi-bindings/trunk/swig/python/CMakeLists.txt Modified: cmpi-bindings/trunk/swig/python/CMakeLists.txt =================================================================== --- cmpi-bindings/trunk/swig/python/CMakeLists.txt 2008-09-05 22:47:51 UTC (rev 918) +++ cmpi-bindings/trunk/swig/python/CMakeLists.txt 2008-09-05 22:54:02 UTC (rev 919) @@ -55,7 +55,8 @@ INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/cmpi.py DESTINATION ${PYTHON_LIB_DIR}/site-packages ) # -# pycmpi_provider.py: provider implementation +# cmpi_bindings.py: provider implementation # -INSTALL(FILES pycmpi_provider.py DESTINATION ${PYTHON_LIB_DIR}/site-packages ) +INSTALL(FILES cmpi_bindings.py DESTINATION ${PYTHON_LIB_DIR}/site-packages ) +INSTALL(FILES cim_provider.py DESTINATION ${PYTHON_LIB_DIR}/site-packages ) #INSTALL(FILES Py_UnixProcessProvider.py DESTINATION /usr/lib/pycim ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ba...@us...> - 2008-09-05 22:47:41
|
Revision: 918 http://omc.svn.sourceforge.net/omc/?rev=918&view=rev Author: bartw Date: 2008-09-05 22:47:51 +0000 (Fri, 05 Sep 2008) Log Message: ----------- altered the interface to no longer require a CIMClass, and thus no longer require a client GetClass call Modified Paths: -------------- cmpi-bindings/trunk/TODO cmpi-bindings/trunk/src/cmpi_provider_python.c cmpi-bindings/trunk/swig/python/Py_UnixProcessProvider.py cmpi-bindings/trunk/test/python/TestAssoc.mof cmpi-bindings/trunk/test/python/TestAssocProvider.py cmpi-bindings/trunk/test/python/TestAtomProvider.py cmpi-bindings/trunk/test/python/TestAtomProvider_Test.py cmpi-bindings/trunk/test/python/TestMethod.py Added Paths: ----------- cmpi-bindings/trunk/swig/python/cim_provider.py cmpi-bindings/trunk/swig/python/cmpi_bindings.py Removed Paths: ------------- cmpi-bindings/trunk/swig/python/pycmpi_provider.py Modified: cmpi-bindings/trunk/TODO =================================================================== --- cmpi-bindings/trunk/TODO 2008-09-05 22:21:27 UTC (rev 917) +++ cmpi-bindings/trunk/TODO 2008-09-05 22:47:51 UTC (rev 918) @@ -19,3 +19,4 @@ Wrap CMPIEnumeration and CMPIArray in typemaps. +Check timestamp on provider modules and reload if modified. Modified: cmpi-bindings/trunk/src/cmpi_provider_python.c =================================================================== --- cmpi-bindings/trunk/src/cmpi_provider_python.c 2008-09-05 22:21:27 UTC (rev 917) +++ cmpi-bindings/trunk/src/cmpi_provider_python.c 2008-09-05 22:47:51 UTC (rev 918) @@ -734,7 +734,7 @@ SWIG_PYTHON_THREAD_BEGIN_BLOCK; SWIG_init(); - _PYPROVMOD = PyImport_ImportModule("pycmpi_provider"); + _PYPROVMOD = PyImport_ImportModule("cmpi_bindings"); if (_PYPROVMOD == NULL) { SWIG_PYTHON_THREAD_END_BLOCK; Modified: cmpi-bindings/trunk/swig/python/Py_UnixProcessProvider.py =================================================================== --- cmpi-bindings/trunk/swig/python/Py_UnixProcessProvider.py 2008-09-05 22:21:27 UTC (rev 917) +++ cmpi-bindings/trunk/swig/python/Py_UnixProcessProvider.py 2008-09-05 22:47:51 UTC (rev 918) @@ -7,8 +7,10 @@ import pywbem import os from socket import getfqdn +from cim_provider import CIMProvider -class Py_UnixProcessProvider(pywbem.CIMProvider): + +class Py_UnixProcessProvider(CIMProvider): """Instrument the CIM class Py_UnixProcess Model a Linux Process, For use with PyWBEM Provider QuickStart Guide @@ -24,7 +26,7 @@ # parameters, set self.filter_results to False # self.filter_results = False - def get_instance(self, env, model, cim_class): + def get_instance(self, env, model, property_list): """Return an instance. Keyword arguments: @@ -59,6 +61,13 @@ # model['OSName'] # model['CSCreationClassName'] # model['CSName'] + + model['CreationClassName'] = model.path['CreationClassName'] + model['OSCreationClassName'] = model.path['OSCreationClassName'] + model['Handle'] = model.path['Handle'] + model['OSName'] = model.path['OSName'] + model['CSCreationClassName'] = model.path['CSCreationClassName'] + model['CSName'] = model.path['CSName'] #model.update_existing(Caption=<value>) # TODO (type = unicode) #model.update_existing(CreationDate=<value>) # TODO (type = pywbem.CIMDateTime) @@ -93,7 +102,7 @@ #model.update_existing(WorkingSetSize=<value>) # TODO (type = pywbem.Uint64) return model - def enum_instances(self, env, model, cim_class, keys_only): + def enum_instances(self, env, model, property_list, keys_only): """Enumerate instances. The WBEM operations EnumerateInstances and EnumerateInstanceNames @@ -122,19 +131,25 @@ % self.__class__.__name__) model['CreationClassName'] = 'Py_UnixProcess' + model.path['CreationClassName'] = 'Py_UnixProcess' model['OSCreationClassName'] = 'CIM_UnitaryComputerSystem' + model.path['OSCreationClassName'] = 'CIM_UnitaryComputerSystem' model['OSName'] = 'Linux' + model.path['OSName'] = 'Linux' model['CSCreationClassName'] = 'CIM_ComputerSystem' + model.path['CSCreationClassName'] = 'CIM_ComputerSystem' model['CSName'] = getfqdn() + model.path['CSName'] = getfqdn() for file in os.listdir('/proc'): if not file.isdigit(): continue model['Handle'] = file + model.path['Handle'] = file if keys_only: yield model else: try: - yield self.get_instance(env, model, cim_class) + yield self.get_instance(env, model, property_list) except pywbem.CIMError, (num, msg): if num not in (pywbem.CIM_ERR_NOT_FOUND, pywbem.CIM_ERR_ACCESS_DENIED): Added: cmpi-bindings/trunk/swig/python/cim_provider.py =================================================================== --- cmpi-bindings/trunk/swig/python/cim_provider.py (rev 0) +++ cmpi-bindings/trunk/swig/python/cim_provider.py 2008-09-05 22:47:51 UTC (rev 918) @@ -0,0 +1,1909 @@ +# +# (C) Copyright 2003-2007 Hewlett-Packard Development Company, L.P. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as +# published by the Free Software Foundation; either version 2 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# + +# Author: Bart Whiteley +# Jon Carey +#### + + +r"""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. + +""" + +import sys +from os.path import dirname +import pywbem +from imp import load_source +import types + +__all__ = ['CIMProvider', + 'is_subclass', + 'codegen'] + + +def _path_equals_ignore_host(lhs, rhs): + """If one object path doesn't inlcude a host, don't include the hosts + in the comparison + + """ + + if lhs is rhs: + return True + if lhs.host is not None and rhs.host is not None and lhs.host != rhs.host: + return False + # need to make sure this stays in sync with CIMInstanceName.__cmp__() + return not (pywbem.cmpname(rhs.classname, lhs.classname) or + cmp(rhs.keybindings, lhs.keybindings) or + pywbem.cmpname(rhs.namespace, lhs.namespace)) + + +class CIMProvider(object): + """Base class for CIM Providers. + + A derived class might normally override the following: + - enum_instances + - get_instance + - set_instance + - delete_instance + - references + + If the provider is a "read-only" instance provider, set_instance and + delete_instance need not be overridden. + + Only association providers need to override references. + + A method provider should implement a method of the form: + def cim_method_<method_name>(self, env, object_name, method, + param_<input_param_1>, + param_<input_param_2>, + ...): + Where <method_name> is the name of the method from the CIM schema. + <method_name> needs to be all lowercase, regardless of the case of + the method name in the CIM schema (CIM method names are case + insensitive). + + Keyword arguments: + env -- Provider Environment (pycimmb.ProviderEnvironment) + object_name -- A pywbem.CIMInstanceName or pywbem.CIMClassname + specifying the object on which the method is to be invoked. + method -- A pywbem.CIMMethod, representing the method to execute. + param_<param_name> -- Corresponds to the input parameter <param_name> + from the CIM schema. <param_name> needs to be all lowercase, + regardless of the case of the parameter name in the CIM schema + (CIM parameter names are case insensitive). + + The method returns a two-tuple containing the return value of the + method, and a dictionary containing the output parameters. + + Example: + def cim_method_requeststatechange(self, env, object_name, method, + param_requestedstate, + param_timeoutperiod): + # do stuff. + out_params = {'job': pywbem.CIMInstanceName(...)} + rval = pywbem.Uint32(0) + return (rval, out_params) + + The methods prefixed with "MI_" correspond to the WBEM operations + from http://www.dmtf.org/standards/published_documents/DSP200.html + The default implementations of these methods call the methods + described above. These will not normally be overridden or extended + by a subclass. + + """ + + def get_instance (self, env, model, property_list): + """Return an instance. + + Keyword arguments: + env -- Provider Environment (pycimmb.ProviderEnvironment) + model -- A template of the pywbem.CIMInstance to be returned. The + key properties are set on this instance to correspond to the + instanceName that was requested. The properties of the model + are already filtered according to the PropertyList from the + request. Only properties present in the model need to be + given values. If you prefer, you can set all of the + values, and the instance will be filtered for you. + cim_class -- The pywbem.CIMClass + + Possible Errors: + CIM_ERR_ACCESS_DENIED + CIM_ERR_INVALID_PARAMETER (including missing, duplicate, unrecognized + or otherwise incorrect parameters) + CIM_ERR_NOT_FOUND (the CIM Class does exist, but the requested CIM + Instance does not exist in the specified namespace) + CIM_ERR_FAILED (some other unspecified error occurred) + + """ + return None + + def enum_instances(self, env, model, property_list, keys_only): + """Enumerate instances. + + The WBEM operations EnumerateInstances and EnumerateInstanceNames + are both mapped to this method. + This method is a python generator + + Keyword arguments: + env -- Provider Environment (pycimmb.ProviderEnvironment) + model -- A template of the pywbem.CIMInstances to be generated. + The properties of the model are already filtered according to + the PropertyList from the request. Only properties present in + the model need to be given values. If you prefer, you can + always set all of the values, and the instance will be filtered + for you. + cim_class -- The pywbem.CIMClass + keys_only -- A boolean. True if only the key properties should be + set on the generated instances. + + Possible Errors: + CIM_ERR_FAILED (some other unspecified error occurred) + + """ + pass + + def set_instance(self, env, instance, previous_instance, property_list): + """Return a newly created or modified instance. + + Keyword arguments: + env -- Provider Environment (pycimmb.ProviderEnvironment) + instance -- The new pywbem.CIMInstance. If modifying an existing + instance, the properties on this instance have been filtered by + the PropertyList from the request. + previous_instance -- The previous pywbem.CIMInstance if modifying + an existing instance. None if creating a new instance. + cim_class -- The pywbem.CIMClass + + Return the new instance. The keys must be set on the new instance. + + Possible Errors: + CIM_ERR_ACCESS_DENIED + CIM_ERR_NOT_SUPPORTED + CIM_ERR_INVALID_PARAMETER (including missing, duplicate, unrecognized + or otherwise incorrect parameters) + CIM_ERR_ALREADY_EXISTS (the CIM Instance already exists -- only + valid if previous_instance is None, indicating that the operation + was CreateInstance) + CIM_ERR_NOT_FOUND (the CIM Instance does not exist -- only valid + if previous_instance is not None, indicating that the operation + was ModifyInstance) + CIM_ERR_FAILED (some other unspecified error occurred) + + """ + raise pywbem.CIMError(pywbem.CIM_ERR_NOT_SUPPORTED, "") + + def delete_instance(self, env, instance_name): + """Delete an instance. + + Keyword arguments: + env -- Provider Environment (pycimmb.ProviderEnvironment) + instance_name -- A pywbem.CIMInstanceName specifying the instance + to delete. + + Possible Errors: + CIM_ERR_ACCESS_DENIED + CIM_ERR_NOT_SUPPORTED + CIM_ERR_INVALID_NAMESPACE + CIM_ERR_INVALID_PARAMETER (including missing, duplicate, unrecognized + or otherwise incorrect parameters) + CIM_ERR_INVALID_CLASS (the CIM Class does not exist in the specified + namespace) + CIM_ERR_NOT_FOUND (the CIM Class does exist, but the requested CIM + Instance does not exist in the specified namespace) + CIM_ERR_FAILED (some other unspecified error occurred) + + """ + raise pywbem.CIMError(pywbem.CIM_ERR_NOT_SUPPORTED, "") + + def references(self, env, object_name, model, assoc_class_name, + result_class_name, role, result_role, keys_only): + """Instrument Associations. + + All four association-related operations (Associators, AssociatorNames, + References, ReferenceNames) are mapped to this method. + This method is a python generator + + Keyword arguments: + env -- Provider Environment (pycimmb.ProviderEnvironment) + object_name -- A pywbem.CIMInstanceName that defines the source + CIM Object whose associated Objects are to be returned. + model -- A template pywbem.CIMInstance to serve as a model + of the objects to be returned. Only properties present on this + model need to be set. + assoc_class_name -- The name of the association class. + result_class_name -- If not empty, this string acts as a filter on + the returned set of Instances by mandating that each returned + Instances MUST represent an association between object_name + and an Instance of a Class whose name matches this parameter + or a subclass. + role -- If not empty, MUST be a valid Property name. It acts as a + filter on the returned set of Instances by mandating that each + returned Instance MUST refer to object_name via a Property + whose name matches the value of this parameter. + result_role -- If not empty, MUST be a valid Property name. It acts + as a filter on the returned set of Instances by mandating that + each returned Instance MUST represent associations of + object_name to other Instances, where the other Instances play + the specified result_role in the association (i.e. the + name of the Property in the Association Class that refers to + the Object related to object_name MUST match the value of this + parameter). + keys_only -- A boolean. True if only the key properties should be + set on the generated instances. + + The following diagram may be helpful in understanding the role, + result_role, and result_class_name parameters. + +------------------------+ +-------------------+ + | object_name.classname | | result_class_name | + | ~~~~~~~~~~~~~~~~~~~~~ | | ~~~~~~~~~~~~~~~~~ | + +------------------------+ +-------------------+ + | +-----------------------------------+ | + | | [Association] assoc_class | | + | object_name | ~~~~~~~~~~~~~~~~~~~~~~~~~ | | + +--------------+ object_name.classname REF role | | + (CIMInstanceName) | result_class_name REF result_role +------+ + | |(CIMInstanceName) + +-----------------------------------+ + + Possible Errors: + CIM_ERR_ACCESS_DENIED + CIM_ERR_NOT_SUPPORTED + CIM_ERR_INVALID_NAMESPACE + CIM_ERR_INVALID_PARAMETER (including missing, duplicate, unrecognized + or otherwise incorrect parameters) + CIM_ERR_FAILED (some other unspecified error occurred) + + """ + pass + + def _set_filter_results(self, value): + self._filter_results = value + def _get_filter_results(self): + if hasattr(self, '_filter_results'): + return self._filter_results + return True + filter_results = property(_get_filter_results, + _set_filter_results, + None, + """Determines if the CIMProvider base class should filter results + + If True, the subclass of CIMProvider in the provider module + does not need to filter returned results based on property_list, + and in the case of association providers, role, result_role, and + result_class_name. The results will be filtered by the + CIMProvider base class. + + If False, the CIMProvider base class will do no filtering. + Therefore the subclass of CIMProvider in the provider module will + have to filter based on property_list, and in the case of + association providers, role, result_role, and result_class_name.""") + + def MI_enumInstanceNames(self, + env, + objPath): + """Return instance names of a given CIM class + + Implements the WBEM operation EnumerateInstanceNames in terms + of the enum_instances method. A derived class will not normally + override this method. + + """ + + logger = env.get_logger() + logger.log_debug('CIMProvider MI_enumInstanceNames called...') + ''' + keys = pywbem.NocaseDict() + [keys.__setitem__(p.name, p) for p in cimClass.properties.values()\ + if 'key' in p.qualifiers] + + _strip_quals(keys) + path = pywbem.CIMInstanceName(classname=cimClass.classname, + namespace=ns) + ''' + model = pywbem.CIMInstance(classname=objPath.classname, + path=objPath) + gen = self.enum_instances(env=env, + model=model, + property_list = None, + keys_only=True) + try: + iter(gen) + except TypeError: + logger.log_debug('CIMProvider MI_enumInstanceNames returning') + return + + for inst in gen: + # TODO rval = build_instance_name(inst) + yield inst.path + logger.log_debug('CIMProvider MI_enumInstanceNames returning') + + def MI_enumInstances(self, + env, + objPath, + propertyList): + """Return instances of a given CIM class + + Implements the WBEM operation EnumerateInstances in terms + of the enum_instances method. A derived class will not normally + override this method. + + """ + logger = env.get_logger() + logger.log_debug('CIMProvider MI_enumInstances called...') + ''' + keyNames = get_keys_from_class(cimClass) + plist = None + if propertyList is not None: + lkns = [kn.lower() for kn in keyNames] + props = pywbem.NocaseDict() + plist = [s.lower() for s in propertyList] + pklist = plist + lkns + [props.__setitem__(p.name, p) for p in cimClass.properties.values() + if p.name.lower() in pklist] + else: + props = cimClass.properties + _strip_quals(props) + ''' + model = pywbem.CIMInstance(classname=objPath.classname, + path=objPath) + gen = self.enum_instances(env=env, + model=model, + property_list=propertyList, + keys_only=False) + try: + iter(gen) + except TypeError: + logger.log_debug('CIMProvider MI_enumInstances returning') + return + for inst in gen: + # inst.path = build_instance_name(inst, keyNames) + if self.filter_results and propertyList: + inst = inst.copy() + filter_instance(inst, propertyList) + yield inst + logger.log_debug('CIMProvider MI_enumInstances returning') + + def MI_getInstance(self, + env, + instanceName, + propertyList): + """Return a specific CIM instance + + Implements the WBEM operation GetInstance in terms + of the get_instance method. A derived class will not normally + override this method. + + """ + + logger = env.get_logger() + logger.log_debug('CIMProvider MI_getInstance called...') + plist = None + if propertyList is not None: + plist = [s.lower() for s in propertyList] + ''' + keyNames = get_keys_from_class(cimClass) + plist = None + if propertyList is not None: + lkns = [kn.lower() for kn in keyNames] + props = pywbem.NocaseDict() + plist = [s.lower() for s in propertyList] + pklist = plist + lkns + [props.__setitem__(p.name, p) for p in cimClass.properties.values() + if p.name.lower() in pklist] + else: + props = cimClass.properties + _strip_quals(props) + ''' + model = pywbem.CIMInstance(classname=instanceName.classname, + path=instanceName) + ''' + for k, v in instanceName.keybindings.items(): + type = cimClass.properties[k].type + + if type != 'reference': + v = val = pywbem.tocimobj(type, v) + model.__setitem__(k, pywbem.CIMProperty(name=k, type=type, + value=v)) + ''' + + rval = self.get_instance(env=env, + model=model, + property_list=plist) + if self.filter_results: + filter_instance(rval, plist) + logger.log_debug('CIMProvider MI_getInstance returning') + if rval is None: + raise pywbem.CIMError(pywbem.CIM_ERR_NOT_FOUND, "") + return rval + + def MI_createInstance(self, + env, + instance): + """Create a CIM instance, and return its instance name + + Implements the WBEM operation CreateInstance in terms + of the set_instance method. A derived class will not normally + override this method. + + """ + + logger = env.get_logger() + logger.log_debug('CIMProvider MI_createInstance called...') + rval = None + ''' + ch = env.get_cimom_handle() + cimClass = ch.GetClass(instance.classname, + instance.path.namespace, + LocalOnly=False, + IncludeQualifiers=True) + ''' + # CIMOM has already filled in default property values for + # props with default values, if values not supplied by client. + rval = self.set_instance(env=env, + instance=instance, + previous_instance=None, + property_list=None) + logger.log_debug('CIMProvider MI_createInstance returning') + return rval.path + + def MI_modifyInstance(self, + env, + modifiedInstance, + propertyList): + """Modify a CIM instance + + Implements the WBEM operation ModifyInstance in terms + of the set_instance method. A derived class will not normally + override this method. + + """ + + logger = env.get_logger() + logger.log_debug('CIMProvider MI_modifyInstance called...') + plist = None + if propertyList is not None: + plist = [p.lower() for p in propertyList] + filter_instance(modifiedInstance, plist) + modifiedInstance.update(modifiedInstance.path) + self.set_instance(env=env, + instance=modifiedInstance, + previous_instance=True, + property_list=plist) + logger.log_debug('CIMProvider MI_modifyInstance returning') + + def MI_deleteInstance(self, + env, + instanceName): + """Delete a CIM instance + + Implements the WBEM operation DeleteInstance in terms + of the delete_instance method. A derived class will not normally + override this method. + + """ + + logger = env.get_logger() + logger.log_debug('CIMProvider MI_deleteInstance called...') + self.delete_instance(env=env, instance_name=instanceName) + logger.log_debug('CIMProvider MI_deleteInstance returning') + + + def MI_associators(self, + env, + objectName, + assocClassName, + resultClassName, + role, + resultRole, + propertyList): + """Return instances associated to a given object. + + Implements the WBEM operation Associators in terms + of the references method. A derived class will not normally + override this method. + + """ + + # NOTE: This should honor the parameters resultClassName, role, resultRole, + # and propertyList + logger = env.get_logger() + logger.log_debug('CIMProvider MI_associators called. assocClass: %s' % (assocClassName)) + if not assocClassName: + raise pywbem.CIMError(pywbem.CIM_ERR_FAILED, + "Empty assocClassName passed to Associators") + ''' + assocClass = ch.GetClass(assocClassName, objectName.namespace, + LocalOnly=False, + IncludeQualifiers=True) + plist = pywbem.NocaseDict() + [plist.__setitem__(p.name, p) for p in assocClass.properties.values() + if 'key' in p.qualifiers or p.type == 'reference'] + _strip_quals(plist) + ''' + ch = env.get_cimom_handle() + model = pywbem.CIMInstance(classname=assocClassName) + model.path = pywbem.CIMInstanceName(classname=assocClassName, + namespace=objectName.namespace) + for inst in self.references(env=env, + object_name=objectName, + model=model, + assoc_class_name=assocClassName, + result_class_name=resultClassName, + role=role, + result_role=None, + keys_only=False): + for prop in inst.properties.values(): + lpname = prop.name.lower() + if prop.type != 'reference': + continue + if role and role.lower() == lpname: + continue + if resultRole and resultRole.lower() != lpname: + continue + if _path_equals_ignore_host(prop.value, objectName): + continue + if resultClassName and self.filter_results and \ + resultClassName.lower() != prop.value.classname.lower(): + continue + try: + if prop.value.namespace is None: + prop.value.namespace = objectName.namespace + args = {'IncludeQualifiers':True, + 'IncludeClassOrigin':True} + if propertyList is not None: + args['PropertyList'] = propertyList + inst = ch.GetInstance(prop.value, **args) + except pywbem.CIMError, (num, msg): + if num == pywbem.CIM_ERR_NOT_FOUND: + continue + else: + raise + if inst.path is None: + inst.path = prop.value + yield inst + logger.log_debug('CIMProvider MI_associators returning') + + def MI_associatorNames(self, + env, + objectName, + assocClassName, + resultClassName, + role, + resultRole): + """Return instances names associated to a given object. + + Implements the WBEM operation AssociatorNames in terms + of the references method. A derived class will not normally + override this method. + + """ + + logger = env.get_logger() + logger.log_debug('CIMProvider MI_associatorNames called. assocClass: %s' % (assocClassName)) + if not assocClassName: + raise pywbem.CIMError(pywbem.CIM_ERR_FAILED, + "Empty assocClassName passed to AssociatorNames") + model = pywbem.CIMInstance(classname=assocClassName) + model.path = pywbem.CIMInstanceName(classname=assocClassName, + namespace=objectName.namespace) + for inst in self.references(env=env, + object_name=objectName, + model=model, + assoc_class_name=assocClassName, + result_class_name=resultClassName, + role=role, + result_role=None, + keys_only=False): + for prop in inst.properties.values(): + lpname = prop.name.lower() + if prop.type != 'reference': + continue + if role and role.lower() == lpname: + continue + if resultRole and resultRole.lower() != lpname: + continue + if _path_equals_ignore_host(prop.value, objectName): + continue + if resultClassName and self.filter_results and \ + resultClassName.lower() != prop.value.classname.lower(): + continue + if prop.value.namespace is None: + prop.value.namespace = objectName.namespace + yield prop.value + logger.log_debug('CIMProvider MI_associatorNames returning') + + def MI_references(self, + env, + objectName, + resultClassName, + role, + propertyList): + """Return instances of an association class. + + Implements the WBEM operation References in terms + of the references method. A derived class will not normally + override this method. + + """ + + logger = env.get_logger() + logger.log_debug('CIMProvider MI_references called. resultClass: %s' % (resultClassName)) + if not resultClassName: + raise pywbem.CIMError(pywbem.CIM_ERR_FAILED, + "Empty resultClassName passed to References") + plist = None + if propertyList is not None: + plist = [s.lower() for s in propertyList] + model = pywbem.CIMInstance(classname=resultClassName) + model.path = pywbem.CIMInstanceName(classname=resultClassName, + namespace=objectName.namespace) + #if role is None: + # raise pywbem.CIMError(pywbem.CIM_ERR_FAILED, + # "** this shouldn't happen") + if role: + if role not in model.properties: + raise pywbem.CIMError(pywbem.CIM_ERR_FAILED, + "** this shouldn't happen") + model[role] = objectName + + for inst in self.references(env=env, + object_name=objectName, + model=model, + assoc_class_name=resultClassName, + result_class_name='', + role=role, + result_role=None, + keys_only=False): + if self.filter_results and plist is not None: + inst = inst.copy() + filter_instance(inst, plist) + for prop in inst.properties.values(): + if hasattr(prop.value, 'namespace') and \ + prop.value.namespace is None: + prop.value.namespace = objectName.namespace + yield inst + logger.log_debug('CIMProvider MI_references returning') + + def MI_referenceNames(self, + env, + objectName, + resultClassName, + role): + """Return instance names of an association class. + + Implements the WBEM operation ReferenceNames in terms + of the references method. A derived class will not normally + override this method. + + """ + + logger = env.get_logger() + logger.log_debug('CIMProvider MI_referenceNames <2> called. resultClass: %s' % (resultClassName)) + if not resultClassName: + raise pywbem.CIMError(pywbem.CIM_ERR_FAILED, + "Empty resultClassName passed to ReferenceNames") + + model = pywbem.CIMInstance(classname=resultClassName) + model.path = pywbem.CIMInstanceName(classname=resultClassName, + namespace=objectName.namespace) + #if role is None: + # raise pywbem.CIMError(pywbem.CIM_ERR_FAILED, + # "** this shouldn't happen") + if role: + if role not in model.properties: + raise pywbem.CIMError(pywbem.CIM_ERR_FAILED, + "** this shouldn't happen") + model[role] = objectName + for inst in self.references(env=env, + object_name=objectName, + model=model, + assoc_class_name=resultClassName, + result_class_name='', + role=role, + result_role=None, + keys_only=True): + for prop in inst.properties.values(): + if hasattr(prop.value, 'namespace') and prop.value.namespace is None: + prop.value.namespace = objectName.namespace + yield inst.path + logger.log_debug('CIMProvider MI_referenceNames returning') + + def MI_invokeMethod(self, env, objectName, methodName, inputParams): + """Invoke an extrinsic method. + + Implements the InvokeMethod WBEM operation by calling the + method on a derived class called cim_method_<method_name>, + where <method_name> is the name of the CIM method, in all + lower case. + + Arguments: + env -- Provider Environment (pycimmb.ProviderEnvironment) + objectName -- The InstanceName or ClassName of the object on + which the method is invoked. + methodName -- The name of the method to be invoked. + inputParams -- A Dictionary where the key is the parameter name + and the value is the parameter value. + + The return value for invokeMethod must be a tuple of size 2 + where: + element 0 is a tuple of size 2 where element 0 is the return + data type name and element 1 is the actual data value. + element 1 is a dictionary where the key is the output + parameter name and the value is a tuple of size 2 where + element 0 is the data type name for the output parameter + and element 1 is the actual value of the output parameter. + + A derived class will not normally override this method. + + """ + + logger = env.get_logger() + logger.log_debug('CIMProvider MI_invokeMethod called. method: %s:%s' \ + % (objectName.classname,methodName)) + lmethName = "cim_method_%s" % methodName.lower() + if hasattr(self, lmethName) : + method = getattr(self, lmethName) + new_inputs = dict([('param_%s' % k.lower(), v) \ + for k, v in inputParams.items()]) + (rval, outs) = method(env=env, object_name=objectName, + method=methodName, **new_inputs) + + def add_type(v): + lv = v + if type(v) == list and len(v) > 0: + lv = v[0] + if isinstance(lv, pywbem.CIMClass): + tp = 'class' + elif isinstance(lv, pywbem.CIMInstance): + tp = 'instance' + elif isinstance(lv, pywbem.CIMInstanceName): + tp = 'reference' + elif v is None or (type(v) == list and len(v) == 0): + assert(None == 'TODO') + else: + tp = pywbem.cimtype(v) + return (tp, v) + + for k, v in outs.items(): + if hasattr(v, 'namespace') and v.namespace is None: + v.namespace = objectName.namespace + outs[k] = add_type(v) + rval = add_type(rval) + rval = (rval, outs) + else: + raise pywbem.CIMError(pywbem.CIM_ERR_METHOD_NOT_FOUND, + "%s:%s"%(objectName.classname, methodName)) + logger.log_debug('CIMProvider MI_invokeMethod returning') + return rval + +def filter_instance(inst, plist): + """Remove properties from an instance that aren't in the PropertyList + + inst -- The CIMInstance + plist -- The property List, or None. The list items must be all + lowercase. + + """ + + if plist is not None: + for pname in inst.properties.keys(): + if pname.lower() not in plist: + del inst.properties[pname] + +def get_keys_from_class(cc): + """Return list of the key property names for a class """ + return [prop.name for prop in cc.properties.values() \ + if 'key' in prop.qualifiers] + +def build_instance_name(inst, obj=None): + """Return an instance name from an instance, and set instance.path """ + if obj is None: + for _ in inst.properties.values(): + inst.path.keybindings.__setitem__(_.name, _.value) + return inst.path + if not isinstance(obj, list): + return build_instance_name(inst, get_keys_from_class(obj)) + keys = {} + for _ in obj: + if _ not in inst.properties: + raise pywbem.CIMError(pywbem.CIM_ERR_FAILED, + "Instance of %s is missing key property %s" \ + %(inst.classname, _)) + keys[_] = inst[_] + inst.path = pywbem.CIMInstanceName(classname=inst.classname, + keybindings=keys, + namespace=inst.path.namespace, + host=inst.path.host) + return inst.path + + +def _strip_quals(props): + for prop in props.values(): # remove all but key quals + try: + prop.qualifiers = pywbem.NocaseDict({'KEY': + prop.qualifiers['KEY']}) + except KeyError: + prop.qualifiers = pywbem.NocaseDict() + + +def is_subclass(ch, ns, super, sub): + """Determine if one class is a subclass of another + + Keyword Arguments: + ch -- A CIMOMHandle. Either a pycimmb.CIMOMHandle or a + pywbem.WBEMConnection. + ns -- Namespace. + super -- A string containing the super class name. + sub -- The subclass. This can either be a string or a pywbem.CIMClass. + + """ + + lsuper = super.lower() + if isinstance(sub, pywbem.CIMClass): + subname = sub.classname + subclass = sub + else: + subname = sub + subclass = None + if subname.lower() == lsuper: + return True + if subclass is None: + subclass = ch.GetClass(subname, + ns, + LocalOnly=True, + IncludeQualifiers=False, + PropertyList=[], + IncludeClassOrigin=False) + while subclass.superclass is not None: + if subclass.superclass.lower() == lsuper: + return True + subclass = ch.GetClass(subclass.superclass, + ns, + LocalOnly=True, + IncludeQualifiers=False, + PropertyList=[], + IncludeClassOrigin=False) + return False + +def codegen (cc): + """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. + + """ + + import inspect + + def format_desc (obj, indent): + linelen = 75 - indent + if isinstance(obj, basestring): + raw = obj + else: + try: + raw = obj.qualifiers['description'].value + except KeyError: + return '' + txt = '' + beg = 0 + end = 0 + while beg < len(raw): + beg = end + end += linelen + while beg < len(raw) and raw[beg].isspace(): + beg = beg+1 + while end < len(raw) and end > beg and not raw[end].isspace(): + end = end-1 + if beg == end: # a long URL + while end < len(raw) and not raw[end].isspace(): + end+= 1 + line = raw[beg:end] + line = line.replace('\n',' ') + line = line.replace('\r','') + txt += '\n%s%s'% (''.ljust(indent), line) + return txt + + ################# + def map_value(obj, val): + rv = str(val) + if 'ValueMap' not in obj.qualifiers: + return rv + if 'Values' not in obj.qualifiers: + return rv + vals = [str(x) for x in obj.qualifiers['Values'].value] + maps = [str(x) for x in obj.qualifiers['ValueMap'].value] + d = dict(zip(maps, vals)) + try: + tmp = d[str(val)] + rv = '' + for ch in tmp: + rv+= ch.isalnum() and ch or '_' + except KeyError: + pass + return rv + + ################# + def type_hint (obj, method_name=None): + if hasattr(obj, 'type'): + tx = obj.type + if 'embeddedinstance' in obj.qualifiers: + tx = "pywbem.CIMInstance(classname='%s', ...)" % \ + obj.qualifiers['embeddedinstance'].value + elif tx == 'reference': + tx = "pywbem.CIMInstanceName(classname='%s', ...)" % \ + obj.reference_class + else: + tx = obj.return_type + if hasattr(obj, 'value') and obj.value is not None: + defval = str(obj.value) + else: + defval = '' + if not tx.startswith('pywbem.'): + if tx == 'boolean': + tx = 'bool(%s)' % defval + elif tx == 'datetime': + tx = 'pywbem.CIMDateTime()' + elif tx == 'string': + tx = "''" + else: + tx = 'pywbem.%s(%s)' % (tx.capitalize(), defval) + if 'valuemap' in obj.qualifiers: + if defval: + defval = map_value(obj, defval) + else: + defval = '<VAL>' + tx = 'self.Values.%s%s.%s' % \ + (method_name and '%s.'%method_name or '', + obj.name, defval) + if hasattr(obj, 'is_array') and obj.is_array: + tx = '[%s,]' % tx + return tx + ################# + def type_str (obj, method_name=None): + if hasattr(obj, 'type'): + tx = obj.type + if 'embeddedinstance' in obj.qualifiers: + return "pywbem.CIMInstance(classname='%s', ...)" % \ + obj.qualifiers['embeddedinstance'].value + elif tx == 'reference': + return "REF (pywbem.CIMInstanceName(classname='%s', ...)" % \ + obj.reference_class + else: + tx = obj.return_type + if tx == 'boolean': + tx = 'bool' + elif tx == 'datetime': + tx = 'pywbem.CIMDateTime' + elif tx == 'string': + tx = 'unicode' + else: + tx = 'pywbem.%s' % tx.capitalize() + if hasattr(obj, 'is_array') and obj.is_array: + tx = '[%s,]' % tx + if 'valuemap' in obj.qualifiers: + tx+= ' self.Values.%s%s' % \ + (method_name and '%s.'%method_name or '',obj.name) + return tx + ################# + def is_required (obj): + if 'required' in obj.qualifiers and obj.qualifiers['required'].value: + return '(Required)' + return '' + ################# + def build_val_map(obj): + vm = obj.qualifiers['valuemap'].value + if 'values' in obj.qualifiers: + vals = obj.qualifiers['values'].value + else: + vals = vm + tmap = zip(vals,vm) + map = [] + for t in tmap: + nname = '' + for ch in t[0]: + if ch.isalnum(): + nname+= ch + else: + nname+= '_' + if hasattr(obj, 'return_type'): + tp = obj.return_type + else: + tp = obj.type + if tp == 'string': + val = "'%s'" % t[1] + else: + try: + int(t[1]) + val = 'pywbem.%s(%s)' % (tp.capitalize(), t[1]) + except ValueError: + val = t[1] + nname = "# "+nname + map.append((nname,val)) + return map + + valuemaps = {} + + for obj in cc.properties.values() + cc.methods.values(): + if 'valuemap' in obj.qualifiers: + valuemaps[obj.name] = {'<vms>':build_val_map(obj)} + + for meth in cc.methods.values(): + for parm in meth.parameters.values(): + if 'valuemap' in parm.qualifiers: + if meth.name not in valuemaps: + valuemaps[meth.name] = {} + valuemaps[meth.name][parm.name] = build_val_map(parm) + + mappings = {'classname':cc.classname, + 'classname_l':cc.classname.lower()} + isAssoc = 'association' in cc.qualifiers + + code = '''"""Python Provider for %(classname)s + +Instruments the CIM class %(classname)s + +""" + +import pywbem + +class %(classname)sProvider(pywbem.CIMProvider): + """Instrument the CIM class %(classname)s \n''' % mappings + code+= format_desc(cc, 4) + code+= ''' + """''' + + + args = inspect.getargspec(CIMProvider.get_instance)[0] + args = ', '.join(args) + code+= ''' + + def __init__ (self, env): + logger = env.get_logger() + logger.log_debug('Initializing provider %%s from %%s' \\ + %% (self.__class__.__name__, __file__)) + # If you will be filtering instances yourself according to + # property_list, role, result_role, and result_class_name + # parameters, set self.filter_results to False + # self.filter_results = False + + def get_instance(%s): + """%s""" + + logger = env.get_logger() + logger.log_debug('Entering %%s.get_instance()' \\ + %% self.__class__.__name__) + ''' % (args, CIMProvider.get_instance.__doc__ ) + keyProps = [p for p in cc.properties.values() \ + if 'key' in p.qualifiers] + code+= ''' + ux = model.update_existing + + # TODO fetch system resource matching the following keys:''' + for kp in keyProps: + code+= ''' + # model['%s']''' % kp.name + code+= '\n' + props = cc.properties.values() + props.sort() + for prop in props: + if 'key' in prop.qualifiers: + continue + #line = "#ux(%s=%s) # TODO (type = %s) %s" % \ + # (prop.name, type_hint(prop), type_str(prop), is_required(prop)) + line = "#ux(%s=%s) # TODO %s" % \ + (prop.name, type_hint(prop), is_required(prop)) + code+= ''' + %s''' % line + + args = inspect.getargspec(CIMProvider.enum_instances)[0] + args = ', '.join(args) + code+= ''' + return model + + def enum_instances(%s): + """%s""" + + logger = env.get_logger() + logger.log_debug('Entering %%s.enum_instances()' \\ + %% self.__class__.__name__) + + while False: # TODO more instances? + # TODO fetch system resource + # Key properties''' % (args, CIMProvider.enum_instances.__doc__) + for kp in keyProps: + if kp.name == 'CreationClassName': + line = "model['%s'] = '%s'" % (kp.name, cc.classname) + else: + line = "#model['%s'] = # TODO (type = %s)" % \ + (kp.name, type_str(kp)) + code+=''' + %s''' % line + code+=''' + if keys_only: + yield model + else: + try: + yield self.get_instance(env, model, cim_class) + except pywbem.CIMError, (num, msg): + if num not in (pywbem.CIM_ERR_NOT_FOUND, + pywbem.CIM_ERR_ACCESS_DENIED): + raise\n''' + + args = inspect.getargspec(CIMProvider.set_instance)[0] + args = ', '.join(args) + code+= ''' + def set_instance(%s): + """%s""" + + logger = env.get_logger() + logger.log_debug('Entering %%s.set_instance()' \\ + %% self.__class__.__name__) + # TODO create or modify the instance + raise pywbem.CIMError(pywbem.CIM_ERR_NOT_SUPPORTED) # Remove to implement + return instance''' % (args, CIMProvider.set_instance.__doc__) + + args = inspect.getargspec(CIMProvider.delete_instance)[0] + args = ', '.join(args) + code+= ''' + + def delete_instance(%s): + """%s""" + + logger = env.get_logger() + logger.log_debug('Entering %%s.delete_instance()' \\ + %% self.__class__.__name__) + + # TODO delete the resource + raise pywbem.CIMError(pywbem.CIM_ERR_NOT_SUPPORTED) # Remove to implement + ''' % (args, CIMProvider.delete_instance.__doc__) + + for method in cc.methods.values(): + inParms = [ p for p in method.parameters.values() if \ + 'in' in p.qualifiers and p.qualifiers['in'].value ] + outParms = [ p for p in method.parame... [truncated message content] |
From: <np...@us...> - 2008-09-05 22:21:17
|
Revision: 917 http://omc.svn.sourceforge.net/omc/?rev=917&view=rev Author: npaxton Date: 2008-09-05 22:21:27 +0000 (Fri, 05 Sep 2008) Log Message: ----------- Create branch with original interface, compatible with openwbem & pegasus interfaces, prior to continuing with new interface in trunk. Added Paths: ----------- cmpi-bindings/branches/oldCompatIfc/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <np...@us...> - 2008-09-05 22:19:12
|
Revision: 916 http://omc.svn.sourceforge.net/omc/?rev=916&view=rev Author: npaxton Date: 2008-09-05 22:19:22 +0000 (Fri, 05 Sep 2008) Log Message: ----------- make branches dir Added Paths: ----------- cmpi-bindings/branches/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <np...@us...> - 2008-09-05 17:32:52
|
Revision: 915 http://omc.svn.sourceforge.net/omc/?rev=915&view=rev Author: npaxton Date: 2008-09-05 17:33:02 +0000 (Fri, 05 Sep 2008) Log Message: ----------- fix init/cleanup alignment issue Modified Paths: -------------- cmpi-bindings/trunk/src/cmpi_provider_python.c Modified: cmpi-bindings/trunk/src/cmpi_provider_python.c =================================================================== --- cmpi-bindings/trunk/src/cmpi_provider_python.c 2008-09-05 05:32:58 UTC (rev 914) +++ cmpi-bindings/trunk/src/cmpi_provider_python.c 2008-09-05 17:33:02 UTC (rev 915) @@ -65,7 +65,8 @@ /* Global handle to the CIM broker. This is initialized by the CIMOM when the provider is loaded */ static const CMPIBroker * _BROKER = NULL; static pthread_mutex_t _CMPI_INIT_MUTEX = PTHREAD_MUTEX_INITIALIZER; -static int _CMPI_INIT = 0; +static int _PY_INIT = 0; // acts as a boolean - is Python Initialized +static int _MI_COUNT = 0; static PyThreadState* cmpiMainPyThreadState = NULL; //static char* _MINAME = NULL; PyObject* _PYPROVMOD = NULL; @@ -354,49 +355,57 @@ const CMPIContext * context, CMPIBoolean terminating) { - CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */ + CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */ - _SBLIM_TRACE(1,("<%d/%d> Cleanup() called", getpid(), pthread_self())); - - SWIG_PYTHON_THREAD_BEGIN_BLOCK; - Py_DecRef(_PYPROVMOD); - SWIG_PYTHON_THREAD_END_BLOCK; + SWIG_PYTHON_THREAD_BEGIN_BLOCK; + Py_DecRef(_PYPROVMOD); + SWIG_PYTHON_THREAD_END_BLOCK; - if (miHdl != NULL) + if (miHdl != NULL) { - _SBLIM_TRACE(1,("\n<%d/%d> >>>>> Cleanup(Python) called, freeing PyProviderMIHandle (%s)\n", getpid(), pthread_self(), miHdl->miName)); - free(miHdl->miName); - - /* Isn't this been done by the broker ?! */ - free(miHdl); - miHdl = NULL; + free(miHdl->miName); + + // we must free the miHdl - it is our PyProviderMIHandle. + // it is pointed to by the CMPI<type>MI * that the broker holds onto... + // the broker is responsible for freeing the CMPI<type>MI* + free(miHdl); + miHdl = NULL; } - /* De-reference _CMPI_INIT, protected by _CMPI_INIT_MUTEX - * call Py_Finalize when _CMPI_INIT drops to zero - */ - if (pthread_mutex_lock(&_CMPI_INIT_MUTEX)) + /* Decrement _MI_COUNT, protected by _CMPI_INIT_MUTEX + * call Py_Finalize when _MI_COUNT drops to zero + */ + if (pthread_mutex_lock(&_CMPI_INIT_MUTEX)) { - perror("Can't lock _CMPI_INIT_MUTEX"); - abort(); + perror("Can't lock _CMPI_INIT_MUTEX"); + abort(); } - if (--_CMPI_INIT > 0) + if (--_MI_COUNT > 0) { - pthread_mutex_unlock(&_CMPI_INIT_MUTEX); - return status; + pthread_mutex_unlock(&_CMPI_INIT_MUTEX); + return status; } - pthread_mutex_unlock(&_CMPI_INIT_MUTEX); + pthread_mutex_unlock(&_CMPI_INIT_MUTEX); - PyEval_AcquireLock(); - PyThreadState_Swap(cmpiMainPyThreadState); - Py_Finalize(); + PyEval_AcquireLock(); + PyThreadState_Swap(cmpiMainPyThreadState); + if (_PY_INIT) // if PY is initialized and _MI_COUNT == 0, call Py_Finalize + { + _SBLIM_TRACE(1,("Calling Py_Finalize()")); + Py_Finalize(); + if (pthread_mutex_lock(&_CMPI_INIT_MUTEX)) + { + perror("Can't lock _CMPI_INIT_MUTEX"); + abort(); + } + _PY_INIT=0; // false + pthread_mutex_unlock(&_CMPI_INIT_MUTEX); + } - _SBLIM_TRACE(1,("<%d/%d> Cleanup(Python) called", getpid(), pthread_self())); - - /* Finished. */ + /* Finished. */ exit: - _SBLIM_TRACE(1,("<%d/%d> Cleanup() %s", getpid(), pthread_self(), (status.rc == CMPI_RC_OK)? "succeeded":"failed")); - return status; + _SBLIM_TRACE(1,("Cleanup() %s", (status.rc == CMPI_RC_OK)? "succeeded":"failed")); + return status; } static CMPIStatus InstCleanup( @@ -404,6 +413,7 @@ const CMPIContext * context, CMPIBoolean terminating) { + _SBLIM_TRACE(1,("Cleanup(Python) called for Instance provider %s", ((PyProviderMIHandle *)self->hdl)->miName)); return Cleanup((PyProviderMIHandle*)self->hdl, context, terminating); } @@ -412,6 +422,7 @@ const CMPIContext * context, CMPIBoolean terminating) { + _SBLIM_TRACE(1,("Cleanup(Python) called for Association provider %s", ((PyProviderMIHandle *)self->hdl)->miName)); return Cleanup((PyProviderMIHandle*)self->hdl, context, terminating); } @@ -420,6 +431,7 @@ const CMPIContext * context, CMPIBoolean terminating) { + _SBLIM_TRACE(1,("Cleanup(Python) called for Method provider %s", ((PyProviderMIHandle *)self->hdl)->miName)); return Cleanup((PyProviderMIHandle*)self->hdl, context, terminating); } @@ -428,6 +440,7 @@ const CMPIContext * context, CMPIBoolean terminating) { + _SBLIM_TRACE(1,("Cleanup(Python) called for Indication provider %s", ((PyProviderMIHandle *)self->hdl)->miName)); return Cleanup((PyProviderMIHandle*)self->hdl, context, terminating); } @@ -441,9 +454,9 @@ const CMPIResult * result, /* [in] Contains the CIM namespace and classname */ const CMPIObjectPath * reference) /* [in] Contains the CIM namespace and classname */ { - CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations */ + CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations */ - _SBLIM_TRACE(1,("EnumInstanceNames() called")); + _SBLIM_TRACE(1,("EnumInstanceNames() called")); _SBLIM_TRACE(1,("EnumInstancesNames(Python) called, context %p, result %p, reference %p", context, result, reference)); @@ -691,9 +704,9 @@ { int rc = 0; - _SBLIM_TRACE(1,("<%d/%d> PyGlobalInitialize() called", getpid(), pthread_self())); + _SBLIM_TRACE(1,("<%d/0x%x> PyGlobalInitialize() called", getpid(), pthread_self())); - /* Do a reference count on _CMPI_INIT, protected by _CMPI_INIT_MUTEX + /* Set _CMPI_INIT, protected by _CMPI_INIT_MUTEX * so we call Py_Finalize() only once. */ if (pthread_mutex_lock(&_CMPI_INIT_MUTEX)) @@ -701,16 +714,17 @@ perror("Can't lock _CMPI_INIT_MUTEX"); abort(); } - if (_CMPI_INIT++) + if (_PY_INIT) { pthread_mutex_unlock(&_CMPI_INIT_MUTEX); - _SBLIM_TRACE(1,("<%d/%d> PyGlobalInitialize() returning: already initialized", getpid(), pthread_self())); + _SBLIM_TRACE(1,("<%d/0x%x> PyGlobalInitialize() returning: already initialized", getpid(), pthread_self())); return 0; } + _PY_INIT=1;//true pthread_mutex_unlock(&_CMPI_INIT_MUTEX); SWIGEXPORT void SWIG_init(void); - _SBLIM_TRACE(1,("<%d/%d> Python: Loading", getpid(), pthread_self())); + _SBLIM_TRACE(1,("<%d/0x%x> Python: Loading", getpid(), pthread_self())); Py_SetProgramName("cmpi_swig"); Py_Initialize(); @@ -724,14 +738,14 @@ if (_PYPROVMOD == NULL) { SWIG_PYTHON_THREAD_END_BLOCK; - _SBLIM_TRACE(1,("<%d/%d> Python: _PYPROVMOD at %p", getpid(), pthread_self(), _PYPROVMOD)); + _SBLIM_TRACE(1,("<%d/0x%x> Python: _PYPROVMOD at %p", getpid(), pthread_self(), _PYPROVMOD)); PY_CMPI_SETFAIL(get_exc_trace()); return -1; } - _SBLIM_TRACE(1,("<%d/%d> Python: _PYPROVMOD at %p", getpid(), pthread_self(), _PYPROVMOD)); + _SBLIM_TRACE(1,("<%d/0x%x> Python: _PYPROVMOD at %p", getpid(), pthread_self(), _PYPROVMOD)); SWIG_PYTHON_THREAD_END_BLOCK; - _SBLIM_TRACE(1,("<%d/%d> PyGlobalInitialize() succeeded", getpid(), pthread_self())); + _SBLIM_TRACE(1,("<%d/0x%x> PyGlobalInitialize() succeeded", getpid(), pthread_self())); return 0; } @@ -745,7 +759,7 @@ return rc; } - _SBLIM_TRACE(1,("<%d/%d> PyInitialize() called", getpid(), pthread_self())); + _SBLIM_TRACE(1,("<%d/0x%x> PyInitialize() called", getpid(), pthread_self())); SWIG_PYTHON_THREAD_BEGIN_BLOCK; PyObject* provclass = PyObject_GetAttrString(_PYPROVMOD, @@ -758,7 +772,7 @@ } PyObject* broker = SWIG_NewPointerObj((void*) _BROKER, SWIGTYPE_p__CMPIBroker, 0); PyObject* args = PyTuple_New(2); - _SBLIM_TRACE(1,("\n<%d/%d> >>>>> PyInitialize(Python) called, MINAME=%s\n", getpid(), pthread_self(), hdl->miName)); + _SBLIM_TRACE(1,("\n<%d/0x%x> >>>>> PyInitialize(Python) called, MINAME=%s\n", getpid(), pthread_self(), hdl->miName)); PyTuple_SetItem(args, 0, string2py(hdl->miName)); PyTuple_SetItem(args, 1, broker); PyObject* provinst = PyObject_CallObject(provclass, args); @@ -774,7 +788,7 @@ hdl->pyMod = provinst; SWIG_PYTHON_THREAD_END_BLOCK; - _SBLIM_TRACE(1,("<%d/%d> PyInitialize() succeeded", getpid(), pthread_self())); + _SBLIM_TRACE(1,("<%d/0x%x> PyInitialize() succeeded", getpid(), pthread_self())); return 0; } @@ -1290,6 +1304,7 @@ CMPI##ptype##MI* _Generic_Create_##ptype##MI(const CMPIBroker* broker, \ const CMPIContext* context, const char* miname, CMPIStatus* st)\ { \ + /*_SBLIM_TRACE(1, ("\n>>>>> in FACTORY: CMPI"#ptype"MI* _Generic_Create_"#ptype"MI... miname=%s", miname));*/ \ PyProviderMIHandle *hdl = (PyProviderMIHandle*)malloc(sizeof(PyProviderMIHandle)); \ if (hdl) { \ hdl->pyMod = NULL; \ @@ -1301,6 +1316,8 @@ mi->ft = &ptype##MIFT__; \ } \ createInit(broker, context, miname, st); \ + /*_SBLIM_TRACE(1, ("\n>>>>> returning mi=0x%08x mi->hdl=0x%08x mi->ft=0x%08x", mi, mi->hdl, mi->ft));*/ \ + ++_MI_COUNT; \ return mi; \ } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <kk...@us...> - 2008-09-05 05:32:49
|
Revision: 914 http://omc.svn.sourceforge.net/omc/?rev=914&view=rev Author: kkaempf Date: 2008-09-05 05:32:58 +0000 (Fri, 05 Sep 2008) Log Message: ----------- document test symlinks for cmpi-bindings Modified Paths: -------------- cmpi-bindings/trunk/test/python/README Modified: cmpi-bindings/trunk/test/python/README =================================================================== --- cmpi-bindings/trunk/test/python/README 2008-09-04 16:33:46 UTC (rev 913) +++ cmpi-bindings/trunk/test/python/README 2008-09-05 05:32:58 UTC (rev 914) @@ -20,14 +20,27 @@ # ln -s `pwd`/*.py /usr/lib/python/site-packages/pywbem/ ] + +- Create symlinks for cmpi-bindings + + cd build/swig/python + sudo ln -s `pwd`/libpyCmpiProvider.so /usr/lib/cmpi + sudo ln -s `pwd`/cmpi.py /usr/lib/python2.5/site-packages + cd ../../.. + cd swig/python + sudo ln -s `pwd`/pycmpi_provider.py /usr/lib/python2.5/site-packages + + - Create symlinks for sfcb mof/reg sudo ./setup.sh This also runs "sfcbrepos -f" - + + - Restart sfcbd + - now run TestMethod_Test.py, TestAtomProvider_Test.py as root. (they only need to run as root because they use the passwordless local unix connection). those two tests should all pass. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ba...@us...> - 2008-09-04 16:33:41
|
Revision: 913 http://omc.svn.sourceforge.net/omc/?rev=913&view=rev Author: bartw Date: 2008-09-04 16:33:46 +0000 (Thu, 04 Sep 2008) Log Message: ----------- updated TODO list Modified Paths: -------------- cmpi-bindings/trunk/TODO Modified: cmpi-bindings/trunk/TODO =================================================================== --- cmpi-bindings/trunk/TODO 2008-09-04 13:29:31 UTC (rev 912) +++ cmpi-bindings/trunk/TODO 2008-09-04 16:33:46 UTC (rev 913) @@ -6,10 +6,6 @@ Items marked as "TODO" in the code. -Fix the build to determine the python version and dynamically link -to libpython. Cmake only knows how to statically link to libpython. -Right now it is hard-coded for libpython-2.5. - Finish wrapping broker FTs, such as upcalls. Handling CMPIStatus: @@ -21,7 +17,5 @@ [Not possible to pass status+message in a generic way. How about a toplevel function which raised the execption ?] -Split src/ into target-specific and common parts - Wrap CMPIEnumeration and CMPIArray in typemaps. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <kk...@us...> - 2008-09-04 13:29:22
|
Revision: 912 http://omc.svn.sourceforge.net/omc/?rev=912&view=rev Author: kkaempf Date: 2008-09-04 13:29:31 +0000 (Thu, 04 Sep 2008) Log Message: ----------- do a reference counting for Py_Initialize/Py_Finalize, protected by a mutex. Modified Paths: -------------- cmpi-bindings/trunk/src/cmpi_provider_python.c Modified: cmpi-bindings/trunk/src/cmpi_provider_python.c =================================================================== --- cmpi-bindings/trunk/src/cmpi_provider_python.c 2008-09-04 00:19:37 UTC (rev 911) +++ cmpi-bindings/trunk/src/cmpi_provider_python.c 2008-09-04 13:29:31 UTC (rev 912) @@ -34,6 +34,7 @@ #include <stdio.h> #include <stdarg.h> +#include <pthread.h> /* Include the required CMPI macros, data types, and API function headers */ #include <cmpidt.h> @@ -63,6 +64,7 @@ /* Global handle to the CIM broker. This is initialized by the CIMOM when the provider is loaded */ static const CMPIBroker * _BROKER = NULL; +static pthread_mutex_t _CMPI_INIT_MUTEX = PTHREAD_MUTEX_INITIALIZER; static int _CMPI_INIT = 0; static PyThreadState* cmpiMainPyThreadState = NULL; //static char* _MINAME = NULL; @@ -352,31 +354,48 @@ const CMPIContext * context, CMPIBoolean terminating) { - CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */ - - _SBLIM_TRACE(1,("Cleanup() called")); - - SWIG_PYTHON_THREAD_BEGIN_BLOCK; - - Py_DecRef(_PYPROVMOD); - SWIG_PYTHON_THREAD_END_BLOCK; - PyEval_AcquireLock(); - PyThreadState_Swap(cmpiMainPyThreadState); - Py_Finalize(); - - _SBLIM_TRACE(1,("Cleanup(Python) called")); + CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */ + + _SBLIM_TRACE(1,("<%d/%d> Cleanup() called", getpid(), pthread_self())); - if (miHdl != NULL) - { - _SBLIM_TRACE(1,("\n>>>>> Cleanup(Python) called, freeing PyProviderMIHandle (%s)\n", miHdl->miName)); - free(miHdl->miName); - free(miHdl); - miHdl = NULL; - } - + SWIG_PYTHON_THREAD_BEGIN_BLOCK; + Py_DecRef(_PYPROVMOD); + SWIG_PYTHON_THREAD_END_BLOCK; + + if (miHdl != NULL) + { + _SBLIM_TRACE(1,("\n<%d/%d> >>>>> Cleanup(Python) called, freeing PyProviderMIHandle (%s)\n", getpid(), pthread_self(), miHdl->miName)); + free(miHdl->miName); + + /* Isn't this been done by the broker ?! */ + free(miHdl); + miHdl = NULL; + } + + /* De-reference _CMPI_INIT, protected by _CMPI_INIT_MUTEX + * call Py_Finalize when _CMPI_INIT drops to zero + */ + if (pthread_mutex_lock(&_CMPI_INIT_MUTEX)) + { + perror("Can't lock _CMPI_INIT_MUTEX"); + abort(); + } + if (--_CMPI_INIT > 0) + { + pthread_mutex_unlock(&_CMPI_INIT_MUTEX); + return status; + } + pthread_mutex_unlock(&_CMPI_INIT_MUTEX); + + PyEval_AcquireLock(); + PyThreadState_Swap(cmpiMainPyThreadState); + Py_Finalize(); + + _SBLIM_TRACE(1,("<%d/%d> Cleanup(Python) called", getpid(), pthread_self())); + /* Finished. */ exit: - _SBLIM_TRACE(1,("Cleanup() %s", (status.rc == CMPI_RC_OK)? "succeeded":"failed")); + _SBLIM_TRACE(1,("<%d/%d> Cleanup() %s", getpid(), pthread_self(), (status.rc == CMPI_RC_OK)? "succeeded":"failed")); return status; } @@ -670,80 +689,93 @@ #define PY_CMPI_SETFAIL(msgstr) {if (st != NULL) st->rc = CMPI_RC_ERR_FAILED; st->msg = msgstr; } static int PyGlobalInitialize(CMPIStatus* st) { - int rc = 0; + int rc = 0; - _SBLIM_TRACE(1,("PyGlobalInitialize() called")); - if (_CMPI_INIT) + _SBLIM_TRACE(1,("<%d/%d> PyGlobalInitialize() called", getpid(), pthread_self())); + + /* Do a reference count on _CMPI_INIT, protected by _CMPI_INIT_MUTEX + * so we call Py_Finalize() only once. + */ + if (pthread_mutex_lock(&_CMPI_INIT_MUTEX)) + { + perror("Can't lock _CMPI_INIT_MUTEX"); + abort(); + } + if (_CMPI_INIT++) { - _SBLIM_TRACE(1,("PyGlobalInitialize() returning: already initialized")); - return 0; + pthread_mutex_unlock(&_CMPI_INIT_MUTEX); + _SBLIM_TRACE(1,("<%d/%d> PyGlobalInitialize() returning: already initialized", getpid(), pthread_self())); + return 0; } - _CMPI_INIT = 1; - SWIGEXPORT void SWIG_init(void); - _SBLIM_TRACE(1,("Python: Loading")); - - Py_SetProgramName("cmpi_swig"); - Py_Initialize(); - PyEval_InitThreads(); - cmpiMainPyThreadState = PyGILState_GetThisThreadState(); - PyEval_ReleaseThread(cmpiMainPyThreadState); + pthread_mutex_unlock(&_CMPI_INIT_MUTEX); - SWIG_PYTHON_THREAD_BEGIN_BLOCK; - SWIG_init(); - _PYPROVMOD = PyImport_ImportModule("pycmpi_provider"); - if (_PYPROVMOD == NULL) - { - SWIG_PYTHON_THREAD_END_BLOCK; - _SBLIM_TRACE(1,("Python: _PYPROVMOD at %p", _PYPROVMOD)); - PY_CMPI_SETFAIL(get_exc_trace()); - return -1; - } - _SBLIM_TRACE(1,("Python: _PYPROVMOD at %p", _PYPROVMOD)); + SWIGEXPORT void SWIG_init(void); + _SBLIM_TRACE(1,("<%d/%d> Python: Loading", getpid(), pthread_self())); + + Py_SetProgramName("cmpi_swig"); + Py_Initialize(); + PyEval_InitThreads(); + cmpiMainPyThreadState = PyGILState_GetThisThreadState(); + PyEval_ReleaseThread(cmpiMainPyThreadState); + + SWIG_PYTHON_THREAD_BEGIN_BLOCK; + SWIG_init(); + _PYPROVMOD = PyImport_ImportModule("pycmpi_provider"); + if (_PYPROVMOD == NULL) + { + SWIG_PYTHON_THREAD_END_BLOCK; + _SBLIM_TRACE(1,("<%d/%d> Python: _PYPROVMOD at %p", getpid(), pthread_self(), _PYPROVMOD)); + PY_CMPI_SETFAIL(get_exc_trace()); + return -1; + } + _SBLIM_TRACE(1,("<%d/%d> Python: _PYPROVMOD at %p", getpid(), pthread_self(), _PYPROVMOD)); + + SWIG_PYTHON_THREAD_END_BLOCK; + _SBLIM_TRACE(1,("<%d/%d> PyGlobalInitialize() succeeded", getpid(), pthread_self())); + return 0; +} - SWIG_PYTHON_THREAD_END_BLOCK; - _SBLIM_TRACE(1,("PyGlobalInitialize() succeeded")); - return 0; -} + static int PyInitialize(PyProviderMIHandle* hdl, CMPIStatus* st) { - int rc = 0; - rc = PyGlobalInitialize(st); - if (rc != 0) - { - return rc; - } + int rc = 0; + rc = PyGlobalInitialize(st); + if (rc != 0) + { + return rc; + } - _SBLIM_TRACE(1,("PyInitialize() called")); - - SWIG_PYTHON_THREAD_BEGIN_BLOCK; - PyObject* provclass = PyObject_GetAttrString(_PYPROVMOD, - "CMPIProvider"); - if (provclass == NULL) + _SBLIM_TRACE(1,("<%d/%d> PyInitialize() called", getpid(), pthread_self())); + + SWIG_PYTHON_THREAD_BEGIN_BLOCK; + PyObject* provclass = PyObject_GetAttrString(_PYPROVMOD, + "CMPIProvider"); + if (provclass == NULL) { - SWIG_PYTHON_THREAD_END_BLOCK; - PY_CMPI_SETFAIL(get_exc_trace()); - return -1; + SWIG_PYTHON_THREAD_END_BLOCK; + PY_CMPI_SETFAIL(get_exc_trace()); + return -1; } - PyObject* broker = SWIG_NewPointerObj((void*) _BROKER, SWIGTYPE_p__CMPIBroker, 0); - PyObject* args = PyTuple_New(2); - _SBLIM_TRACE(1,("\n>>>>> PyInitialize(Python) called, MINAME=%s\n", hdl->miName)); - PyTuple_SetItem(args, 0, string2py(hdl->miName)); - PyTuple_SetItem(args, 1, broker); - PyObject* provinst = PyObject_CallObject(provclass, args); - Py_DecRef(args); - Py_DecRef(provclass); - if (provinst == NULL) + PyObject* broker = SWIG_NewPointerObj((void*) _BROKER, SWIGTYPE_p__CMPIBroker, 0); + PyObject* args = PyTuple_New(2); + _SBLIM_TRACE(1,("\n<%d/%d> >>>>> PyInitialize(Python) called, MINAME=%s\n", getpid(), pthread_self(), hdl->miName)); + PyTuple_SetItem(args, 0, string2py(hdl->miName)); + PyTuple_SetItem(args, 1, broker); + PyObject* provinst = PyObject_CallObject(provclass, args); + Py_DecRef(args); + Py_DecRef(provclass); + if (provinst == NULL) { - SWIG_PYTHON_THREAD_END_BLOCK; - PY_CMPI_SETFAIL(get_exc_trace()); - return -1; + SWIG_PYTHON_THREAD_END_BLOCK; + PY_CMPI_SETFAIL(get_exc_trace()); + return -1; } - - hdl->pyMod = provinst; - - SWIG_PYTHON_THREAD_END_BLOCK; - _SBLIM_TRACE(1,("PyInitialize() succeeded")); - return 0; + + hdl->pyMod = provinst; + + SWIG_PYTHON_THREAD_END_BLOCK; + _SBLIM_TRACE(1,("<%d/%d> PyInitialize() succeeded", getpid(), pthread_self())); + return 0; } @@ -1185,13 +1217,6 @@ /***************************************************************************/ - - - - - - - static CMPIMethodMIFT MethodMIFT__={ CMPICurrentVersion, CMPICurrentVersion, @@ -1245,7 +1270,13 @@ const CMPIContext* context, const char* miname, CMPIStatus* st) { _SBLIM_TRACE(1,("\n>>>>> createInit(Python) called, miname= %s (ctx=%p)\n", miname, context)); - _BROKER = broker; + if (!_BROKER) + { + _BROKER = broker; + } + else if (_BROKER != broker) + fprintf(stderr, "createInit broker %p, _BROKER %p\n", broker, _BROKER); + //_MINAME = strdup(miname); /* * We can't initialize Python here and load Python modules, because This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ba...@us...> - 2008-09-04 00:19:29
|
Revision: 911 http://omc.svn.sourceforge.net/omc/?rev=911&view=rev Author: bartw Date: 2008-09-04 00:19:37 +0000 (Thu, 04 Sep 2008) Log Message: ----------- fixed deadlock issue Modified Paths: -------------- cmpi-bindings/trunk/src/cmpi_provider_python.c Modified: cmpi-bindings/trunk/src/cmpi_provider_python.c =================================================================== --- cmpi-bindings/trunk/src/cmpi_provider_python.c 2008-09-03 23:16:13 UTC (rev 910) +++ cmpi-bindings/trunk/src/cmpi_provider_python.c 2008-09-04 00:19:37 UTC (rev 911) @@ -64,6 +64,7 @@ /* Global handle to the CIM broker. This is initialized by the CIMOM when the provider is loaded */ static const CMPIBroker * _BROKER = NULL; static int _CMPI_INIT = 0; +static PyThreadState* cmpiMainPyThreadState = NULL; //static char* _MINAME = NULL; PyObject* _PYPROVMOD = NULL; @@ -358,9 +359,10 @@ SWIG_PYTHON_THREAD_BEGIN_BLOCK; Py_DecRef(_PYPROVMOD); + SWIG_PYTHON_THREAD_END_BLOCK; + PyEval_AcquireLock(); + PyThreadState_Swap(cmpiMainPyThreadState); Py_Finalize(); - // TODO should release come before finalize? - SWIG_PYTHON_THREAD_END_BLOCK; _SBLIM_TRACE(1,("Cleanup(Python) called")); @@ -681,11 +683,13 @@ _SBLIM_TRACE(1,("Python: Loading")); Py_SetProgramName("cmpi_swig"); + Py_Initialize(); PyEval_InitThreads(); - Py_Initialize(); + cmpiMainPyThreadState = PyGILState_GetThisThreadState(); + PyEval_ReleaseThread(cmpiMainPyThreadState); + SWIG_PYTHON_THREAD_BEGIN_BLOCK; SWIG_init(); - SWIG_PYTHON_THREAD_BEGIN_BLOCK; _PYPROVMOD = PyImport_ImportModule("pycmpi_provider"); if (_PYPROVMOD == NULL) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <np...@us...> - 2008-09-03 23:16:05
|
Revision: 910 http://omc.svn.sourceforge.net/omc/?rev=910&view=rev Author: npaxton Date: 2008-09-03 23:16:13 +0000 (Wed, 03 Sep 2008) Log Message: ----------- fix typo: arg to args Modified Paths: -------------- cmpi-bindings/trunk/swig/python/pycmpi_provider.py Modified: cmpi-bindings/trunk/swig/python/pycmpi_provider.py =================================================================== --- cmpi-bindings/trunk/swig/python/pycmpi_provider.py 2008-09-03 22:52:27 UTC (rev 909) +++ cmpi-bindings/trunk/swig/python/pycmpi_provider.py 2008-09-03 23:16:13 UTC (rev 910) @@ -167,7 +167,7 @@ cc = _get_class(op.namespace, op.classname) try: pinst = self.proxy.MI_getInstance(self.env, op, plist, cc) - except pywbem.CIMError, arg: + except pywbem.CIMError, args: return args[:2] cinst = pywbem2cmpi_inst(pinst) rslt.return_instance(cinst) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ba...@us...> - 2008-09-03 22:52:18
|
Revision: 909 http://omc.svn.sourceforge.net/omc/?rev=909&view=rev Author: bartw Date: 2008-09-03 22:52:27 +0000 (Wed, 03 Sep 2008) Log Message: ----------- split initialization into global stuff and per-miname stuff Modified Paths: -------------- cmpi-bindings/trunk/src/cmpi_provider_python.c Modified: cmpi-bindings/trunk/src/cmpi_provider_python.c =================================================================== --- cmpi-bindings/trunk/src/cmpi_provider_python.c 2008-09-03 17:49:14 UTC (rev 908) +++ cmpi-bindings/trunk/src/cmpi_provider_python.c 2008-09-03 22:52:27 UTC (rev 909) @@ -63,6 +63,7 @@ /* Global handle to the CIM broker. This is initialized by the CIMOM when the provider is loaded */ static const CMPIBroker * _BROKER = NULL; +static int _CMPI_INIT = 0; //static char* _MINAME = NULL; PyObject* _PYPROVMOD = NULL; @@ -246,8 +247,8 @@ pyfunc = PyObject_GetAttrString(hdl->pyMod, opname); if (pyfunc == NULL) { - PyErr_Print(); - PyErr_Clear(); + PyErr_Print(); + PyErr_Clear(); char* str = fmtstr("Python module does not contain \"%s\"", opname); _SBLIM_TRACE(1,(str)); st->rc = CMPI_RC_ERR_FAILED; @@ -665,33 +666,52 @@ #define PY_CMPI_SETFAIL(msgstr) {if (st != NULL) st->rc = CMPI_RC_ERR_FAILED; st->msg = msgstr; } -static int PyInitialize(PyProviderMIHandle* hdl, CMPIStatus* st) +static int PyGlobalInitialize(CMPIStatus* st) { int rc = 0; - SWIGEXPORT void SWIG_init(void); - - _SBLIM_TRACE(1,("PyInitialize() called")); - - _SBLIM_TRACE(1,("Python: Loading")); - + _SBLIM_TRACE(1,("PyGlobalInitialize() called")); + if (_CMPI_INIT) + { + _SBLIM_TRACE(1,("PyGlobalInitialize() returning: already initialized")); + return 0; + } + _CMPI_INIT = 1; + SWIGEXPORT void SWIG_init(void); + _SBLIM_TRACE(1,("Python: Loading")); - Py_SetProgramName("cmpi_swig"); - //PyEval_InitThreads(); - Py_Initialize(); + Py_SetProgramName("cmpi_swig"); + PyEval_InitThreads(); + Py_Initialize(); - SWIG_init(); + SWIG_init(); + SWIG_PYTHON_THREAD_BEGIN_BLOCK; + _PYPROVMOD = PyImport_ImportModule("pycmpi_provider"); + if (_PYPROVMOD == NULL) + { + SWIG_PYTHON_THREAD_END_BLOCK; + _SBLIM_TRACE(1,("Python: _PYPROVMOD at %p", _PYPROVMOD)); + PY_CMPI_SETFAIL(get_exc_trace()); + return -1; + } + _SBLIM_TRACE(1,("Python: _PYPROVMOD at %p", _PYPROVMOD)); + SWIG_PYTHON_THREAD_END_BLOCK; + _SBLIM_TRACE(1,("PyGlobalInitialize() succeeded")); + return 0; +} +static int PyInitialize(PyProviderMIHandle* hdl, CMPIStatus* st) +{ + int rc = 0; + rc = PyGlobalInitialize(st); + if (rc != 0) + { + return rc; + } + + _SBLIM_TRACE(1,("PyInitialize() called")); + SWIG_PYTHON_THREAD_BEGIN_BLOCK; - _PYPROVMOD = PyImport_ImportModule("pycmpi_provider"); - if (_PYPROVMOD == NULL) - { - SWIG_PYTHON_THREAD_END_BLOCK; - _SBLIM_TRACE(1,("Python: _PYPROVMOD at %p", _PYPROVMOD)); - PY_CMPI_SETFAIL(get_exc_trace()); - return -1; - } - _SBLIM_TRACE(1,("Python: _PYPROVMOD at %p", _PYPROVMOD)); PyObject* provclass = PyObject_GetAttrString(_PYPROVMOD, "CMPIProvider"); if (provclass == NULL) @@ -718,8 +738,6 @@ hdl->pyMod = provinst; SWIG_PYTHON_THREAD_END_BLOCK; - - _SBLIM_TRACE(1,("PyInitialize() succeeded")); return 0; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ba...@us...> - 2008-09-03 17:49:11
|
Revision: 908 http://omc.svn.sourceforge.net/omc/?rev=908&view=rev Author: bartw Date: 2008-09-03 17:49:14 +0000 (Wed, 03 Sep 2008) Log Message: ----------- fixed some of the threading stuff. Modified Paths: -------------- cmpi-bindings/trunk/src/cmpi_provider_python.c Modified: cmpi-bindings/trunk/src/cmpi_provider_python.c =================================================================== --- cmpi-bindings/trunk/src/cmpi_provider_python.c 2008-09-02 19:08:45 UTC (rev 907) +++ cmpi-bindings/trunk/src/cmpi_provider_python.c 2008-09-03 17:49:14 UTC (rev 908) @@ -31,7 +31,6 @@ static char _CLASSNAME[] = "CmpiInstanceSwig"; -#define WITH_SWIG_THREADS 0 #include <stdio.h> #include <stdarg.h> @@ -108,18 +107,14 @@ Py_RETURN_NONE; } PyObject* pl; -#if WITH_SWIG_THREADS SWIG_PYTHON_THREAD_BEGIN_BLOCK; -#endif pl = PyList_New(0); for (; *cplist != NULL; ++cplist) { PyList_Append(pl, PyString_FromString(*cplist)); } -#if WITH_SWIG_THREADS - SWIG_PYTHON_THREAD_END_BLOCK -#endif + SWIG_PYTHON_THREAD_END_BLOCK; return pl; } @@ -129,14 +124,10 @@ string2py(const char *s) { PyObject *obj; -#if WITH_SWIG_THREADS SWIG_PYTHON_THREAD_BEGIN_BLOCK; -#endif obj = PyString_FromString(s); -#if WITH_SWIG_THREADS - SWIG_PYTHON_THREAD_END_BLOCK -#endif + SWIG_PYTHON_THREAD_END_BLOCK; return obj; } @@ -249,9 +240,7 @@ PyObject *pyargs = NULL; PyObject *pyfunc = NULL; PyObject *prv = NULL; -#if WITH_SWIG_THREADS SWIG_PYTHON_THREAD_BEGIN_BLOCK; -#endif pyargs = PyTuple_New(nargs); pyfunc = PyObject_GetAttrString(hdl->pyMod, opname); @@ -346,9 +335,7 @@ Py_DecRef(pyargs); Py_DecRef(pyfunc); Py_DecRef(prv); -#if WITH_SWIG_THREADS - SWIG_PYTHON_THREAD_END_BLOCK -#endif + SWIG_PYTHON_THREAD_END_BLOCK; return rc; } @@ -367,16 +354,12 @@ _SBLIM_TRACE(1,("Cleanup() called")); -#if WITH_SWIG_THREADS SWIG_PYTHON_THREAD_BEGIN_BLOCK; -#endif Py_DecRef(_PYPROVMOD); Py_Finalize(); // TODO should release come before finalize? -#if WITH_SWIG_THREADS - SWIG_PYTHON_THREAD_END_BLOCK -#endif + SWIG_PYTHON_THREAD_END_BLOCK; _SBLIM_TRACE(1,("Cleanup(Python) called")); @@ -692,36 +675,30 @@ _SBLIM_TRACE(1,("Python: Loading")); -#if WITH_SWIG_THREADS - SWIG_PYTHON_THREAD_BEGIN_BLOCK; -#endif Py_SetProgramName("cmpi_swig"); - PyEval_InitThreads(); + //PyEval_InitThreads(); Py_Initialize(); SWIG_init(); + SWIG_PYTHON_THREAD_BEGIN_BLOCK; _PYPROVMOD = PyImport_ImportModule("pycmpi_provider"); if (_PYPROVMOD == NULL) { - _SBLIM_TRACE(1,("Python: _PYPROVMOD at %p", _PYPROVMOD)); - PY_CMPI_SETFAIL(get_exc_trace()); -#if WITH_SWIG_THREADS SWIG_PYTHON_THREAD_END_BLOCK; -#endif - return -1; + _SBLIM_TRACE(1,("Python: _PYPROVMOD at %p", _PYPROVMOD)); + PY_CMPI_SETFAIL(get_exc_trace()); + return -1; } _SBLIM_TRACE(1,("Python: _PYPROVMOD at %p", _PYPROVMOD)); PyObject* provclass = PyObject_GetAttrString(_PYPROVMOD, "CMPIProvider"); if (provclass == NULL) { - PY_CMPI_SETFAIL(get_exc_trace()); -#if WITH_SWIG_THREADS SWIG_PYTHON_THREAD_END_BLOCK; -#endif - return -1; + PY_CMPI_SETFAIL(get_exc_trace()); + return -1; } PyObject* broker = SWIG_NewPointerObj((void*) _BROKER, SWIGTYPE_p__CMPIBroker, 0); PyObject* args = PyTuple_New(2); @@ -733,18 +710,14 @@ Py_DecRef(provclass); if (provinst == NULL) { - PY_CMPI_SETFAIL(get_exc_trace()); -#if WITH_SWIG_THREADS SWIG_PYTHON_THREAD_END_BLOCK; -#endif - return -1; + PY_CMPI_SETFAIL(get_exc_trace()); + return -1; } hdl->pyMod = provinst; -#if WITH_SWIG_THREADS - SWIG_PYTHON_THREAD_END_BLOCK -#endif + SWIG_PYTHON_THREAD_END_BLOCK; _SBLIM_TRACE(1,("PyInitialize() succeeded")); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |