scripting openwsman server plugins - suse linuxkkaempf/presentations/mdc2008/openwsm… ·...

37
November 17-21, 2008, Santa Clara Marriott, Santa Clara, CA Scripting Openwsman server plugins Klaus Kämpf <[email protected]>

Upload: others

Post on 15-Jun-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Scripting Openwsman server plugins - SUSE Linuxkkaempf/Presentations/MDC2008/openwsm… · Scripting Openwsman server plugins Klaus Kämpf  2 Motivation •

November 17-21, 2008, Santa Clara Marriott, Santa Clara, CA

Scripting Openwsman server plugins

Klaus Kämpf<[email protected]>

Page 2: Scripting Openwsman server plugins - SUSE Linuxkkaempf/Presentations/MDC2008/openwsm… · Scripting Openwsman server plugins Klaus Kämpf  2 Motivation •

2

Motivation

• Management instrumentation is not sexy• CIM learning curve• Writing CIM providers is complex

Easy remote access to services

Page 3: Scripting Openwsman server plugins - SUSE Linuxkkaempf/Presentations/MDC2008/openwsm… · Scripting Openwsman server plugins Klaus Kämpf  2 Motivation •

3

Instrumentation wishlist

• Single protocol• Single daemon• Single open port• Firewall friendly• Easy to code• Interoperable

Page 4: Scripting Openwsman server plugins - SUSE Linuxkkaempf/Presentations/MDC2008/openwsm… · Scripting Openwsman server plugins Klaus Kämpf  2 Motivation •

Properties of WS-Management

• Management of Resources– Universal resource identifiers

• Generic semantics on resources• Transport interface• There's more than just WS-CIM

Page 5: Scripting Openwsman server plugins - SUSE Linuxkkaempf/Presentations/MDC2008/openwsm… · Scripting Openwsman server plugins Klaus Kämpf  2 Motivation •

openwsman

• Open source implementation of WS-Management

• Client and Server• Server architecture is plugin based• Includes (WS-)CIM plugin

Page 6: Scripting Openwsman server plugins - SUSE Linuxkkaempf/Presentations/MDC2008/openwsm… · Scripting Openwsman server plugins Klaus Kämpf  2 Motivation •

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

Page 7: Scripting Openwsman server plugins - SUSE Linuxkkaempf/Presentations/MDC2008/openwsm… · Scripting Openwsman server plugins Klaus Kämpf  2 Motivation •

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

Page 8: Scripting Openwsman server plugins - SUSE Linuxkkaempf/Presentations/MDC2008/openwsm… · Scripting Openwsman server plugins Klaus Kämpf  2 Motivation •

8

Plugins

• Simple C interface• See my MDC2007 presentation

“Web Service Management Application Enablement”

• Goal: Write plugins in scripting language

Page 9: Scripting Openwsman server plugins - SUSE Linuxkkaempf/Presentations/MDC2008/openwsm… · Scripting Openwsman server plugins Klaus Kämpf  2 Motivation •

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

Page 10: Scripting Openwsman server plugins - SUSE Linuxkkaempf/Presentations/MDC2008/openwsm… · Scripting Openwsman server plugins Klaus Kämpf  2 Motivation •

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

Page 11: Scripting Openwsman server plugins - SUSE Linuxkkaempf/Presentations/MDC2008/openwsm… · Scripting Openwsman server plugins Klaus Kämpf  2 Motivation •

How it was done

• Use a code generator (SWIG)• Reuse of generic code• Similar 'look&feel' across languages• Small language dependent layer

Page 12: Scripting Openwsman server plugins - SUSE Linuxkkaempf/Presentations/MDC2008/openwsm… · Scripting Openwsman server plugins Klaus Kämpf  2 Motivation •

SWIGSimplified Wrapper and Interface Generator

Page 13: Scripting Openwsman server plugins - SUSE Linuxkkaempf/Presentations/MDC2008/openwsm… · Scripting Openwsman server plugins Klaus Kämpf  2 Motivation •

SWIG

SWIG is an interface compiler that connects programs written in C and C++ with scripting languages such as

Perl, Python, Ruby, and more.

Page 14: Scripting Openwsman server plugins - SUSE Linuxkkaempf/Presentations/MDC2008/openwsm… · Scripting Openwsman server plugins Klaus Kämpf  2 Motivation •

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

Page 15: Scripting Openwsman server plugins - SUSE Linuxkkaempf/Presentations/MDC2008/openwsm… · Scripting Openwsman server plugins Klaus Kämpf  2 Motivation •

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

Page 16: Scripting Openwsman server plugins - SUSE Linuxkkaempf/Presentations/MDC2008/openwsm… · Scripting Openwsman server plugins Klaus Kämpf  2 Motivation •

SWIG: Languages

Allegro Common Lisp CFFI (Common Lisp)

Chicken(Scheme)

CLisp

MzScheme

Octave

Page 17: Scripting Openwsman server plugins - SUSE Linuxkkaempf/Presentations/MDC2008/openwsm… · Scripting Openwsman server plugins Klaus Kämpf  2 Motivation •

SWIG – How does it work ?

wsman.h

C header

Page 18: Scripting Openwsman server plugins - SUSE Linuxkkaempf/Presentations/MDC2008/openwsm… · Scripting Openwsman server plugins Klaus Kämpf  2 Motivation •

SWIG – How does it work ?

