/
xmlrpcClient.py
1483 lines (1339 loc) · 49.8 KB
/
xmlrpcClient.py
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
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from __future__ import print_function
import socket
import sys
socket.setdefaulttimeout(180)
kwargs = {}
try:
import ssl
kwargs["context"] = ssl._create_unverified_context()
except:
pass
try:
import xmlrpclib
except ImportError:
import xmlrpc.client as xmlrpclib
try:
import httplib
except ImportError:
import http.client as httplib
def get_proxy(uri):
try:
return xmlrpclib.ServerProxy(uri, **kwargs)
except Exception as e:
if "__init__" in str(e):
return xmlrpclib.ServerProxy(uri)
from datetime import datetime, timedelta
import time
import random
import os
import sys
from rcGlobalEnv import rcEnv
import rcStatus
import rcExceptions as ex
rcEnv.warned = False
import logging
import logging.handlers
logfile = os.path.join(rcEnv.paths.pathlog, 'xmlrpc.log')
log = logging.getLogger("xmlrpc")
log.setLevel(logging.INFO)
try:
fileformatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
filehandler = logging.handlers.RotatingFileHandler(os.path.join(logfile),
maxBytes=5242880,
backupCount=5)
filehandler.setFormatter(fileformatter)
log.addHandler(filehandler)
except Exception as e:
pass
try:
if sys.version_info[0] >= 3:
from multiprocessing import queue as Queue, Process
else:
from multiprocessing import Queue, Process
from Queue import Empty
if rcEnv.sysname == 'Windows':
from multiprocessing import set_executable
set_executable(os.path.join(sys.exec_prefix, 'pythonw.exe'))
mp = True
except:
mp = False
def do_call(fn, args, kwargs, log, proxy, mode="synchronous"):
tries = 5
for i in range(tries):
try:
return _do_call(fn, args, kwargs, log, proxy, mode=mode)
except Exception as e:
s = str(e)
if "retry" in s:
# db table changed. retry immediately
max_wait = 0
elif "restart" in s or "Gateway" in s:
# collector overload issues, retry after a random delay
max_wait = 3
else:
# no need to retry at all there, unknown cause
raise
if max_wait > 0:
time.sleep(random.random()*max_wait)
log.warning("retry call %s on error %s" % (fn, str(e)))
log.error("failed to call %s after %d tries" % (fn, tries))
def _do_call(fn, args, kwargs, log, proxy, mode="synchronous"):
log.info("call remote function %s in %s mode"%(fn, mode))
try:
_b = datetime.now()
buff = getattr(proxy, fn)(*args, **kwargs)
_e = datetime.now()
_d = _e - _b
log.info("call %s done in %d.%03d seconds"%(fn, _d.seconds, _d.microseconds//1000))
return buff
except Exception as e:
_e = datetime.now()
_d = _e - _b
log.exception("call %s error after %d.%03d seconds"%(fn, _d.seconds, _d.microseconds//1000))
def call_worker(q, node):
e = "foo"
o = Collector(worker=True, node=node)
o.init()
try:
while e is not None:
e = q.get()
if e is None:
break
fn, args, kwargs = e
do_call(fn, args, kwargs, o.log, o.proxy, mode="asynchronous")
o.log.info("shutdown")
except ex.excSignal:
o.log.info("interrupted on signal")
class Collector(object):
def submit(self, fn, *args, **kwargs):
self.init_worker()
self.log.info("enqueue %s"%fn)
self.queue.put((fn, args, kwargs), block=True)
def call(self, *args, **kwargs):
fn = args[0]
self.init(fn)
if rcEnv.dbopensvc is None:
return {"ret": 1, "msg": "no collector defined. set 'dbopensvc' in node.conf"}
if len(self.proxy_methods) == 0:
return
if len(args) > 1:
args = args[1:]
else:
args = []
if fn == "register_node" and \
'register_node' not in self.proxy_methods:
print("collector does not support node registration", file=sys.stderr)
return
if rcEnv.uuid == "" and \
rcEnv.dbopensvc is not None and \
not rcEnv.warned and \
self.auth_node and \
fn != "register_node":
print("this node is not registered. try 'nodemgr register'", file=sys.stderr)
print("to disable this warning, set 'dbopensvc = None' in node.conf", file=sys.stderr)
rcEnv.warned = True
return
return do_call(fn, args, kwargs, self.log, self, mode="synchronous")
def __init__(self, worker=False, node=None):
self.node = node
self.proxy = None
self.proxy_methods = []
self.comp_proxy = None
self.comp_proxy_methods = []
self._worker = worker
self.worker = None
self.queue = None
self.comp_fns = ['comp_get_data_moduleset',
'comp_get_svc_data_moduleset',
'comp_get_data',
'comp_get_svc_data',
'comp_attach_moduleset',
'comp_attach_svc_moduleset',
'comp_detach_moduleset',
'comp_detach_svc_moduleset',
'comp_get_ruleset',
'comp_get_svc_ruleset',
'comp_get_ruleset_md5',
'comp_attach_ruleset',
'comp_attach_svc_ruleset',
'comp_detach_ruleset',
'comp_detach_svc_ruleset',
'comp_list_ruleset',
'comp_list_moduleset',
'comp_show_status',
'comp_log_actions']
self.auth_node = True
self.log = logging.getLogger("xmlrpc%s"%('.worker' if worker else ''))
def get_methods_dbopensvc(self):
if rcEnv.dbopensvc is None:
self.proxy_methods = []
return
self.log.debug("get dbopensvc method list")
try:
if self.proxy is None:
self.proxy = get_proxy(rcEnv.dbopensvc)
self.proxy_methods = self.proxy.system.listMethods()
except Exception as e:
self.log.error(str(e))
self.proxy = get_proxy("https://127.0.0.1/")
self.proxy_methods = []
self.log.debug("%d feed methods"%len(self.proxy_methods))
def get_methods_dbcompliance(self):
if rcEnv.dbcompliance is None:
self.comp_proxy_methods = []
return
self.log.debug("get dbcompliance method list")
try:
if self.comp_proxy is None:
self.comp_proxy = get_proxy(rcEnv.dbcompliance)
self.comp_proxy_methods = self.comp_proxy.system.listMethods()
except Exception as e:
self.log.error(str(e))
self.comp_proxy = get_proxy("https://127.0.0.1/")
self.comp_proxy_methods = []
self.log.debug("%d compliance methods"%len(self.comp_proxy_methods))
def init(self, fn=None):
if fn is not None:
if fn in self.comp_fns:
if self.comp_proxy is not None:
return
elif self.proxy is not None:
return
if rcEnv.dbopensvc is None:
return
try:
a = socket.getaddrinfo(rcEnv.dbopensvc_host, None)
if len(a) == 0:
raise Exception
dbopensvc_ip = a[0][-1][0]
except:
self.log.error("could not resolve %s to an ip address. disable collector updates."%rcEnv.dbopensvc_host)
try:
a = socket.getaddrinfo(rcEnv.dbcompliance_host, None)
if len(a) == 0:
raise Exception
dbcompliance_ip = a[0][-1][0]
except Exception as e:
self.log.error(str(e))
self.log.error("could not resolve %s to an ip address. disable collector updates."%rcEnv.dbcompliance_host)
try:
self.proxy = get_proxy(rcEnv.dbopensvc)
self.get_methods_dbopensvc()
except Exception as e:
self.log.error(str(e))
self.proxy = get_proxy("https://127.0.0.1/")
if fn in self.comp_fns:
try:
self.comp_proxy = get_proxy(rcEnv.dbcompliance)
self.get_methods_dbcompliance()
except:
self.comp_proxy = get_proxy("https://127.0.0.1/")
self.log.info("feed proxy %s"%str(self.proxy))
self.log.info("compliance proxy %s"%str(self.comp_proxy))
if "register_node" not in self.proxy_methods:
self.auth_node = False
def stop_worker(self):
if self.queue is None:
self.log.debug("worker already stopped (queue is None)")
return
if self.worker is None:
self.log.debug("worker already stopped (worker is None)")
return
try:
if not self.worker.is_alive():
self.log.debug("worker already stopped (not alive)")
return
except AssertionError:
self.log.error("don't stop worker (not a child of this process)")
return
self.log.debug("give poison pill to worker")
self.queue.put(None)
self.worker.join()
self.queue = None
self.worker = None
def init_worker(self):
if self._worker:
return
if self.worker is not None:
return
try:
self.queue = Queue()
except Exception as e:
self.log.error("Queue not supported. disable async mode. %s" % str(e))
self.queue = None
return
self.worker = Process(target=call_worker, name="xmlrpc", args=(self.queue, self.node))
self.worker.start()
self.log.info("worker started")
def begin_action(self, svc, action, begin, sync=True):
args = [['svcname',
'action',
'hostname',
'version',
'begin',
'cron'],
[str(svc.svcname),
str(action),
str(rcEnv.nodename),
str(svc.node.agent_version()),
str(begin),
'1' if svc.options.cron else '0']
]
if self.auth_node:
args += [(rcEnv.uuid, rcEnv.nodename)]
if sync or not mp:
self.proxy.begin_action(*args)
else:
self.submit("begin_action", *args)
def end_action(self, svc, action, begin, end, alogfile, sync=True):
err = 'ok'
dateprev = None
res = None
res_err = None
pid = None
msg = None
lines = open(alogfile, 'r').read()
pids = set()
"""Example logfile line:
2009-11-11 01:03:25,252;;DISK.VG;;INFO;;unxtstsvc01_data is already up;;10200;;EOL
"""
vars = ['svcname',
'action',
'hostname',
'pid',
'begin',
'end',
'status_log',
'status',
'cron']
vals = []
for line in lines.split(';;EOL\n'):
if line.count(';;') != 4:
continue
if ";;status_history;;" in line:
continue
date = line.split(';;')[0]
"""Push to database the previous line, so that begin and end
date are available.
"""
if res is not None and dateprev is not None:
res = res.lower()
res = res.replace(rcEnv.nodename+'.'+svc.svcname+'.','')
vals.append([svc.svcname,
res+' '+action,
rcEnv.nodename,
pid,
dateprev,
date,
msg,
res_err,
'1' if svc.options.cron else '0'])
res_err = 'ok'
(date, res, lvl, msg, pid) = line.split(';;')
# database overflow protection
trim_lim = 10000
trim_tag = ' <trimmed> '
trim_head = trim_lim // 2
trim_tail = trim_head-len(trim_tag)
if len(msg) > trim_lim:
msg = msg[:trim_head]+' <trimmed> '+msg[-trim_tail:]
pids |= set([pid])
if lvl is None or lvl == 'DEBUG':
continue
if lvl == 'ERROR':
err = 'err'
res_err = 'err'
if lvl == 'WARNING' and err != 'err':
err = 'warn'
if lvl == 'WARNING' and res_err != 'err':
res_err = 'warn'
dateprev = date
"""Push the last log entry, using 'end' as end date
"""
if dateprev is not None:
res = res.lower()
res = res.replace(rcEnv.nodename+'.'+svc.svcname+'.','')
vals.append([svc.svcname,
res+' '+action,
rcEnv.nodename,
pid,
dateprev,
date,
msg,
res_err,
'1' if svc.options.cron else '0'])
if len(vals) > 0:
args = [vars, vals]
if self.auth_node:
args += [(rcEnv.uuid, rcEnv.nodename)]
if sync or not mp:
self.proxy.res_action_batch(*args)
else:
self.submit("res_action_batch", *args)
"""Complete the wrap-up database entry
"""
""" If logfile is empty, default to current process pid
"""
if len(pids) == 0:
pids = set([os.getpid()])
args = [
['svcname',
'action',
'hostname',
'pid',
'begin',
'end',
'time',
'status',
'cron'],
[str(svc.svcname),
str(action),
str(rcEnv.nodename),
','.join(map(str, pids)),
str(begin),
str(end),
str(end-begin),
str(err),
'1' if svc.options.cron else '0']
]
if self.auth_node:
args += [(rcEnv.uuid, rcEnv.nodename)]
if sync or not mp:
self.proxy.end_action(*args)
else:
self.submit("end_action", *args)
def svcmon_update_combo(self, g_vars, g_vals, r_vars, r_vals, sync=True):
if 'svcmon_update_combo' in self.proxy_methods:
args = [g_vars, g_vals, r_vars, r_vals]
if self.auth_node:
args += [(rcEnv.uuid, rcEnv.nodename)]
if sync or not mp:
self.proxy.svcmon_update_combo(*args)
else:
self.submit("svcmon_update_combo", *args)
else:
args = [g_vars, g_vals]
if self.auth_node:
args += [(rcEnv.uuid, rcEnv.nodename)]
if sync or not mp:
self.proxy.svcmon_update(*args)
else:
self.submit("svcmon_update", *args)
args = [r_vars, r_vals]
if self.auth_node:
args += [(rcEnv.uuid, rcEnv.nodename)]
if sync or not mp:
self.proxy.resmon_update(*args)
else:
self.submit("resmon_update", *args)
def _push_resinfo(self, svc, sync=True):
if 'update_resinfo' not in self.proxy_methods:
return
vars = ['res_svcname',
'res_nodename',
'topology',
'rid',
'res_key',
'res_value']
vals = []
for r in svc.get_resources():
l = [
["driver", r.type],
["standby", str(r.standby).lower()],
["optional", str(r.optional).lower()],
["disabled", str(r.disabled).lower()],
["monitor", str(r.monitor).lower()],
["shared", str(r.shared).lower()],
["encap", str(r.encap).lower()],
["restart", str(r.nb_restart)],
]
if r.subset:
l.append(["subset", r.subset])
if len(r.tags) > 0:
l.append(["tags", " ".join(r.tags)])
vals += r.fmt_info(l)
if not hasattr(r, "info"):
continue
try:
vals += r.info()
except Exception as e:
print(e, file=sys.stderr)
if len(vals) == 0:
return
for val in vals:
try:
print("%-16s %-20s %s"%(val[3], val[4], val[5]))
except Exception as e:
print(e, val, file=sys.stderr)
args = [vars, vals]
if self.auth_node:
args += [(rcEnv.uuid, rcEnv.nodename)]
self.proxy.update_resinfo(*args)
def push_config(self, svc, sync=True):
def repr_config(svc):
import codecs
if not os.path.exists(svc.paths.cf):
return
with codecs.open(svc.paths.cf, 'r', encoding="utf8") as f:
buff = f.read()
return buff
return
vars = ['svc_name',
'svc_topology',
'svc_flex_min_nodes',
'svc_flex_max_nodes',
'svc_flex_cpu_low_threshold',
'svc_flex_cpu_high_threshold',
'svc_env',
'svc_nodes',
'svc_drpnode',
'svc_drpnodes',
'svc_comment',
'svc_app',
'svc_config',
'svc_ha']
vals = [svc.svcname,
svc.topology,
svc.flex_min_nodes,
svc.flex_max_nodes,
svc.flex_cpu_low_threshold,
svc.flex_cpu_high_threshold,
svc.svc_env,
' '.join(svc.nodes),
svc.drpnode,
' '.join(svc.drpnodes),
svc.comment,
svc.app,
repr_config(svc),
'1' if svc.ha else '0']
args = [vars, vals]
if self.auth_node:
args += [(rcEnv.uuid, rcEnv.nodename)]
self.proxy.update_service(*args)
def push_containerinfo(self, svc, sync=True):
vars = ['mon_svcname',
'mon_nodname',
'mon_vmname',
'mon_guestos',
'mon_vmem',
'mon_vcpus',
'mon_containerpath']
vals = []
for container in svc.get_resources('container'):
container_info = container.get_container_info()
vals += [[svc.svcname,
rcEnv.nodename,
container.vm_hostname,
container.guestos if hasattr(container, 'guestos') and container.guestos is not None else "",
container_info['vmem'],
container_info['vcpus'],
container.zonepath if hasattr(container, 'zonepath') else ""]]
if len(vals) > 0:
args = [vars, vals]
if self.auth_node:
args += [(rcEnv.uuid, rcEnv.nodename)]
self.proxy.svcmon_update(*args)
def push_disks(self, data, sync=True):
vars = ['disk_id',
'disk_svcname',
'disk_size',
'disk_used',
'disk_vendor',
'disk_model',
'disk_dg',
'disk_nodename',
'disk_region']
vals = []
served_disks = []
for disk_id, disk in data["disks"].items():
for svcname, service in disk["services"].items():
vals.append([
disk_id,
svcname,
disk["size"],
service["used"],
disk["vendor"],
disk["model"],
service["dg"],
rcEnv.nodename,
service["region"],
])
if disk["used"] < disk["size"]:
vals.append([
disk_id,
"",
disk["size"],
disk["size"] - disk["used"],
disk["vendor"],
disk["model"],
"",
rcEnv.nodename,
0,
])
args = [vars, vals]
if self.auth_node:
args += [(rcEnv.uuid, rcEnv.nodename)]
self.proxy.register_disks(*args)
#
# register disks this node provides to its VM
#
vars = ['disk_id',
'disk_arrayid',
'disk_devid',
'disk_size',
'disk_raid',
'disk_group']
vals = []
for disk_id, disk in data["served_disks"].items():
vals.append([
disk["vdisk_id"],
disk["cluster"],
disk_id,
disk["size"],
"virtual",
"virtual"
])
args = [vars, vals]
if self.auth_node:
args += [(rcEnv.uuid, rcEnv.nodename)]
self.proxy.register_diskinfo(*args)
def push_stats_fs_u(self, l, sync=True):
args = [l[0], l[1]]
if self.auth_node:
args += [(rcEnv.uuid, rcEnv.nodename)]
self.proxy.insert_stats_fs_u(*args)
def push_pkg(self, sync=True):
p = __import__('rcPkg'+rcEnv.sysname)
vars = ['pkg_nodename',
'pkg_name',
'pkg_version',
'pkg_arch']
vals = p.listpkg()
n = len(vals)
if n == 0:
print("No package found. Skip push.")
return
else:
print("Pushing %d packages information."%n)
if len(vals[0]) >= 5:
vars.append('pkg_type')
if len(vals[0]) >= 6:
vars.append('pkg_install_date')
if len(vals[0]) >= 7:
vars.append('pkg_sig')
args = [rcEnv.nodename]
if self.auth_node:
args += [(rcEnv.uuid, rcEnv.nodename)]
args = [vars, vals]
if self.auth_node:
args += [(rcEnv.uuid, rcEnv.nodename)]
self.proxy.insert_pkg(*args)
def push_patch(self, sync=True):
p = __import__('rcPkg'+rcEnv.sysname)
vars = ['patch_nodename',
'patch_num',
'patch_rev']
vals = p.listpatch()
if len(vals) == 0:
return
if len(vals[0]) == 4:
vars.append('patch_install_date')
args = [rcEnv.nodename]
if self.auth_node:
args += [(rcEnv.uuid, rcEnv.nodename)]
args = [vars, vals]
if self.auth_node:
args += [(rcEnv.uuid, rcEnv.nodename)]
self.proxy.insert_patch(*args)
def push_stats(self, interval=None, stats_dir=None,
stats_start=None, stats_end=None, sync=True, disable=None):
try:
s = __import__('rcStats'+rcEnv.sysname)
except ImportError:
return
try:
sp = s.StatsProvider(interval=interval,
stats_dir=stats_dir,
stats_start=stats_start,
stats_end=stats_end)
except ValueError as e:
print(str(e))
return 1
except Exception as e:
print(e)
raise
h = {}
for stat in ['cpu', 'mem_u', 'proc', 'swap', 'block',
'blockdev', 'netdev', 'netdev_err', 'svc', 'fs_u']:
if disable is not None and stat in disable:
print("%s collection is disabled in node configuration"%stat)
continue
h[stat] = sp.get(stat)
print("%s stats: %d samples" % (stat, len(h[stat][1])))
import json
args = [json.dumps(h)]
if self.auth_node:
args += [(rcEnv.uuid, rcEnv.nodename)]
print("pushing")
self.proxy.insert_stats(*args)
def sysreport_lstree(self, sync=True):
args = []
if self.auth_node:
args += [(rcEnv.uuid, rcEnv.nodename)]
data = self.proxy.sysreport_lstree(*args)
return data
def send_sysreport(self, fpath, deleted, sync=True):
args = []
if fpath is None:
args += ["", ""]
else:
with open(fpath, 'rb') as f:
binary = xmlrpclib.Binary(f.read())
args = [os.path.basename(fpath), binary]
print("archive length:", len(binary.data))
args += [deleted]
if self.auth_node:
args += [(rcEnv.uuid, rcEnv.nodename)]
self.proxy.send_sysreport(*args)
def push_asset(self, node, data=None, sync=True):
if "update_asset" not in self.proxy_methods:
print("'update_asset' method is not exported by the collector")
return
d = dict(data)
gen = {}
if 'hba' in d:
vars = ['nodename', 'hba_id', 'hba_type']
vals = [(rcEnv.nodename, _d["hba_id"], _d["tgt_type"]) for _d in d['hba']]
del(d['hba'])
gen.update({'hba': [vars, vals]})
if 'targets' in d:
vars = ['hba_id', 'tgt_id']
vals = [(_d["hba_id"], _d["tgt_id"]) for _d in d['targets']]
del(d['targets'])
gen.update({'targets': [vars, vals]})
if 'lan' in d:
vars = ['mac', 'intf', 'type', 'addr', 'mask', 'flag_deprecated']
vals = []
for mac, l in d['lan'].items():
for _d in l:
vals.append([mac, _d['intf'], _d['type'], _d['addr'], _d['mask'], _d['flag_deprecated']])
del(d['lan'])
gen.update({'lan': [vars, vals]})
if 'uids' in d:
vars = ['user_name', 'user_id']
vals = [(_d["username"], _d["uid"]) for _d in d['uids']]
del(d['uids'])
gen.update({'uids': [vars, vals]})
if 'gids' in d:
vars = ['group_name', 'group_id']
vals = [(_d["groupname"], _d["gid"]) for _d in d['gids']]
del(d['gids'])
gen.update({'gids': [vars, vals]})
if len(gen) > 0:
args = [gen]
if self.auth_node:
args += [(rcEnv.uuid, rcEnv.nodename)]
self.proxy.insert_generic(*args)
_vars = []
_vals = []
for key, _d in d.items():
_vars.append(key)
if _d["value"] is None:
_d["value"] = ""
_vals.append(_d["value"])
args = [_vars, _vals]
if self.auth_node:
args += [(rcEnv.uuid, rcEnv.nodename)]
if node.options.syncrpc:
self.proxy.update_asset_sync(*args)
else:
self.proxy.update_asset(*args)
def daemon_ping(self, sync=True):
args = [(rcEnv.uuid, rcEnv.nodename)]
self.proxy.daemon_ping(*args)
def push_daemon_status(self, data, changes=None, sync=True):
import json
args = [json.dumps(data), json.dumps(changes), (rcEnv.uuid, rcEnv.nodename)]
self.proxy.push_daemon_status(*args)
def push_brocade(self, objects=[], sync=True):
if 'update_brocade' not in self.proxy_methods:
print("'update_brocade' method is not exported by the collector")
return
m = __import__('rcBrocade')
try:
brocades = m.Brocades(objects)
except:
return
for brocade in brocades:
vals = []
for key in brocade.keys:
try:
vals.append(getattr(brocade, 'get_'+key)())
except:
print("error fetching", key)
continue
args = [brocade.name, brocade.keys, vals]
if self.auth_node:
args += [(rcEnv.uuid, rcEnv.nodename)]
self.proxy.update_brocade(*args)
def push_vioserver(self, objects=[], sync=True):
if 'update_vioserver' not in self.proxy_methods:
print("'update_vioserver' method is not exported by the collector")
return
m = __import__('rcVioServer')
try:
vioservers = m.VioServers(objects)
except:
return
for vioserver in vioservers:
vals = []
for key in vioserver.keys:
vals.append(getattr(vioserver, 'get_'+key)())
args = [vioserver.name, vioserver.keys, vals]
if self.auth_node:
args += [(rcEnv.uuid, rcEnv.nodename)]
self.proxy.update_vioserver(*args)
def push_hds(self, objects=[], sync=True):
if 'update_hds' not in self.proxy_methods:
print("'update_hds' method is not exported by the collector")
return
m = __import__('rcHds')
try:
hdss = m.Arrays(objects)
except Exception as e:
print(e, file=sys.stderr)
return
for hds in hdss:
vals = []
for key in hds.keys:
vals.append(getattr(hds, 'get_'+key)())
args = [hds.name, hds.keys, vals]
if self.auth_node:
args += [(rcEnv.uuid, rcEnv.nodename)]
self.proxy.update_hds(*args)
def push_necism(self, objects=[], sync=True):
if 'update_necism' not in self.proxy_methods:
print("'update_necism' method is not exported by the collector")
return
m = __import__('rcNecIsm')
try:
necisms = m.NecIsms(objects)
except:
return
for necism in necisms:
vals = []
for key in necism.keys:
vals.append(getattr(necism, 'get_'+key)())
args = [necism.name, necism.keys, vals]
if self.auth_node:
args += [(rcEnv.uuid, rcEnv.nodename)]
self.proxy.update_necism(*args)
def push_hp3par(self, objects=[], sync=True):
if 'update_hp3par' not in self.proxy_methods:
print("'update_hp3par' method is not exported by the collector")
return
m = __import__('rcHp3par')
try:
hp3pars = m.Hp3pars(objects)
except:
return
for hp3par in hp3pars:
vals = []
for key in hp3par.keys:
vals.append(getattr(hp3par, 'get_'+key)())
args = [hp3par.name, hp3par.keys, vals]
if self.auth_node:
args += [(rcEnv.uuid, rcEnv.nodename)]
self.proxy.update_hp3par(*args)
def push_centera(self, objects=[], sync=True):
if 'update_centera' not in self.proxy_methods:
print("'update_centera' method is not exported by the collector")
return
m = __import__('rcCentera')
try:
centeras = m.Centeras(objects)
except:
return
for centera in centeras:
vals = []
print(centera.name)
for key in centera.keys:
print(" extract", key)
vals.append(getattr(centera, 'get_'+key)())
args = [centera.name, [k+".xml" for k in centera.keys], vals]
if self.auth_node:
args += [(rcEnv.uuid, rcEnv.nodename)]
self.proxy.update_centera(*args)
def push_emcvnx(self, objects=[], sync=True):
if 'update_emcvnx' not in self.proxy_methods:
print("'update_emcvnx' method is not exported by the collector")
return
m = __import__('rcEmcVnx')
try:
emcvnxs = m.EmcVnxs(objects)
except:
return
for emcvnx in emcvnxs:
vals = []
print(emcvnx.name)
for key in emcvnx.keys:
print(" extract", key)
vals.append(getattr(emcvnx, 'get_'+key)())
args = [emcvnx.name, emcvnx.keys, vals]
if self.auth_node:
args += [(rcEnv.uuid, rcEnv.nodename)]
self.proxy.update_emcvnx(*args)
def push_netapp(self, objects=[], sync=True):
if 'update_netapp' not in self.proxy_methods:
print("'update_netapp' method is not exported by the collector")
return
m = __import__('rcNetapp')
try:
netapps = m.Netapps(objects)
except:
return
for netapp in netapps:
vals = []
print(netapp.name)
for key in netapp.keys:
print(" extract", key)
vals.append(getattr(netapp, 'get_'+key)())
args = [netapp.name, netapp.keys, vals]
if self.auth_node:
args += [(rcEnv.uuid, rcEnv.nodename)]
self.proxy.update_netapp(*args)
def push_ibmsvc(self, objects=[], sync=True):
if 'update_ibmsvc' not in self.proxy_methods:
print("'update_ibmsvc' method is not exported by the collector")
return
m = __import__('rcIbmSvc')
try:
ibmsvcs = m.IbmSvcs(objects)
except: