-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathNDBActivator3.0_I5_Plus.py
709 lines (665 loc) · 26.3 KB
/
NDBActivator3.0_I5_Plus.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
"""Start NDB Embedded using Guestshell"""
import json
import subprocess
import re
import os
import sys
import copy
import time
import logging
import zipfile
import fileinput
from cli import *
class Nexus(object):
"""Class to perform nexus switch related operations"""
def __init__(self):
self.user = None
self.vs_data = None
self.n3k_flag = 0
self.n9k_flag = 0
def get_vs_info(self):
"""Collect the virtual service cpu/memory/disk size"""
self.vs_data = None
vs_memory_cmd = 'show virtual-service global | json'
try:
self.vs_data = cli(vs_memory_cmd)
self.vs_data = json.loads(self.vs_data)
except:
logger.error("Something went wrong while fetching switch memory")
return self.vs_data
def get_vs_memory_quota(self, vs_info=None):
"""Returns the available memory quota for Virtual-service"""
memory_quota = None
if vs_info is None:
self.vs_data = self.get_vs_info()
else:
self.vs_data = copy.deepcopy(vs_info)
vs_items = self.vs_data['TABLE_resource_limits']['ROW_resource_limits']
for resource_item in vs_items:
if 'memory' in resource_item['media_name']:
memory_quota = resource_item['quota']
return memory_quota
def get_vs_disk_quota(self, vs_info=None):
"""Returns the available disk quota for Virtual-service"""
disk_quota = None
if vs_info is None:
self.vs_data = self.get_vs_info()
else:
self.vs_data = copy.deepcopy(vs_info)
vs_items = self.vs_data['TABLE_resource_limits']['ROW_resource_limits']
for resource_item in vs_items:
if 'bootflash' in resource_item['media_name']:
disk_quota = resource_item['quota']
return disk_quota
def get_vs_cpu_quota(self, vs_info=None):
"""Returns the available cpu quota for Virtual-service"""
cpu_quota = None
if vs_info is None:
self.vs_data = self.get_vs_info()
else:
self.vs_data = copy.deepcopy(vs_info)
vs_items = self.vs_data['TABLE_resource_limits']['ROW_resource_limits']
for resource_item in vs_items:
if 'system CPU' in resource_item['media_name']:
cpu_quota = resource_item['quota']
return cpu_quota
def get_user(self):
"""Returns the current username"""
current_user = subprocess.check_output("whoami", shell=True)
self.user = current_user.strip()
return self.user
def get_role(self, user=None):
"""Returns the role of a given user"""
user_roles = None
if user:
self.user = user
if self.user:
roles_cmd = 'show user-account '+ self.user.decode('UTF-8') +' | json'
try:
roles_resp = cli(roles_cmd)
roles = json.loads(roles_resp)
user_roles = roles['TABLE_template']['ROW_template'][
'TABLE_role']['ROW_role']
except:
logger.error("Something went wrong while fetching user roles")
else:
logger.error("Please specify valid user")
return user_roles
def get_privilege(self):
"""Returns the privilege of a given user"""
user_priv = None
priv_cmd = 'show privilege'
try:
priv_resp = cli(priv_cmd)
for line in priv_resp.split("\n"):
line = line.strip()
if "privilege level" in line:
user_priv = line.split(":")[1]
except:
logger.info("Something went wrong while fetching user privilege")
return user_priv
def get_nxos_version(self):
"""Returns the NXOS version of switch"""
version = None
version_cmd = 'show version | json'
try:
version_resp = cli(version_cmd)
version_resp = json.loads(version_resp)
version = version_resp['kickstart_ver_str']
except:
logger.error("Something went wrong while fetching NXOS version")
return version
def get_nxos_platform(self):
"""Returns the NXOS platform of switch"""
platform = None
platform_cmd = 'sh ver | inc ignore-case Chassis'
try:
cliout = cli(platform_cmd)
for line in cliout.split("\n"):
line = line.strip()
if ("Chassis" in line or 'chassis' in line) and 'cisco' in line:
if len(line.split()) >= 4:
platform = line.split()[2]
else:
platform = line.split()[1]
except:
pass
return platform
def enable_nxapi_feature(self):
"""Enables feature nxapi"""
nxapi_cmd = 'configure terminal ; feature nxapi'
try:
cli(nxapi_cmd)
return True
except:
logger.error("Something went wrong while enabling feature NX-API")
return False
def set_nxapi_vrf(self):
"""Configures vrf to be used for nxapi communication"""
vrf_cmd = 'configure terminal ; nxapi use-vrf management ; copy running-config startup-config'
try:
cli(vrf_cmd)
return True
except:
logger.error("Something went wrong while keeping nxapi to listen to network namespace")
return False
def remove_file(self, name):
"""Remove a file/directory from bootflash"""
file_name = name
remove_cmd = 'sudo rm -rf /bootflash/' + file_name
try:
subprocess.check_output(remove_cmd, shell=True)
return True
except:
return False
def check_file(self, name):
"""check a file/directory from bootflash"""
file_name = name
file_path = '/bootflash/' + file_name
try:
return bool(os.path.exists(file_path))
except:
return False
def modify_content(self, user, embedded_path):
"""Replace the content of the files in xnc/embedded/i5 directory"""
try:
make_path = embedded_path + '/make-systemctl-env.sh'
if bool(os.path.exists(make_path)):
for line in fileinput.input(make_path, inplace=1):
print (line.replace("guestshell", user.decode('UTF-8')))
service_path = embedded_path + '/ndb.service'
if bool(os.path.exists(service_path)):
for line in fileinput.input(service_path, inplace=1):
print (line.replace("guestshell", user.decode('UTF-8')))
trigger_path = embedded_path + 'trigger.sh'
if bool(os.path.exists(trigger_path)):
for line in fileinput.input(trigger_path, inplace=1):
print (line.replace("guestshell", user.decode('UTF-8')))
return True
except:
return False
class Guestshell(Nexus):
"""Performs guestshell related operations in nexus switch"""
def __init__(self):
super(Guestshell, self).__init__()
self.status = None
self.reserved_cpu = None
self.reserved_memory = None
self.reserved_disk = None
self.guestshell_version = None
def get_cpu(self):
"""Get the reserved cpu value for guestshell"""
status_cmd = 'show virtual-service detail name guestshell+ | json'
guestshell_cpu = None
try:
guestshell_resp = cli(status_cmd)
if guestshell_resp != '':
guestshell_resp = json.loads(guestshell_resp)
guestshell_cpu = guestshell_resp['TABLE_detail']['ROW_detail']['cpu_reservation']
self.reserved_cpu = guestshell_cpu
return self.reserved_cpu
except:
logger.error("Something went wrong while fetching guestshell+ reserved cpu")
def get_memory(self):
"""Get the reserved memory value for guestshell"""
status_cmd = 'show virtual-service detail name guestshell+ | json'
guestshell_memory = None
try:
guestshell_resp = cli(status_cmd)
if guestshell_resp != '':
guestshell_resp = json.loads(guestshell_resp)
guestshell_memory = guestshell_resp['TABLE_detail'][
'ROW_detail']['memory_reservation']
self.reserved_memory = guestshell_memory
return self.reserved_memory
except:
logger.error("Something went wrong while fetching guestshell+ reserved memory")
def get_disk(self):
"""Get the reserved disk value for guestshell"""
status_cmd = 'show virtual-service detail name guestshell+ | json'
try:
guestshell_resp = cli(status_cmd)
if guestshell_resp != '':
guestshell_resp = json.loads(guestshell_resp)
guestshell_disk = guestshell_resp['TABLE_detail']['ROW_detail']['disk_reservation']
self.reserved_disk = guestshell_disk
return self.reserved_disk
except:
logger.error("Something went wrong while fetching guestshell+ reserved memory")
def set_cpu(self, cpu_value):
"""Set the cpu value for guestshell"""
cpu_cmd = 'guestshell resize cpu ' + str(cpu_value)
try:
cli(cpu_cmd)
return True
except:
logger.error("Something went wrong while configuring cpu for guestshell+")
return False
def set_memory(self, memory_value):
"""Set the cpu value for guestshell"""
memory_cmd = 'guestshell resize memory ' + str(memory_value)
try:
cli(memory_cmd)
return True
except:
logger.error("Something went wrong while configuring memory for guestshell+")
return False
def set_disk(self, disk_value):
"""Set the cpu value for guestshell"""
disk_cmd = 'guestshell resize rootfs ' + str(disk_value)
try:
cli(disk_cmd)
return True
except:
logger.error("Something went wrong while configuring bootflash for guestshell+")
return False
def enable(self, pkg_name=None):
"""Enables the guestshell"""
enable_cmd = 'guestshell enable'
if pkg_name:
enable_cmd = 'guestshell enable package ' + pkg_name
try:
cli(enable_cmd)
return True
except:
logger.error("Something went wrong while enabling guestshell")
return False
def disable(self):
"""Disables the guestshell"""
disable_cmd = 'guestshell disable'
try:
cli(disable_cmd)
return True
except:
logger.error("Something went wrong while disabling guestshell")
def reboot(self):
"""Rebooting the guestshell"""
reboot_cmd = 'guestshell reboot'
try:
cli(reboot_cmd)
return True
except:
logger.error("Something went wrong while rebooting guestshell")
def get_status(self):
"""Get the status of the guestshell"""
status_cmd = 'show virtual-service detail name guestshell+ | json'
guestshell_status = None
try:
guestshell_resp = cli(status_cmd)
if guestshell_resp == '':
guestshell_status = 'Not Installed'
else:
guestshell_resp = json.loads(guestshell_resp)
guestshell_status = guestshell_resp['TABLE_detail']['ROW_detail']['state']
self.status = guestshell_status
return self.status
except:
logger.error("Something went wrong while fetching guestshell+ status")
def get_version(self):
"""Get the version of guestshell"""
status_cmd = 'show virtual-service detail name guestshell+ | json'
guestshell_version = None
try:
guestshell_resp = cli(status_cmd)
if guestshell_resp != '':
guestshell_resp = json.loads(guestshell_resp)
guestshell_version = guestshell_resp['TABLE_detail'][
'ROW_detail']['application_version']
self.guestshell_version = guestshell_version
return self.guestshell_version
except:
logger.error("Something went wrong while fetching guestshell+ reserved cpu")
def gs_copy_ndb(self, from_path, to_path):
"""Proc to copy file from one location to another"""
copy_cmd = 'guestshell run cp -Rf ' + from_path + " " + to_path + "/"
try:
cli(copy_cmd)
return True
except:
return False
def change_ndb_perm(self, guest_path):
"""Proc to change the directory permission through guestshell"""
perm_cmd = 'guestshell run chmod -Rf 777 ' + guest_path
try:
cli(perm_cmd)
return True
except:
return False
def guestshell_user(self):
"""proc to get the guestshell user"""
gs_user_cmd = 'guestshell run whoami'
# logger.info(gs_user_cmd)
try:
gs_user = cli(gs_user_cmd)
return gs_user
except:
return "Something went wrong while getting the guestshell username"
class NDB(Guestshell):
"""Performs NDB related operations inside Guestshell"""
def __init__(self):
super(NDB, self).__init__()
self.ndb_version = None
def extract_ndb(self, file_name, path_to_extract):
"""Extract the NDB zip file to given path"""
try:
zip_ref = zipfile.ZipFile(file_name, 'r')
zip_ref.extractall(path_to_extract)
zip_ref.close()
return True
except:
return False
def validate_ndb_content(self, path):
"""Check for the files inside xnc directory"""
try:
xncpath = path
files = ('runxnc.sh', 'start.sh', 'version.properties', 'runxnc.cmd')
dirs = ('embedded', 'lib', 'bin', 'configuration', 'etc', 'plugins')
for file_name in files:
file_path = xncpath + '/' + file_name
if not os.path.exists(file_path):
return False
for dir_name in dirs:
dir_path = xncpath + '/' + dir_name
if not os.path.isdir(dir_path):
return False
return True
except:
return False
def start_ndb(self, path):
"""Starting the NDB"""
start_cmd = 'guestshell run ' + path + '/embedded/i5/make-systemctl-env.sh'
try:
cli(start_cmd)
return True
except:
return False
def verify_ndb(self):
"""Verifying if NDB is already installed"""
systemd_path = '/isan/vdc_1/virtual-instance/guestshell+/rootfs/usr/lib/systemd/system/ndb.service'
return bool(os.path.exists(systemd_path))
def validate_gs_version(version):
"""Returns True if guestshell version is equal to or greater than 2.2(0.2)"""
guestshell_version = version
version_pattern = r"(\d+).(\d+)"
versions = re.findall(version_pattern, guestshell_version)
version1 = list(versions[0])
major_version1 = version1[0]
minor_version1 = version1[1]
expected_major_version1 = 2
expected_minor_version1 = 2
val = str(major_version1) + "." + str(minor_version1)
flag = False
if val == "2.2":
version2 = list(versions[1])
major_version2 = version2[0]
minor_version2 = version2[1]
expected_major_version2 = 0
expected_minor_version2 = 2
if int(major_version2) > int(expected_major_version2):
flag = True
elif int(major_version2) == int(expected_major_version2):
if int(minor_version2) >= int(expected_minor_version2):
flag = True
else:
if int(major_version1) > int(expected_major_version1):
flag = True
elif int(major_version1) == int(expected_major_version1):
if int(minor_version1) >= int(expected_minor_version1):
flag = True
return flag
def wait_gs_up(gs_obj):
"""Waits for the guestshell to be UP"""
status_check_count = 36
check_interval = 5
activated_flag = 0
for _ in range(status_check_count):
gs_status = gs_obj.get_status()
if gs_status == 'Activated':
activated_flag = 1
break
else:
time.sleep(check_interval)
return bool(activated_flag)
def allocate_gs_resource(gs_obj):
"""Allocate guestshell resource based on available quota"""
min_memory = 1024
min_disk = 1024
min_cpu = 5
skip_memory = 0
skip_disk = 0
skip_cpu = 0
set_flag = 1
memory_quota = gs_obj.get_vs_memory_quota()
disk_quota = gs_obj.get_vs_disk_quota()
cpu_quota = gs_obj.get_vs_cpu_quota()
committed_memory = gs_obj.get_memory()
committed_disk = gs_obj.get_disk()
committed_cpu = gs_obj.get_cpu()
if int(memory_quota) < min_memory:
set_resp = gs_obj.set_memory(memory_quota)
gs_obj.n3k_flag = 1
gs_obj.n9k_flag = 0
if not set_resp:
set_flag = 0
else:
gs_obj.n9k_flag = 1
gs_obj.n3k_flag = 0
if int(committed_memory) >= min_memory:
skip_memory = 1
else:
set_resp = gs_obj.set_memory(min_memory)
if not set_resp:
set_flag = 0
if int(disk_quota) < min_disk:
set_resp = gs_obj.set_disk(disk_quota)
if not set_resp:
set_flag = 0
else:
if int(committed_disk) >= min_disk:
skip_disk = 1
else:
set_resp = gs_obj.set_disk(min_disk)
if not set_resp:
set_flag = 0
if int(cpu_quota) < min_cpu:
set_resp = gs_obj.set_cpu(cpu_quota)
if not set_resp:
set_flag = 0
else:
if int(committed_cpu) >= min_cpu:
skip_cpu = 1
else:
set_resp = gs_obj.set_cpu(min_cpu)
if not set_resp:
set_flag = 0
if skip_cpu and skip_disk and skip_memory:
return True, gs_obj
elif set_flag:
reboot_resp = gs_obj.reboot()
if reboot_resp:
wait_resp = wait_gs_up(gs_obj)
return wait_resp, gs_obj
else:
return False, gs_obj
def add_content(nexus_obj, path):
"""Adds platform and flag for NXOS"""
try:
xncpath = path
platform_string = "Platform="
platform = nexus_obj.get_nxos_platform()
if not platform:
return False
platform = int(re.search(r'\d+', platform).group())
platform_string += str(platform)+'\n'
platform_file = xncpath + "/embedded/Platform"
file_obj = open(platform_file, "w+")
n3k_string = 'n3k_conf_flag='+str(nexus_obj.n3k_flag)+'\n'
n9k_string = 'n9k_conf_flag='+str(nexus_obj.n9k_flag)+'\n'
platform_content = [platform_string, n9k_string, n3k_string]
file_obj.writelines(platform_content)
file_obj.close()
return True
except:
return False
def guestshell():
"""Perform all guestshell operation to start NDB"""
ndb_obj = NDB()
force_flag = 0
if len(sys.argv) == 4:
zip_file_path = sys.argv[-1]
elif len(sys.argv) == 5 and '--force' in sys.argv[-1]:
zip_file_path = sys.argv[-2]
force_flag = 1
elif len(sys.argv) == 5 and '--quiet' in sys.argv[-1]:
zip_file_path = sys.argv[-2]
elif len(sys.argv) == 6:
zip_file_path = sys.argv[-3]
else:
logger.error("Please provide valid arguments")
sys.exit(0)
if not os.path.exists(zip_file_path):
logger.error("NDB zip file does not exists in the given path " + zip_file_path)
sys.exit(0)
c_user = ndb_obj.get_user()
if not c_user:
logger.error("Something went wrong while fetching current user")
sys.exit(0)
# Check the current user role
c_user_role = ndb_obj.get_role()
if type(c_user_role)==list:
for roles in c_user_role:
if "network-admin" in roles["role"]:
c_user_role = "network-admin"
else:
c_user_role = c_user_role["role"]
if 'network-admin' not in c_user_role:
logger.error("User role is not network-admin")
sys.exit(0)
try:
privilege = ndb_obj.get_privilege()
if int(privilege) != 15:
logger.error("User privilege is not 15")
sys.exit(0)
except:
logger.info("Show privilege validation skipped")
# Check whether the guestshell is activated
current_gs_status = ndb_obj.get_status()
if current_gs_status == 'Activated':
pass
else:
# Enabling Guestshell in the switch
logger.info("Enabling Guestshell")
enable_resp = ndb_obj.enable()
state_flag = 0
if enable_resp:
wait_resp = wait_gs_up(ndb_obj)
if wait_resp:
state_flag = 1
if not state_flag:
logger.error("Something went wrong while enabling Guestshell")
sys.exit(0)
# Validate the current GS version
gs_version = ndb_obj.get_version()
logger.info("Validating Guestshell version")
validate_resp = validate_gs_version(gs_version)
if not validate_resp:
logger.error("NDB doesn't support current Guestshell version")
logger.error("NDB will run on Guestshell version 2.2 and above, either upgrade the Guestshell or destroy and re-run the script")
sys.exit(0)
if not force_flag:
allocate_resp, ndb_obj = allocate_gs_resource(ndb_obj)
if allocate_resp:
logger.info("Resized the guestshell resources")
else:
logger.error("Something went wrong while allocating Guestshell resource")
sys.exit(0)
check_file_resp = ndb_obj.check_file('xnc')
if check_file_resp:
logger.error("Directory xnc already present in bootflash. Please remove it.")
sys.exit(0)
# Unzipping NDB zip file to Guestshell bootflash
extract_resp = ndb_obj.extract_ndb(zip_file_path, '/bootflash')
xnc_path = '/bootflash/xnc'
gs_user = ndb_obj.guestshell_user().splitlines()[0]
guest_path = '/home/' + gs_user
# Verifying NDB is already installed
if not force_flag:
verify_ndb_resp = ndb_obj.verify_ndb()
if verify_ndb_resp:
logger.error("NDB application is already installed.")
ndb_obj.remove_file('xnc')
sys.exit(0)
if extract_resp:
# Validate the content in ndb dir
if not os.path.exists(xnc_path):
logger.error("Zip file doesn't contain xnc. Provide valid zip file")
ndb_obj.remove_file('xnc')
sys.exit(0)
validate_resp = ndb_obj.validate_ndb_content(xnc_path)
if not validate_resp:
logger.error("Some files are missing in xnc. Provide valid zip file")
ndb_obj.remove_file('xnc')
sys.exit(0)
else:
# add the actual value instead of generic zip file
logger.error("Something went wrong while extracting zip file")
ndb_obj.remove_file('xnc')
sys.exit(0)
embedded_path = xnc_path + '/embedded/i5'
modify_resp = ndb_obj.modify_content(c_user, embedded_path)
if not modify_resp:
logger.error("Something went wrong while replacing file information under xnc/embedded directory")
ndb_obj.remove_file('xnc')
sys.exit(0)
add_resp = add_content(ndb_obj, xnc_path)
if not add_resp:
logger.warning("Something went wrong while adding platform information under xnc/embedded directory")
# Copying xnc directory to guestshell
copy_resp = ndb_obj.gs_copy_ndb(xnc_path, guest_path)
if not copy_resp:
logger.error("Something went wrong while copying xnc to guestshell path")
ndb_obj.remove_file('xnc')
sys.exit(0)
else:
logger.info("Placed the xnc folder into home directory "+guest_path)
# Remove xnc directory from bootflash
remove_resp = ndb_obj.remove_file('xnc')
if not remove_resp:
logger.error("Something went wrong while removing xnc from bootflash")
ndb_path = '/home/' + gs_user + '/xnc'
ndb_perm_resp = ndb_obj.change_ndb_perm(ndb_path)
if not ndb_perm_resp:
logger.error("Something went wrong while changing the permission of xnc directory")
nxapi_resp = ndb_obj.enable_nxapi_feature()
if not nxapi_resp:
logger.error("Something went wrong while enabling feature nxapi in switch")
vrf_resp = ndb_obj.set_nxapi_vrf()
if vrf_resp:
logger.info("Kept the nxapi to listen to network namespace")
else:
logger.error("Something went wrong while keeping nxapi to listen to network namespace")
sys.exit(0)
start_resp = ndb_obj.start_ndb(ndb_path)
if start_resp:
logger.info("Started NDB")
else:
logger.error("Something went wrong while starting NDB as a service")
sys.exit(0)
def main():
"""Function which triggers guestshell proc to start NDB"""
guestshell()
if __name__ == "__main__":
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
con_log_handler = logging.StreamHandler()
file_log_handler = logging.FileHandler("/bootflash/ndb_deploy.log")
file_log_handler.setLevel(logging.DEBUG)
con_log_handler.setLevel(logging.DEBUG)
formatter = logging.Formatter(
'%(asctime)s - %(name)s - %(levelname)s - %(message)s')
file_log_handler.setFormatter(formatter)
con_log_handler.setFormatter(formatter)
logger.addHandler(file_log_handler)
if '--quiet' not in sys.argv:
logger.addHandler(con_log_handler)
main()