wsman.i

Interface description

%module wsman

%include "wsman.h"

wsman.h

C header

Page 19: Scripting Openwsman server plugins - SUSE Linuxkkaempf/Presentations/MDC2008/openwsm… · Scripting Openwsman server plugins Klaus Kämpf  2 Motivation •

SWIG – How does it work ?

cmpi.i

Interface description

SWIGcmpi.h

C header

Page 20: Scripting Openwsman server plugins - SUSE Linuxkkaempf/Presentations/MDC2008/openwsm… · Scripting Openwsman server plugins Klaus Kämpf  2 Motivation •

SWIG – How does it work ?

wsman.i

wsman_wrap.c

Interface description

SWIG

Binding code

wsman.py

(Python code)

wsman.h

C header

Page 21: Scripting Openwsman server plugins - SUSE Linuxkkaempf/Presentations/MDC2008/openwsm… · Scripting Openwsman server plugins Klaus Kämpf  2 Motivation •

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

Page 22: Scripting Openwsman server plugins - SUSE Linuxkkaempf/Presentations/MDC2008/openwsm… · Scripting Openwsman server plugins Klaus Kämpf  2 Motivation •

SWIG - Usage

test.py

Example: Python

import pywsman

Page 23: Scripting Openwsman server plugins - SUSE Linuxkkaempf/Presentations/MDC2008/openwsm… · Scripting Openwsman server plugins Klaus Kämpf  2 Motivation •

SWIG - Usage

pywsman.pytest.py

Example: Python

import pywsman

Page 24: Scripting Openwsman server plugins - SUSE Linuxkkaempf/Presentations/MDC2008/openwsm… · Scripting Openwsman server plugins Klaus Kämpf  2 Motivation •

SWIG - Usage

pywsman.py wsman_wrap.sotest.py

Example: Python

import pywsman

Page 25: Scripting Openwsman server plugins - SUSE Linuxkkaempf/Presentations/MDC2008/openwsm… · Scripting Openwsman server plugins Klaus Kämpf  2 Motivation •

SWIG - Usage

pywsman.py wsman_wrap.sotest.py

Example: Python

import pywsman

client = Client(“http://localhost”)

options = ClientOptions()

doc = client.identify( options )

Page 26: Scripting Openwsman server plugins - SUSE Linuxkkaempf/Presentations/MDC2008/openwsm… · Scripting Openwsman server plugins Klaus Kämpf  2 Motivation •

Result

• Target language module• Access to openwsman data structures• Access to openwsman manipulation functions• Data wrappers ( C <-> target language)

• Missing: openwsman plugin API

Page 27: Scripting Openwsman server plugins - SUSE Linuxkkaempf/Presentations/MDC2008/openwsm… · Scripting Openwsman server plugins Klaus Kämpf  2 Motivation •

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

Page 28: Scripting Openwsman server plugins - SUSE Linuxkkaempf/Presentations/MDC2008/openwsm… · Scripting Openwsman server plugins Klaus Kämpf  2 Motivation •

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

Page 29: Scripting Openwsman server plugins - SUSE Linuxkkaempf/Presentations/MDC2008/openwsm… · Scripting Openwsman server plugins Klaus Kämpf  2 Motivation •

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;}

Page 30: Scripting Openwsman server plugins - SUSE Linuxkkaempf/Presentations/MDC2008/openwsm… · Scripting Openwsman server plugins Klaus Kämpf  2 Motivation •

target_$lang.c

• Target language specific layer• Very thin

– TargetInitialize(...)– TargetCall(...)– TargetCleanup(...)

• Loads/Unloads target interpreter• Loads endpoint implementation• Calls endpoint implementation

Page 31: Scripting Openwsman server plugins - SUSE Linuxkkaempf/Presentations/MDC2008/openwsm… · Scripting Openwsman server plugins Klaus Kämpf  2 Motivation •

Code size

• swig-plugin.c: 1225 lines• target_python.c: 491 lines• target_ruby.c: 401 lines

• Easy to maintain• Easy to extend

Page 32: Scripting Openwsman server plugins - SUSE Linuxkkaempf/Presentations/MDC2008/openwsm… · Scripting Openwsman server plugins Klaus Kämpf  2 Motivation •

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

Page 33: Scripting Openwsman server plugins - SUSE Linuxkkaempf/Presentations/MDC2008/openwsm… · Scripting Openwsman server plugins Klaus Kämpf  2 Motivation •

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

Page 34: Scripting Openwsman server plugins - SUSE Linuxkkaempf/Presentations/MDC2008/openwsm… · Scripting Openwsman server plugins Klaus Kämpf  2 Motivation •

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)

Page 35: Scripting Openwsman server plugins - SUSE Linuxkkaempf/Presentations/MDC2008/openwsm… · Scripting Openwsman server plugins Klaus Kämpf  2 Motivation •

Outlook

• Documentation• Improve openwsman plugin API• Finish Python backend

Page 36: Scripting Openwsman server plugins - SUSE Linuxkkaempf/Presentations/MDC2008/openwsm… · Scripting Openwsman server plugins Klaus Kämpf  2 Motivation •

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

Page 37: Scripting Openwsman server plugins - SUSE Linuxkkaempf/Presentations/MDC2008/openwsm… · Scripting Openwsman server plugins Klaus Kämpf  2 Motivation •

Thank you !

Questions ?