November 17-21, 2008, Santa Clara Marriott, Santa Clara, CA Scripting Openwsman server plugins Klaus Kämpf <[email protected]> Motivation • Management instrumentation is not sexy • CIM learning curve • Writing CIM providers is complex Easy remote access to services 2 Instrumentation wishlist • Single protocol • Single daemon • Single open port • Firewall friendly • Easy to code • Interoperable 3 Properties of WS-Management • Management of Resources – Universal resource identifiers • Generic semantics on resources • Transport interface • There's more than just WS-CIM openwsman • Open source implementation of WS- Management • Client and Server • Server architecture is plugin based • Includes (WS-)CIM plugin openwsman plugins • Plugins handle resources • Resources are accessed by their universal resource identifier (URI) • URI = namespace + classname + keys • namespace + class prefix identify plugin • Plugins provide endpoints for resource operations Openwsman Architecture HTTP Server openwsmand Listen Authorize Dispatch Endpoints Endpoints WS-Enumeration InvokeEndpoints Enumerate Identify Pull Release WS-Transfer Create WS-Eventing Delete Subscribe Get Unsubscribe Put Renew 7 Plugins • Simple C interface • See my MDC2007 presentation “Web Service Management Application Enablement” • Goal: Write plugins in scripting language 8 Motivation • Make the developers life easier • Scripting language – Edit-Run vs. Edit-Compile-Link-Run • Use the tools best fitted to the task • Drastically reduce code size • Let developers focus on instrumentation • Leverage dynamic scripting languages • Portability 9 Design goals • Support most popular scripting languages – Python, Ruby, Perl, ... • Object orientation – Reduce parameters – Leverage exceptions • Reuse openwsman client bindings – Add server bindings • Consistent API – Similar code across scripting languages 10 How it was done • Use a code generator (SWIG) • Reuse of generic code • Similar 'look&feel' across languages • Small language dependent layer SWIG Simplified Wrapper and Interface Generator SWIG SWIG is an interface compiler that connects programs written in C and C++ with scripting languages such as Perl, Python, Ruby, and more. SWIG: Motivation • Building more powerful C/C++ programs • Portability • Make C libraries 'object oriented' • Rapid prototyping and debugging • Systems integration • Construction of scripting language extension modules SWIG: About • Homepage: http://www.swig.org • Available for – Linux – Unix (AIX, HP-UX, Solaris, ...) – Macintosh OS-X/Darwin – Windows 95/98/NT/2000/XP/Vista • History Initially started in July, 1995 at Los Alamos National Laboratory. First alpha release: February, 1996. Latest release: April 7, 2008. SWIG-1.3.35 • Active development 3-4 releases per year SWIG: Languages Allegro Common Lisp CFFI (Common Lisp) CLisp Octave Chicken (Scheme) MzScheme SWIG – How does it work ? wsman.h C header SWIG – How does it work ? wsman.h C header %module wsman wsman.i %include "wsman.h" Interface description SWIG – How does it work ? cmpi.h SWIG C header cmpi.i Interface description SWIG – How does it work ? wsman.h SWIG C header wsman_wrap.c Binding code wsman.i Interface description wsman.py (Python code) SWIG – How does it work ? wsman.h SWIG C header wsman_wrap.c Binding code wsman.i Interface description Compiler wsman.py (Python code) wsman_wrap.so Target language module SWIG - Usage Example: Python test.py import pywsman SWIG - Usage Example: Python test.py pywsman.py import pywsman SWIG - Usage Example: Python test.py pywsman.py wsman_wrap.so import pywsman SWIG - Usage Example: Python test.py pywsman.py wsman_wrap.so import pywsman client = Client(“http://localhost”) options = ClientOptions() doc = client.identify( options ) Result • Target language module • Access to openwsman data structures • Access to openwsman manipulation functions • Data wrappers ( C <-> target language) • Missing: openwsman plugin API swig-plugin.c • Manually crafted plugin interface • Supports all endpoint functions • Target language agnostic • Converts C data to target language • Calls target language • Status handling Building bridges wsman.h SWIG C header wsman_wrap.c swig-plugin.c Binding code wsman.i Interface description Compiler wsman.py (Python code) wsman_wrap.so Target language module + openwsman plugin API Plugin endpoint example static int Swig_Enumerate_EP( WsContextH cntx, WsEnumerateInfo* enumInfo, WsmanStatus *status, void *opaqueData ) { Target_Type _context, _enumInfo; Target_Type _status; int rc; _context = SWIG_NewPointerObj((void*) cntx, SWIGTYPE_p__WS_CONTEXT, OWN); _enumInfo = SWIG_NewPointerObj((void*) enumInfo, SWIGTYPE_p___WsEnumerateInfo, OWN); _status = SWIG_NewPointerObj((void*) status, SWIGTYPE_p__WsmanStatus, OWN); rc = TargetCall(cntx->indoc, _TARGET_MODULE, "enumerate", 3, _context, _enumInfo, _status ); return rc; } target_$lang.c • Target language specific layer • Very thin – TargetInitialize(...) – TargetCall(...) – TargetCleanup(...) • Loads/Unloads target interpreter • Loads endpoint implementation • Calls endpoint implementation Code size • swig-plugin.c: 1225 lines • target_python.c: 491 lines • target_ruby.c: 401 lines • Easy to maintain • Easy to extend Implementation example • Enumerate (Ruby) def enumerate context, enum_info, status selectors = context.selectors results = compute( selectors ) # compute enumeration result enum_info.index = 0; enum_info.total_items = results.size enum_info.enum_results = results enum_info.enum_context = self true # success ! end Implementation example (cont.) • Pull (Ruby) def self.pull context, enum_info, status if enum_info.index < enum_info.total_items then # create SOAP response out_doc = context.indoc.create_response_envelope body = out_doc.body # Construct WS-Enumeration pull response response = body.add(XML_NS_ENUMERATION, WSENUM_PULL_RESP) response = response.add(XML_NS_ENUMERATION, WSENUM_ITEMS) # resource representation response.add(enum_info.result[enum_info.index].to_xml) enum_info.pull_result = out_doc return true end end Status • Beta quality – Code available through openwsman svn • Ruby as first choice – Author is a Python illiterate • Need other languages ? – Please give feedback (or code) Outlook • Documentation • Improve openwsman plugin API • Finish Python backend References • Openwsman – http://www.openwsman.org • Swig plugin source – http://www.openwsman.org/trac/browser/openws man/trunk/src/plugins/swig • Swig – http://www.swig.org Thank you ! Questions ?.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages37 Page
-
File Size-