scripting openwsman server plugins - suse linuxkkaempf/presentations/mdc2008/openwsm… ·...
TRANSCRIPT
November 17-21, 2008, Santa Clara Marriott, Santa Clara, CA
Scripting Openwsman server plugins
Klaus Kämpf<[email protected]>
2
Motivation
• Management instrumentation is not sexy• CIM learning curve• Writing CIM providers is complex
Easy remote access to services
3
Instrumentation wishlist
• Single protocol• Single daemon• Single open port• Firewall friendly• Easy to code• Interoperable
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
7
Openwsman Architecture
EndpointsEndpoints
openwsmand
Dispatch
AuthorizeListen
HTTP Server
Endpoints
Invoke Identify
WS-Transfer Create Delete Get Put
WS-Enumeration Enumerate Pull Release
WS-Eventing Subscribe Unsubscribe Renew
8
Plugins
• Simple C interface• See my MDC2007 presentation
“Web Service Management Application Enablement”
• Goal: Write plugins in scripting language
9
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
10
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
How it was done
• Use a code generator (SWIG)• Reuse of generic code• Similar 'look&feel' across languages• Small language dependent layer
SWIGSimplified 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
• HistoryInitially started in July, 1995 at Los Alamos National Laboratory.
First alpha release: February, 1996.
Latest release: April 7, 2008. SWIG-1.3.35
• Active development3-4 releases per year
SWIG: Languages
Allegro Common Lisp CFFI (Common Lisp)
Chicken(Scheme)
CLisp
MzScheme
Octave
SWIG – How does it work ?
wsman.h
C header
SWIG – How does it work ?
wsman.i
Interface description
%module wsman
%include "wsman.h"
wsman.h
C header
SWIG – How does it work ?
cmpi.i
Interface description
SWIGcmpi.h
C header
SWIG – How does it work ?
wsman.i
wsman_wrap.c
Interface description
SWIG
Binding code
wsman.py
(Python code)
wsman.h
C header
SWIG – How does it work ?
wsman.i
wsman_wrap.c
Interface description
SWIG
Binding code
wsman_wrap.so
Compiler
Target languagemodule
wsman.py
(Python code)
wsman.h
C header
SWIG - Usage
test.py
Example: Python
import pywsman
SWIG - Usage
pywsman.pytest.py
Example: Python
import pywsman
SWIG - Usage
pywsman.py wsman_wrap.sotest.py
Example: Python
import pywsman
SWIG - Usage
pywsman.py wsman_wrap.sotest.py
Example: Python
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.i
wsman_wrap.c
Interface description
SWIG
Binding code
wsman_wrap.so
Compiler
Target language module+openwsman plugin API
wsman.py
(Python code)
wsman.h
C header swig-plugin.c
Plugin endpoint example
static intSwig_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 ?