105
119
log('Unable to update /etc/apt/sources.list')
122
def configure_analyst_opsvm():
124
Configures Anaylyst for OPSVM
126
if not service_running('plumgrid'):
128
NS_ENTER = ('/opt/local/bin/nsenter -t $(ps ho pid --ppid $(cat '
129
'/var/run/libvirt/lxc/plumgrid.pid)) -m -n -u -i -p ')
130
sigmund_stop = NS_ENTER + '/usr/bin/service plumgrid-sigmund stop'
131
sigmund_status = NS_ENTER \
132
+ '/usr/bin/service plumgrid-sigmund status'
133
sigmund_autoboot = NS_ENTER \
134
+ '/usr/bin/sigmund-configure --ip {0} --start --autoboot' \
135
.format(config('opsvm-ip'))
137
status = subprocess.check_output(sigmund_status, shell=True)
138
if 'start/running' in status:
139
if subprocess.call(sigmund_stop, shell=True):
140
log('plumgrid-sigmund couldn\'t be stopped!')
142
subprocess.check_call(sigmund_autoboot, shell=True)
144
log('plumgrid-sigmund couldn\'t be started!')
108
147
def determine_packages():
110
149
Returns list of packages required by PLUMgrid director as specified
317
366
set_nic_mtu(fabric_interface, interface_mtu)
320
def disable_apparmor_libvirt():
322
Disables Apparmor profile of libvirtd.
324
apt_install('apparmor-utils')
325
apt_install('cgroup-bin')
326
_exec_cmd(['sudo', 'aa-disable', '/usr/sbin/libvirtd'],
327
error_msg='Error disabling AppArmor profile of libvirtd')
329
service_restart('libvirt-bin')
332
def disable_apparmor():
334
Disables Apparmor security for lxc.
337
f = open(LXC_CONF, 'r')
339
log('Libvirt not installed yet')
343
newdata = filedata.replace("security_driver = \"apparmor\"",
344
"#security_driver = \"apparmor\"")
345
f = open(LXC_CONF, 'w')
350
369
def _exec_cmd(cmd=None, error_msg='Command exited with ERRORs', fatal=False):
352
371
Function to execute any bash command on the node.
455
Posts PLUMgrid nodes IPs to solutions api server.
457
if not config('enable-sapi'):
458
log('Solutions API support is disabled!')
460
pg_edge_ips = _pg_edge_ips()
461
pg_dir_ips = _pg_dir_ips()
462
pg_gateway_ips = _pg_gateway_ips()
463
pg_dir_ips.append(get_host_ip(unit_get('private-address')))
464
pg_edge_ips = '"edge_ips"' + ':' \
465
+ '"{}"'.format(','.join(str(i) for i in pg_edge_ips))
466
pg_dir_ips = '"director_ips"' + ':' \
467
+ '"{}"'.format(','.join(str(i) for i in pg_dir_ips))
468
pg_gateway_ips = '"gateway_ips"' + ':' \
469
+ '"{}"'.format(','.join(str(i) for i in pg_gateway_ips))
470
opsvm_ip = '"opsvm_ip"' + ':' + '"{}"'.format(config('opsvm-ip'))
471
virtual_ip = '"virtual_ip"' + ':' \
472
+ '"{}"'.format(config('plumgrid-virtual-ip'))
473
JSON_IPS = ','.join([pg_dir_ips, pg_edge_ips, pg_gateway_ips,
474
opsvm_ip, virtual_ip])
476
'curl -H \'Content-Type: application/json\' -X '
477
'PUT -d \'{{{0}}}\' http://{1}' + ':' + '{2}/v1/zones/{3}/allIps'
478
).format(JSON_IPS, config('lcm-ip'), config('sapi-port'),
480
POST_ZONE_IPs = _exec_cmd_output(
482
'Posting Zone IPs to Solutions API server failed!')
484
if 'success' in POST_ZONE_IPs:
485
log('Successfully posted Zone IPs to Solutions API server!')
489
def _exec_cmd_output(cmd=None, error_msg='Command exited with ERRORs',
492
Function to get output from bash command executed on the node.
495
log("No command specified")
498
return subprocess.check_output(cmd, shell=True)
501
return subprocess.check_output(cmd, shell=True)
502
except subprocess.CalledProcessError:
507
def sapi_post_license():
509
Posts PLUMgrid License to solutions api server
511
if not config('enable-sapi'):
512
log('Solutions API support is disabled!')
514
username = '"user_name":' + '"{}"'.format(config('plumgrid-username'))
515
password = '"password":' + '"{}"'.format(config('plumgrid-password'))
516
license = '"license":' + '"{}"'.format(config('plumgrid-license-key'))
517
JSON_LICENSE = ','.join([username, password, license])
519
'curl -H \'Content-Type: application/json\' -X '
520
'PUT -d \'{{{0}}}\' http://{1}' + ':' + '{2}/v1/zones/{3}/pgLicense'
521
).format(JSON_LICENSE, config('lcm-ip'), config('sapi-port'),
523
POST_LICENSE = _exec_cmd_output(
525
'Posting PLUMgrid License to Solutions API server failed!')
527
if 'success' in POST_LICENSE:
528
log('Successfully posted license file for zone "{}"!'
529
.format(config('sapi-zone')))
533
def sapi_post_zone_info():
535
Posts zone information to solutions api server
537
if not config('enable-sapi'):
538
log('Solutions API support is disabled!')
540
sol_name = '"solution_name":"Ubuntu OpenStack"'
541
release = config('openstack-release')
542
for key, value in OPENSTACK_RELEASE_VERS.iteritems():
547
sol_version = '"solution_version":"{}"'.format(sol_version)
548
pg_ons_version = _exec_cmd_output(
549
'dpkg -l | grep plumgrid | awk \'{print $3}\' | '
550
'sed \'s/-/./\' | cut -f1 -d"-"',
551
'Unable to obtain PG ONS version'
554
'"pg_ons_version":"{}"'.format(pg_ons_version)
555
hypervisor = '"hypervisor":"Ubuntu"'
556
hypervisor_version = \
557
_exec_cmd_output('lsb_release -r | awk \'{print $2}\'',
558
'Unable to obtain solution version'
560
hypervisor_version = '"hypervisor_version":"{}"' \
561
.format(hypervisor_version)
562
kernel_version = _exec_cmd_output(
564
'Unable to obtain kernal version').replace('\n', '')
566
'"kernel_version":"{}"'.format(kernel_version)
567
cloudapex_path = '/var/lib/libvirt/filesystems/plumgrid/' \
568
'opt/pg/web/cloudApex/modules/appCloudApex' \
570
if os.path.isfile(cloudapex_path):
571
pg_cloudapex_version = 'cat ' \
572
+ '{}'.format(cloudapex_path) \
573
+ ' | grep -i appversion | awk \'{print $2}\''
574
pg_cloudapex_version = \
575
_exec_cmd_output(pg_cloudapex_version,
576
'Unable to retrieve CloudApex version'
579
log('CloudApex not installed!')
580
pg_cloudapex_version = ''
581
pg_cloudapex_version = \
582
'"pg_cloudapex_version":"{}"'.format(pg_cloudapex_version)
583
JSON_ZONE_INFO = ','.join([
590
pg_cloudapex_version,
593
'curl -H \'Content-Type: application/json\' -X '
594
'PUT -d \'{{{0}}}\' http://{1}:{2}/v1/zones/{3}/zoneinfo'
595
).format(JSON_ZONE_INFO, config('lcm-ip'), config('sapi-port'),
597
POST_ZONE_INFO = _exec_cmd_output(
599
'Posting Zone Information to Solutions API server failed!')
601
if 'success' in POST_ZONE_INFO:
602
log('Successfully posted Zone information to Solutions API'
434
607
def load_iptables():
436
609
Loads iptables rules to allow all PLUMgrid communication.