-
Notifications
You must be signed in to change notification settings - Fork 49
/
cbact
executable file
·738 lines (617 loc) · 30.9 KB
/
cbact
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
#!/usr/bin/env python3
#/*******************************************************************************
# Copyright (c) 2012 IBM Corp.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#/*******************************************************************************
from logging import getLogger, StreamHandler, Formatter, Filter, DEBUG, ERROR, \
INFO, WARN, CRITICAL
from lib.auxiliary.code_instrumentation import VerbosityFilter, MsgFilter
from logging.handlers import logging, SysLogHandler, RotatingFileHandler
from optparse import OptionParser
from time import sleep, time
from os import getuid, environ
from pwd import getpwuid
from subprocess import Popen, PIPE
from random import randint
from uuid import uuid5, NAMESPACE_DNS
from sys import stdout, path
import sys
import os
import signal
import threading
import socket
from lib.operations.active_operations import ActiveObjectOperations
from lib.operations.passive_operations import PassiveObjectOperations
from lib.auxiliary.code_instrumentation import cbdebug, cberr, cbwarn, cbinfo, cbcrit, ReconnectingNewlineSysLogHandler
from lib.auxiliary.data_ops import str2dic, dic2str
from lib.stores.redis_datastore_adapter import RedisMgdConn
from lib.stores.stores_initial_setup import load_metricstore_adapter
from daemon import DaemonContext
def actuator_cli_parsing() :
# Do command line parsing
usage = '''usage: %prog [options]
'''
parser = OptionParser(usage)
parser.add_option("-d", "--debug_host", dest = "debug_host", metavar = "<ip address>", \
default = None, \
help = "Point CloudBench to a remote debugger")
# Process options
parser.add_option("--procid", dest = "procid", metavar = "procid", \
default = "TEST_" + getpwuid(getuid())[0], \
help = "Set the process id")
# Parameters
parser.add_option("--osp", dest = "osp", metavar = "OSP", \
default = None, \
help ="Set Object Store Parameters")
parser.add_option("--cn", dest = "cn", metavar = "CN", \
default = None, \
help ="Set the Cloud name")
parser.add_option("--operation", dest = "operation", metavar = "OP", \
default = None, \
help ="Set the Operation")
parser.add_option("--oop", dest = "oop", metavar = "OOP", \
default = None, \
help ="Set Object Operations Parameters")
parser.add_option("--uuid", dest = "ouuid", metavar = "OUUID", \
default = None, help ="Set Object UUID")
parser.add_option("--logdest", dest = "logdest", metavar = "LOGDEST", \
default = None, help ="Alter default logging behavior")
parser.add_option("--syslogp", dest = "syslogp", metavar = "SYSLOGP", \
default = None, \
help ="Set syslog port")
parser.add_option("--syslogh", dest = "syslogh", metavar = "SYSLOGH", \
default = None, \
help ="Set syslog hostname")
parser.add_option("--syslogr", dest = "syslogr", metavar = "SYSLOGR", \
default = 'UDP', \
help ="Set syslog protocol")
parser.add_option("--syslogf", dest = "syslogf", metavar = "SYSLOGF", \
default = None, \
help ="Set syslog facility")
parser.add_option("-k", "--keepsession", dest = "keepsession", action = "store_true", \
default = False, help = "Keep previous server session")
parser.add_option('--guiport', default='8080', dest='guiport', \
help='GUI Port to serve on (default 8080)')
parser.add_option('--guisslcert', default=False, dest='guisslcert', \
help='GUI Certificate for HTTPS (default none)')
parser.add_option('--guisslkey', default=False, dest='guisslkey', \
help='GUI Private key for HTTPS (default none)')
parser.add_option('--guihost', default='0.0.0.0', dest='guihost', \
help='GUI hostname to which to bind (default 0.0.0.0)')
parser.add_option('--guibranding', default='favicon.ico,20,http://localhost', \
dest='guibranding', \
help='What icon to use in the UI for company branding relative to the gui_files source directory')
parser.add_option('--apiport', default='7070', dest='apiport', \
help='GUI Port to serve on (default 7070)')
parser.add_option('--apihost', default='127.0.0.1', dest='apihost', \
help='GUI hostname to which to bind (default 127.0.0.1)')
parser.add_option("-D", "--daemon", dest = "daemon", action = "store_true", \
default = False, \
help ="Execute operation in daemonized mode")
# Verbosity Options
parser.add_option("-v", "--verbosity", dest = "verbosity", metavar = "LV", \
default = -1, help = "Set verbosity level.")
parser.add_option("-q", dest = "quiet", action = "store_true", \
help = "Set quiet output.")
parser.set_defaults()
(_options, _args) = parser.parse_args()
if _options.debug_host is not None :
try :
import debug
print(str(sys.path))
import pydevd
pydevd.settrace(host=_options.debug_host)
except ImportError as msg :
cbwarn("Failed to import debug file for remote debugging: " + str(msg), True)
_options.debug_host = None
pass
try :
_fmsg = ""
_home = environ["HOME"]
_from_file = False
_fn = _home + "/cb_os_parameters.txt"
_fh = open(_fn, "r")
_fc = _fh.readlines()
_fh.close()
_options.osp = ''
for _line in _fc :
_line = _line.strip()
if _line.count("#OSKN-") :
_options.osp += "kind:" + _line[6:] + ','
elif _line.count("#OSHN-") :
_options.osp += "host:" + _line[6:] + ','
elif _line.count("#OSPN-") :
_options.osp += "port:" + _line[6:] + ','
elif _line.count("#OSDN-") :
_options.osp += "dbid:" + _line[6:] + ','
elif _line.count("#OSTO-") :
_options.osp += "timout:" + _line[6:] + ','
elif _line.count("#OSMO-") :
_options.osp += "mode:" + _line[6:] + ','
elif _line.count("#OSCN-") :
_options.cn = _line[6:]
else :
True
_options.osp = _options.osp[:-1]
_from_file = True
except IOError as msg :
_status = 10
_fmsg = str(msg)
except OSError as msg :
_status = 20
_fmsg = str(msg)
except Exception as e :
_status = 23
_fmsg = str(e)
finally :
if _options.operation and _options.osp and (_options.operation in ["cloud-api", "cloud-gui" ] or _options.cn) :
if (_options.operation in [ "cloud-api", "cloud-gui"]) and \
(not _options.apiport or not _options.apihost) :
print("The following parameters are mandatory: --apiport, --apihost")
exit(19)
return _options
else :
print("The following parameters are mandatory: --osp, --operation, --oop, --cn")
exit(18)
if not _options.cn and (not _options.syslogp or not _options.syslogf or not _options.syslogh or not _options.syslogr):
print("The following parameters are mandatory: --apiport, --apihost, --syslogf, --syslogh, --syslogp, --syslogr")
exit(20)
def setup_syslog(operation, facility, verbosity, port, hostname, quiet, logdest, protocol) :
'''
TBD
'''
try :
_fmsg = ""
_status = 100
# HACK ALERT - A very crude "syslog facility selector"
_syslog_selector = {}
_syslog_selector["16"] = SysLogHandler.LOG_LOCAL0
_syslog_selector["17"] = SysLogHandler.LOG_LOCAL1
_syslog_selector["18"] = SysLogHandler.LOG_LOCAL2
_syslog_selector["19"] = SysLogHandler.LOG_LOCAL3
_syslog_selector["20"] = SysLogHandler.LOG_LOCAL4
_syslog_selector["21"] = SysLogHandler.LOG_LOCAL5
_syslog_selector["22"] = SysLogHandler.LOG_LOCAL6
_syslog_selector["23"] = SysLogHandler.LOG_LOCAL7
_verbosity = int(verbosity)
logger = getLogger()
# Reset the logging handlers
while len(logger.handlers) != 0 :
logger.removeHandler(logger.handlers[0])
if logdest == "console" or (not hostname or not port) :
hdlr = StreamHandler(stdout)
else :
_facility = int(facility)
if _facility > 23 or _facility < 16 :
_facility = 23
if protocol == "TCP" :
hdlr = ReconnectingNewlineSysLogHandler(address = (hostname, int(port)),
facility=_syslog_selector[str(_facility)],
socktype = socket.SOCK_STREAM)
else :
hdlr = SysLogHandler(address = (hostname, int(port)),
facility=_syslog_selector[str(_facility)],
socktype = socket.SOCK_DGRAM)
# Need to make this rfc3164-compliant by including the 'hostname' and the 'program name'
formatter = Formatter(socket.getfqdn() + " cloudbench [%(levelname)s] %(message)s")
hdlr.setFormatter(formatter)
logger.addHandler(hdlr)
if _verbosity :
if int(_verbosity) >= 8 :
logger.setLevel(DEBUG)
elif int(_verbosity) >= 7 :
# Used to filter out all function calls from all modules in the
# "stores" subdirectory.
hdlr.addFilter(VerbosityFilter("datastore"))
logger.setLevel(DEBUG)
elif int(_verbosity) >= 6 :
hdlr.addFilter(VerbosityFilter("PassiveObjectOperations"))
hdlr.addFilter(VerbosityFilter("data_ops"))
# Used to filter out all function calls from all modules in the
# "stores" subdirectory.
hdlr.addFilter(VerbosityFilter("datastore"))
logger.setLevel(DEBUG)
elif int(_verbosity) >= 5 :
hdlr.addFilter(VerbosityFilter("PassiveObjectOperations"))
hdlr.addFilter(VerbosityFilter("get_object_count"))
hdlr.addFilter(VerbosityFilter("get_counters"))
hdlr.addFilter(VerbosityFilter("get_process_object"))
hdlr.addFilter(VerbosityFilter("data_ops"))
# Used to filter out all function calls from all modules in the
# "stores" subdirectory.
hdlr.addFilter(VerbosityFilter("datastore"))
logger.setLevel(DEBUG)
elif int(_verbosity) >= 4 :
hdlr.addFilter(VerbosityFilter("PassiveObjectOperations"))
hdlr.addFilter(VerbosityFilter("get_object_count"))
hdlr.addFilter(VerbosityFilter("get_counters"))
hdlr.addFilter(VerbosityFilter("get_process_object"))
hdlr.addFilter(VerbosityFilter("data_ops"))
# Used to filter out all function calls from the "auxiliary"
# subdirectory.
hdlr.addFilter(VerbosityFilter("auxiliary"))
# Used to filter out all function calls from all modules in the
# "stores" subdirectory.
hdlr.addFilter(VerbosityFilter("stores"))
hdlr.addFilter(VerbosityFilter("datastore"))
logger.setLevel(DEBUG)
elif int(_verbosity) >= 3 :
hdlr.addFilter(VerbosityFilter("PassiveObjectOperations"))
hdlr.addFilter(VerbosityFilter("get_object_count"))
hdlr.addFilter(VerbosityFilter("get_counters"))
hdlr.addFilter(VerbosityFilter("get_process_object"))
hdlr.addFilter(VerbosityFilter("data_ops"))
# Filter out gmetad logging statements
hdlr.addFilter(VerbosityFilter("gmetad"))
# Used to filter out all function calls from the "auxiliary"
# subdirectory.
hdlr.addFilter(VerbosityFilter("auxiliary"))
# Used to filter out all function calls from the "remote"
# subdirectory.
hdlr.addFilter(VerbosityFilter("remote"))
# Used to filter out all function calls from all modules in the
# "stores" subdirectory.
hdlr.addFilter(VerbosityFilter("stores"))
hdlr.addFilter(VerbosityFilter("datastore"))
hdlr.addFilter(MsgFilter("Exit point"))
hdlr.addFilter(MsgFilter("Entry point"))
logger.setLevel(DEBUG)
elif int(_verbosity) >= 2 :
hdlr.addFilter(VerbosityFilter("PassiveObjectOperations"))
hdlr.addFilter(VerbosityFilter("get_object_count"))
hdlr.addFilter(VerbosityFilter("get_counters"))
hdlr.addFilter(VerbosityFilter("get_process_object"))
hdlr.addFilter(VerbosityFilter("data_ops"))
# Filter out gmetad logging statements
hdlr.addFilter(VerbosityFilter("gmetad"))
# Used to filter out all function calls from the "auxiliary"
# subdirectory.
hdlr.addFilter(VerbosityFilter("auxiliary"))
# Used to filter out all function calls from all modules in the
# "collectors" subdirectory.
hdlr.addFilter(VerbosityFilter("collectors"))
# Used to filter out all function calls from the "remote"
# subdirectory.
hdlr.addFilter(VerbosityFilter("remote"))
# Used to filter out all function calls from all modules in the
# "stores" subdirectory.
hdlr.addFilter(VerbosityFilter("stores"))
hdlr.addFilter(VerbosityFilter("datastore"))
hdlr.addFilter(MsgFilter("Exit point"))
hdlr.addFilter(MsgFilter("Entry point"))
logger.setLevel(DEBUG)
elif int(_verbosity) == 1 :
hdlr.addFilter(VerbosityFilter("PassiveObjectOperations"))
hdlr.addFilter(VerbosityFilter("get_object_count"))
hdlr.addFilter(VerbosityFilter("get_counters"))
hdlr.addFilter(VerbosityFilter("get_process_object"))
hdlr.addFilter(VerbosityFilter("data_ops"))
# Filter out gmetad logging statements
hdlr.addFilter(VerbosityFilter("gmetad"))
# Used to filter out all function calls from the "auxiliary"
# subdirectory.
hdlr.addFilter(VerbosityFilter("auxiliary"))
# Used to filter out all function calls from all modules in the
# "stores" subdirectory.
hdlr.addFilter(VerbosityFilter("stores"))
hdlr.addFilter(VerbosityFilter("datastore"))
# Used to filter out all function calls from all modules in the
# "collectors" subdirectory.
hdlr.addFilter(VerbosityFilter("collectors"))
# Used to filter out all function calls from the "remote"
# subdirectory.
hdlr.addFilter(VerbosityFilter("remote"))
# Used to filter out all function calls from all modules in the
# "stores" subdirectory.
hdlr.addFilter(VerbosityFilter("clouds"))
logger.setLevel(DEBUG)
else :
logger.setLevel(INFO)
if quiet :
logger.setLevel(ERROR)
_status = 0
except Exception as e :
_status = 23
_fmsg = str(e)
finally :
if _status :
_msg = "Failure while setting up syslog channel: " + _fmsg
print(_msg)
exit(2)
else :
_msg = "Syslog channel set up successfully."
print(_msg)
return True
def main(options) :
'''
TBD
'''
try :
threading.current_thread().abort = False
_status = 100
_fmsg = ""
_local_process = False
_uuid = None
'''
OSCI and MSCI are cloud-independent entities. They can be instantiated
immediately and passed down the entire function call stack.
'''
_obj_type, _operation = options.operation.split('-')
_oscp = str2dic(options.osp)
if options.cn :
_oscp["cloud_name"] = options.cn
_osci = RedisMgdConn(_oscp)
_osci.experiment_inst = options.procid
if options.cn :
_dir_defaults = _osci.get_object(options.cn, "GLOBAL", False, "space", False)
_base_dir = _dir_defaults["base_dir"]
'''
For some historical reason, we're pulling logging options from both Redis and the CLI
This is OK for instances of the actuator that run on the orchestrator machine
itself, but for the load manager, it breaks when it runs over the VPN.
The modification here is that if and only if we're running as the load manager
then use the CLI values instead of the Redis values for logging.
'''
if _operation.count("execute") or not options.cn :
_log_defaults = {
"hostname" : options.syslogh,
"port" : options.syslogp,
_operation + "_facility" : options.syslogf,
"verbosity" : options.verbosity,
"protocol" : options.syslogr
}
else :
_log_defaults = _osci.get_object(options.cn, "GLOBAL", False, "logstore", False)
if str(options.verbosity).strip() != "-1" :
_log_defaults["verbosity"] = options.verbosity
setup_syslog(_operation, \
_log_defaults[_operation + "_facility"], \
_log_defaults["verbosity"], \
_log_defaults["port"], \
_log_defaults["hostname"], \
options.quiet, \
options.logdest, \
_log_defaults["protocol"]
)
if options.oop :
_parameters = options.oop.split(',')
'''
If any parameter contains a comma (that is the case for "meta_tags"
and temporary key-value pairs, it was "protected" by converting them
to some special, very unlikely to be use sequence. We cannot simply
get rid of the command on meta_tags and temporary key-value pairs,
because it is used by the dic2str function to create a dictionary
later. Here we just "recover" the command by reconverting it.
We do the same to "recover" the ">" character, since it is used in
the AI sut description
'''
_temp_parameters = ' '
for _parameter in _parameters :
_temp_parameters += _parameter.replace("+_*",',') + ' '
_temp_parameters = _temp_parameters.replace("-+-+-+", "->")
_parameters = _temp_parameters
else :
_parameters = "none"
_msg = "Operation is \"" + _operation + "\" and object is \""
_msg += _obj_type.upper() + "\". Object operation parameters are: "
_msg += _parameters + '.'
cbdebug(_msg)
_active_obj_command = ActiveObjectOperations(_osci)
_passive_obj_command = PassiveObjectOperations(_osci)
if _operation.count("attach") :
_local_process = True
_obj_attr_list = {}
_obj_attr_list["nosync"] = "true"
if options.ouuid :
_obj_attr_list["uuid"] = options.ouuid
else :
_obj_attr_list["uuid"] = str(uuid5(NAMESPACE_DNS, \
str(randint(0, \
1000000000000000000)))).upper()
_uuid = _obj_attr_list["uuid"]
if _obj_type.upper() == "VM" :
_obj_attr_list["ai"] = "none"
_obj_attr_list["ai_name"] = "none"
_obj_attr_list["aidrs"] = "none"
_obj_attr_list["aidrs_name"] = "none"
_obj_attr_list["pattern"] = "none"
_obj_attr_list["type"] = "none"
else :
True
if _operation == "attachall" and _obj_type.upper() == "VMC" :
_status, _fmsg, _object = _active_obj_command.vmcattachall(_obj_attr_list, \
_parameters, \
options.operation)
else :
_status, _fmsg, _object = _active_obj_command.objattach(_obj_attr_list, \
_parameters, \
options.operation)
elif _operation.count("submit") :
_local_process = True
_uuid = options.ouuid
if _obj_type.upper() == "AIDR" :
_obj_type = "AIDRS"
_status, _fmsg = _active_obj_command.aidsubmit(options.cn, _base_dir, _obj_type, _uuid)
elif _obj_type.upper() == "VMCR" :
_obj_type = "VMCRS"
_status, _fmsg = _active_obj_command.vmcrsubmit(options.cn, _base_dir, _obj_type, _uuid)
else :
_msg = "Unknown Submitter Type"
_status = 99
elif _operation.count("remove") :
_local_process = True
_uuid = options.ouuid
if _obj_type.upper() == "AIDR" :
_obj_type = "AIDRS"
_status, _fmsg = _active_obj_command.aidremove(options.cn, _base_dir, _obj_type, _uuid)
else :
_fmsg = "Unknown Remover Type"
_status = 99
elif _operation.count("subscribe") :
_obj_type = "AI"
_local_process = False
_uuid = options.ouuid
_osci.subscribe_channel(options.cn, _obj_type, _uuid, 3600)
_status = 0
elif _operation.count("api") :
_local_process = True
_obj_type = "GLOBAL"
_status, _fmsg = _passive_obj_command.run_api_service(_passive_obj_command, \
_active_obj_command, \
options.debug_host,
options.apiport,
options.apihost.split(","))
elif _operation.count("gui") :
from lib.auxiliary.gui import gui
_local_process = True
_obj_type = "GLOBAL"
gui(options)
_status = 0
_msg = "Complete"
elif _operation.count("qemu") :
_local_process = True
_obj_type = "AI"
_status, _fmsg = _passive_obj_command.qemu_scraper(options.cn, options.ouuid)
elif _operation.count("watch") :
_local_process = True
_obj_type = "GLOBAL"
_status, _fmsg = _passive_obj_command.cloud_watch(options.cn, _uuid)
_status = 0
elif _operation.count("emit") :
_local_process = True
_uuid = options.ouuid
_obj_type = "AI"
_status, _fmsg = _passive_obj_command.performance_metrics_emitter(options.cn, _uuid)
_status = 0
elif _operation.count("execute") :
_obj_type = "AI"
_local_process = False
_uuid = options.ouuid
_status, _fmsg = _active_obj_command.aiexecute(options.cn, \
_obj_type, _uuid)
elif _operation.count("migrate") or _operation.count("protect") :
_local_process = True
_uuid = options.ouuid
_obj_attr_list = {}
_obj_attr_list["nosync"] = "true"
if _obj_type.upper() == "VM" :
_obj_type = "VM"
_status, _fmsg, _object = _active_obj_command.migrate(_obj_attr_list, \
_parameters, \
options.operation)
elif _operation.count("login") or _operation.count("display") :
_local_process = True
_uuid = options.ouuid
_obj_attr_list = {}
_obj_attr_list["nosync"] = "true"
if _obj_type.upper() == "VM" :
_obj_type = "VM"
_status, _fmsg, _object = _active_obj_command.gtk(_obj_attr_list, _parameters, options.operation)
elif _operation.count("capture") :
_local_process = True
_uuid = options.ouuid
_obj_attr_list = {}
_obj_attr_list["nosync"] = "true"
if _obj_type.upper() == "VM" :
_obj_type = "VM"
_status, _fmsg, _object = _active_obj_command.vmcapture(_obj_attr_list, \
_parameters, \
options.operation)
elif _obj_type.upper() == "AI" :
_obj_type = "AI"
_status, _fmsg, _object = _active_obj_command.aicapture(_obj_attr_list, \
_parameters, \
options.operation)
elif _operation.count("runstate") :
_local_process = True
_uuid = options.ouuid
_obj_attr_list = {}
if _obj_type.upper() == "VM" :
_obj_type = "VM"
_status, _fmsg, _object = _active_obj_command.vmrunstate(_obj_attr_list, \
_parameters, \
options.operation)
elif _obj_type.upper() == "AI" :
_obj_type = "AI"
_status, _fmsg, _object = _active_obj_command.airunstate(_obj_attr_list, \
_parameters, \
options.operation)
elif _operation.count("fail") :
_local_process = True
_uuid = options.ouuid
_obj_attr_list = {}
if _obj_type.upper() == "VM" :
_status, _fmsg, _object = _active_obj_command.vmfail_repair(_obj_attr_list, \
_parameters, \
options.operation)
elif _obj_type.upper() == "HOST" :
_status, _fmsg, _object = _active_obj_command.hostfail_repair(_obj_attr_list, \
_parameters, \
options.operation)
elif _operation.count("repair") :
_local_process = True
_uuid = options.ouuid
_obj_attr_list = {}
if _obj_type.upper() == "VM" :
_status, _fmsg, _object = _active_obj_command.vmfail_repair(_obj_attr_list, \
_parameters, \
options.operation)
elif _obj_type.upper() == "HOST" :
_status, _fmsg, _object = _active_obj_command.hostfail_repair(_obj_attr_list, \
_parameters, \
options.operation)
elif _operation.count("detach") :
_local_process = True
_uuid = options.ouuid
# The dictionary needs to be reset anyway.
_obj_attr_list = {}
_status, _fmsg, _object = _active_obj_command.objdetach(_obj_attr_list, \
_parameters, \
options.operation)
else :
_local_process = False
_fmsg = "Unknown operation: " + _operation
_status = 45
except KeyboardInterrupt:
_status = 27
_fmsg = "CTRL-C Exiting"
except Exception as e :
_status = 23
_fmsg = str(e)
finally :
if _local_process and options.cn :
_obj_id = str(_uuid) + '-' + _operation
_msg = "Removing the entry from the \"running_processes\" list "
_msg += " on the object store (FQVN: " + options.procid
_msg += ':' + options.cn + ":GLOBAL:running_processes"
cbdebug(_msg)
_active_obj_command.update_process_list(options.cn, \
_obj_type.upper(), \
_obj_id, None, "remov")
if _status :
_msg = "Operation \"" + options.operation + "\" failure: " + _fmsg
cberr(_msg)
exit(2)
else :
_msg = "Operation \"" + options.operation + "\" success."
cbdebug(_msg)
# exit(0)
os.kill(os.getpid(), signal.SIGKILL)
# Executed code
_options = actuator_cli_parsing()
MainThread = threading.current_thread()
MainThread.abort = False
MainThread.aborted = False
if _options.daemon :
with DaemonContext(working_directory="/tmp", pidfile=None) :
main(_options)
else :
main(_options)