-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathwsman-client.i
608 lines (571 loc) · 16.2 KB
/
wsman-client.i
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
/*
* wsman-client.i
*
* client declarations for openwsman swig bindings
*
*/
%rename(Client) _WsManClient;
%nodefault _WsManClient;
typedef struct _WsManClient {
} WsManClient;
/*
* Document-class: Client
*
* Instances of Client represent a connection to a client used for
* sending WS-Management operation requests.
*
*/
%extend _WsManClient {
/*
* Create a client connection.
*
* There are two ways to connect to a client, either by specifying a
* URL or by passing all client parameters separately
*
* call-seq:
* Client.new(uri)
* Client.new(host, port, path, scheme, username, password)
*
* Client.new("http://user:pass@host.domain.com:1234/path")
* Client.new("host.domain.com", 1234, "/path", "http", "user", "pass")
*
*/
_WsManClient( const char *uri ) {
struct _WsManClient *client = wsmc_create_from_uri( uri );
if (client == NULL)
SWIG_exception( SWIG_ValueError, "Can't create Openwsman::Client from given URI" );
#if defined(SWIGPYTHON) || defined(SWIGPERL) || defined(SWIGJAVA)
fail:
#endif
return client;
}
/*
* :nodoc:
*/
_WsManClient(const char *hostname,
const int port, const char *path,
const char *scheme,
const char *username,
const char *password) {
struct _WsManClient *client = wsmc_create( hostname, port, path, scheme, username, password );
if (client == NULL)
SWIG_exception( SWIG_ValueError, "Can't create Openwsman::Client from given values" );
#if defined(SWIGPYTHON) || defined(SWIGPERL) || defined(SWIGJAVA)
fail:
#endif
return client;
}
/* destructor */
~_WsManClient() {
wsmc_release( $self );
}
/* set dumpfile */
#if defined(SWIGRUBY)
%rename( "dumpfile=" ) set_dumpfile( FILE *f );
#endif
/*
* Set the dumpfile (for debugging) to dump xml requests
*
* call-seq:
* client.dumpfile = File.open(...)
*
*/
void set_dumpfile( FILE *f ) {
wsmc_set_dumpfile( $self, f );
}
/*
* Response code of the last request (HTTP response code)
*
* call-seq:
* client.reponse_code -> Integer
*
*/
long response_code() {
return wsmc_get_response_code( $self );
}
%newobject scheme;
/*
* String representation of the transport scheme
*
* call-seq:
* client.scheme -> String
*
*/
char *scheme() {
return wsmc_get_scheme( $self );
}
%newobject host;
/*
* The host part of the client URL
*
*/
char *host() {
return wsmc_get_hostname( $self );
}
/*
* The TCP port used in the connection
*
*/
int port() {
return wsmc_get_port( $self );
}
%newobject path;
/*
* The path of the clien URL
*
*/
char *path() {
return wsmc_get_path( $self );
}
%newobject user;
/*
* The user name used for authentication
*
*/
char *user() {
return wsmc_get_user( $self );
}
%newobject password;
/*
* The password used for authentication
*
*/
char *password() {
return wsmc_get_password( $self );
}
/*
* The Transport instance associated to the client
*/
WsManTransport *transport() {
wsmc_transport_init($self, NULL);
wsmc_transport_set_auth_request_func( $self, auth_request_callback );
return (WsManTransport *)$self;
}
/*
* Send a (raw) SOAP request to the client
*
* call-seq:
* client.send_request(XmlDoc.new("<xml ...>...</xml>")) -> Integer
*
*/
int send_request(WsXmlDocH request) {
return wsman_send_request($self, request);
}
/*
* Build envelope from response
*
* call-seq:
* client.build_envelope_from_response() -> XmlDoc
*
*/
WsXmlDocH build_envelope_from_response() {
return wsmc_build_envelope_from_response($self);
}
/*
* Get client encoding
*
* call-seq:
* client.encoding -> "utf-8"
*
*/
char *encoding() {
return wsmc_get_encoding($self);
}
#if defined(SWIGRUBY)
%rename( "encoding=" ) set_encoding( const char *encoding );
#endif
/*
* Set client encoding
*
* call-seq:
* client.encoding = "utf-8"
*
*/
void set_encoding(const char *encoding) {
wsmc_set_encoding($self, encoding);
}
/*-----------------------------------------------------------------*/
/* actions */
/*
* WS-Identify
*
* identify: Sends an identify request
*
* call-seq:
* client.identify(options) -> XmlDoc
*
*/
WsXmlDocH identify( client_opt_t *options ) {
#if RUBY_VERSION > 18 /* YARV */
wsmc_action_args_t args;
args.client = $self;
args.options = options;
#if RUBY_VERSION > 20 /* New threading model */
return (WsXmlDocH)rb_thread_call_without_gvl((void * (*)(void *))ruby_identify_thread, &args, RUBY_UBF_IO, 0);
#else
return (WsXmlDocH)rb_thread_blocking_region((rb_blocking_function_t*)ruby_identify_thread, &args, RUBY_UBF_IO, 0);
#endif
#else
return wsmc_action_identify( $self, options );
#endif
}
/*
* WS-Get
*
* get_from_epr: Get a resource via an endpoint reference
*
* call-seq:
* client.get_from_epr(options, end_point_reference) -> XmlDoc
*
*/
WsXmlDocH get_from_epr( client_opt_t *options , epr_t *epr) {
#if RUBY_VERSION > 18 /* YARV */
wsmc_action_args_t args;
args.client = $self;
args.options = options;
args.epr = epr;
#if RUBY_VERSION > 20 /* New threading model */
return (WsXmlDocH)rb_thread_call_without_gvl((void * (*)(void *))ruby_get_from_epr_thread, &args, RUBY_UBF_IO, 0);
#else
return (WsXmlDocH)rb_thread_blocking_region((rb_blocking_function_t*)ruby_get_from_epr_thread, &args, RUBY_UBF_IO, 0);
#endif
#else
return wsmc_action_get_from_epr( $self, epr, options);
#endif
}
/*
* WS-Delete
*
* delete_from_epr: Remove a resource via an endpoint reference
*
* call-seq:
* client.delete_from_epr(options, end_point_reference) -> XmlDoc
*
*/
WsXmlDocH delete_from_epr( client_opt_t *options , epr_t *epr) {
#if RUBY_VERSION > 18 /* YARV */
wsmc_action_args_t args;
args.client = $self;
args.options = options;
args.epr = epr;
#if RUBY_VERSION > 20 /* New threading model */
return (WsXmlDocH)rb_thread_call_without_gvl((void * (*)(void *))ruby_delete_from_epr_thread, &args, RUBY_UBF_IO, 0);
#else
return (WsXmlDocH)rb_thread_blocking_region((rb_blocking_function_t*)ruby_delete_from_epr_thread, &args, RUBY_UBF_IO, 0);
#endif
#else
return wsmc_action_delete_from_epr( $self, epr, options);
#endif
}
/*
* WS-Enumerate
*
* enumerate: List resources
*
* It is highly recommended to do an optimized enumeration by
* setting the client options
* options.flags = Openwsman::FLAG_ENUMERATION_OPTIMIZATION
* options.max_elements = 999
* to get the enumeration result as part of the http request.
*
* Otherwise separate pull requests are needed resulting in extra
* round-trips (client -> wsman -> cimom & back), dramatically
* affecting performance.
*
* call-seq:
* client.enumerate(options, filter, uri) -> XmlDoc
*
*/
WsXmlDocH enumerate( client_opt_t *options , filter_t *filter, char *resource_uri) {
#if RUBY_VERSION > 18 /* YARV */
wsmc_action_args_t args;
args.client = $self;
args.options = options;
args.filter = filter;
args.resource_uri = resource_uri;
#if RUBY_VERSION > 20 /* New threading model */
return (WsXmlDocH)rb_thread_call_without_gvl((void * (*)(void *))ruby_enumerate_thread, &args, RUBY_UBF_IO, 0);
#else
return (WsXmlDocH)rb_thread_blocking_region((rb_blocking_function_t*)ruby_enumerate_thread, &args, RUBY_UBF_IO, 0);
#endif
#else
return wsmc_action_enumerate( $self, resource_uri, options, filter);
#endif
}
/*
* WS-Transport
*
* pull: Get resources from enumeration context
*
* call-seq:
* client.pull(options, filter, uri, context) -> XmlDoc
*
*/
WsXmlDocH pull( client_opt_t *options , filter_t *filter, const char *resource_uri, const char *context) {
#if RUBY_VERSION > 18 /* YARV */
wsmc_action_args_t args;
args.client = $self;
args.options = options;
args.filter = filter;
args.resource_uri = resource_uri;
args.context = context;
#if RUBY_VERSION > 20 /* New threading model */
return (WsXmlDocH)rb_thread_call_without_gvl((void * (*)(void *))ruby_pull_thread, &args, RUBY_UBF_IO, 0);
#else
return (WsXmlDocH)rb_thread_blocking_region((rb_blocking_function_t*)ruby_pull_thread, &args, RUBY_UBF_IO, 0);
#endif
#else
return wsmc_action_pull( $self, resource_uri, options, filter, context);
#endif
}
/*
* WS-Create
*
* create: Create a resource
*
* call-seq:
* client.create(options, uri, xml, xml.size, "utf-8") -> XmlDoc
*
*/
WsXmlDocH create( client_opt_t *options, const char *resource_uri, const char *data, size_t size, const char *encoding = "utf-8") {
#if RUBY_VERSION > 18 /* YARV */
wsmc_action_args_t args;
args.client = $self;
args.options = options;
args.resource_uri = resource_uri;
args.data = data;
args.size = size;
args.encoding = encoding;
#if RUBY_VERSION > 20 /* New threading model */
return (WsXmlDocH)rb_thread_call_without_gvl((void * (*)(void *))ruby_create_fromtext_thread, &args, RUBY_UBF_IO, 0);
#else
return (WsXmlDocH)rb_thread_blocking_region((rb_blocking_function_t*)ruby_create_fromtext_thread, &args, RUBY_UBF_IO, 0);
#endif
#else
return wsmc_action_create_fromtext( $self, resource_uri, options, data, size, encoding);
#endif
}
/*
* WS-Transport
*
* put: Change a resource
*
* call-seq:
* client.put(options, uri, xml, xml.size, "utf-8") -> XmlDoc
*
*/
WsXmlDocH put( client_opt_t *options, const char *resource_uri, const char *data, size_t size, const char *encoding = "utf-8") {
#if RUBY_VERSION > 18 /* YARV */
wsmc_action_args_t args;
args.client = $self;
args.options = options;
args.resource_uri = resource_uri;
args.data = data;
args.size = size;
args.encoding = encoding;
#if RUBY_VERSION > 20 /* New threading model */
return (WsXmlDocH)rb_thread_call_without_gvl((void * (*)(void *))ruby_put_fromtext_thread, &args, RUBY_UBF_IO, 0);
#else
return (WsXmlDocH)rb_thread_blocking_region((rb_blocking_function_t*)ruby_put_fromtext_thread, &args, RUBY_UBF_IO, 0);
#endif
#else
return wsmc_action_put_fromtext( $self, resource_uri, options, data, size, encoding);
#endif
}
/*
* WS-Release
*
* release: Release enumeration context
*
* call-seq:
* client.release(options, uri, context) -> XmlDoc
*
*/
WsXmlDocH release( client_opt_t *options, const char *resource_uri, const char *context) {
#if RUBY_VERSION > 18 /* YARV */
wsmc_action_args_t args;
args.client = $self;
args.options = options;
args.resource_uri = resource_uri;
args.context = context;
#if RUBY_VERSION > 20 /* New threading model */
return (WsXmlDocH)rb_thread_call_without_gvl((void * (*)(void *))ruby_release_thread, &args, RUBY_UBF_IO, 0);
#else
return (WsXmlDocH)rb_thread_blocking_region((rb_blocking_function_t*)ruby_release_thread, &args, RUBY_UBF_IO, 0);
#endif
#else
return wsmc_action_release( $self, resource_uri, options, context);
#endif
}
/*
* WS-Transport
*
* get: Get a resource
*
* call-seq:
* client.get(options, uri) -> XmlDoc
*
*/
WsXmlDocH get( client_opt_t *options, const char *resource_uri) {
#if RUBY_VERSION > 18 /* YARV */
wsmc_action_args_t args;
args.client = $self;
args.options = options;
args.resource_uri = resource_uri;
#if RUBY_VERSION > 20 /* New threading model */
return (WsXmlDocH)rb_thread_call_without_gvl((void * (*)(void *))ruby_get_thread, &args, RUBY_UBF_IO, 0);
#else
return (WsXmlDocH)rb_thread_blocking_region((rb_blocking_function_t*)ruby_get_thread, &args, RUBY_UBF_IO, 0);
#endif
#else
return wsmc_action_get( $self, resource_uri, options);
#endif
}
/*
* WS-Transport
*
* delete: Delete a resource
*
* call-seq:
* client.delete(options, uri) -> XmlDoc
*
*/
WsXmlDocH delete( client_opt_t *options, const char *resource_uri) {
#if RUBY_VERSION > 18 /* YARV */
wsmc_action_args_t args;
args.client = $self;
args.options = options;
args.resource_uri = resource_uri;
#if RUBY_VERSION > 20 /* New threading model */
return (WsXmlDocH)rb_thread_call_without_gvl((void * (*)(void *))ruby_delete_thread, &args, RUBY_UBF_IO, 0);
#else
return (WsXmlDocH)rb_thread_blocking_region((rb_blocking_function_t*)ruby_delete_thread, &args, RUBY_UBF_IO, 0);
#endif
#else
return wsmc_action_delete( $self, resource_uri, options);
#endif
}
/*
* WS-Invoke
*
* invoke: Invoke a resource function
*
* call-seq:
* client.invoke(options, uri, "method-name") -> XmlDoc
* client.invoke(options, uri, "method-name", xml_doc) -> XmlDoc
*
*/
WsXmlDocH invoke( client_opt_t *options, const char *resource_uri, const char *method, WsXmlDocH data = NULL) {
#if RUBY_VERSION > 18 /* YARV */
wsmc_action_args_t args;
args.client = $self;
args.options = options;
args.resource_uri = resource_uri;
args.method = method;
args.method_args = data;
#if RUBY_VERSION > 20 /* New threading model */
return (WsXmlDocH)rb_thread_call_without_gvl((void * (*)(void *))ruby_invoke_thread, &args, RUBY_UBF_IO, 0);
#else
return (WsXmlDocH)rb_thread_blocking_region((rb_blocking_function_t*)ruby_invoke_thread, &args, RUBY_UBF_IO, 0);
#endif
#else
return wsmc_action_invoke( $self, resource_uri, options, method, data);
#endif
}
/*
* WS-Eventing
*
* subscribe: Subscribe a listener to events
*
* call-seq:
* client.subscribe(options, filter, uri) -> XmlDoc
*
*/
WsXmlDocH subscribe(client_opt_t *options, filter_t *filter, const char *resource_uri) {
#if RUBY_VERSION > 18 /* YARV */
wsmc_action_args_t args;
args.client = $self;
args.options = options;
args.filter = filter;
args.resource_uri = resource_uri;
#if RUBY_VERSION > 20 /* New threading model */
return (WsXmlDocH)rb_thread_call_without_gvl((void * (*)(void *))ruby_subscribe_thread, &args, RUBY_UBF_IO, 0);
#else
return (WsXmlDocH)rb_thread_blocking_region((rb_blocking_function_t*)ruby_subscribe_thread, &args, RUBY_UBF_IO, 0);
#endif
#else
return wsmc_action_subscribe($self, resource_uri, options, filter);
#endif
}
/*
* WS-Eventing
*
* unsubscribe: Remove a listener from events
*
* call-seq:
* client.unsubscribe(options, filter, uri, identifier) -> XmlDoc
*
*/
WsXmlDocH unsubscribe(client_opt_t *options, filter_t *filter, const char *resource_uri, const char *identifier) {
#if RUBY_VERSION > 18 /* YARV */
wsmc_action_args_t args;
args.client = $self;
args.options = options;
args.filter = filter;
args.resource_uri = resource_uri;
args.identifier = identifier;
#if RUBY_VERSION > 20 /* New threading model */
return (WsXmlDocH)rb_thread_call_without_gvl((void * (*)(void *))ruby_unsubscribe_thread, &args, RUBY_UBF_IO, 0);
#else
return (WsXmlDocH)rb_thread_blocking_region((rb_blocking_function_t*)ruby_unsubscribe_thread, &args, RUBY_UBF_IO, 0);
#endif
#else
return wsmc_action_unsubscribe($self, resource_uri, options, identifier);
#endif
}
/*
* WS-Eventing
*
* renew: Renew a subscription
*
* call-seq:
* client.renew(options, uri, identifier) -> XmlDoc
*
*/
WsXmlDocH renew(client_opt_t *options , char *resource_uri, char *identifier) {
#if RUBY_VERSION > 18 /* YARV */
wsmc_action_args_t args;
args.client = $self;
args.options = options;
args.resource_uri = resource_uri;
args.identifier = identifier;
#if RUBY_VERSION > 20 /* New threading model */
return (WsXmlDocH)rb_thread_call_without_gvl((void * (*)(void *))ruby_renew_thread, &args, RUBY_UBF_IO, 0);
#else
return (WsXmlDocH)rb_thread_blocking_region((rb_blocking_function_t*)ruby_renew_thread, &args, RUBY_UBF_IO, 0);
#endif
#else
return wsmc_action_renew($self, resource_uri, options, identifier);
#endif
}
/*
* Get a string representation of the last fault
*
* call-seq:
* client.fault_string -> String
*
*/
char *fault_string() {
return wsmc_get_fault_string($self);
}
/*
* Get a numeric representation of the last fault
*
* call-seq:
* client.last_error -> Integer
*
*/
int last_error() {
return wsmc_get_last_error($self);
}
}