Adding PLUMgrid License Posting from charm
This commit is contained in:
parent
22e4e4c8b6
commit
ad346b736f
10
config.yaml
10
config.yaml
@ -6,7 +6,7 @@ options:
|
||||
lcm-ssh-key:
|
||||
default: 'null'
|
||||
type: string
|
||||
description: Public SSH key of PLUMgrid LCM which is running PG-Tools
|
||||
description: Public SSH key of PLUMgrid LCM which is running PG-Tools.
|
||||
network-device-mtu:
|
||||
type: string
|
||||
default: '1580'
|
||||
@ -14,8 +14,12 @@ options:
|
||||
install_sources:
|
||||
default: 'ppa:plumgrid-team/stable'
|
||||
type: string
|
||||
description: Provide the install source from where to install the PLUMgrid debs
|
||||
description: Provide the install source from where to install the PLUMgrid debs.
|
||||
install_keys:
|
||||
default: null
|
||||
type: string
|
||||
description: Provide the respective keys of the install sources
|
||||
description: Provide the respective keys of the install sources.
|
||||
plumgrid-license-key:
|
||||
default: null
|
||||
type: string
|
||||
description: Provide the PLUMgrid ONS License key.
|
||||
|
@ -28,6 +28,8 @@ from pg_dir_utils import (
|
||||
remove_iovisor,
|
||||
ensure_mtu,
|
||||
add_lcm_key,
|
||||
post_pg_license,
|
||||
remove_pg_license,
|
||||
)
|
||||
|
||||
hooks = Hooks()
|
||||
@ -45,6 +47,7 @@ def install():
|
||||
apt_install(pkg, options=['--force-yes'], fatal=True)
|
||||
load_iovisor()
|
||||
ensure_mtu()
|
||||
post_pg_license()
|
||||
add_lcm_key()
|
||||
|
||||
|
||||
@ -63,6 +66,12 @@ def config_changed():
|
||||
This hook is run when a config parameter is changed.
|
||||
It also runs on node reboot.
|
||||
'''
|
||||
if post_pg_license():
|
||||
log("PLUMgrid License Posted")
|
||||
return 1
|
||||
if add_lcm_key():
|
||||
log("PLUMgrid LCM Key added")
|
||||
return 1
|
||||
stop_pg()
|
||||
configure_sources(update=True)
|
||||
pkgs = determine_packages()
|
||||
@ -82,6 +91,7 @@ def stop():
|
||||
'''
|
||||
stop_pg()
|
||||
remove_iovisor()
|
||||
remove_pg_license()
|
||||
pkgs = determine_packages()
|
||||
for pkg in pkgs:
|
||||
apt_purge(pkg, fatal=False)
|
||||
|
@ -24,6 +24,7 @@ import subprocess
|
||||
import time
|
||||
import os
|
||||
import re
|
||||
import json
|
||||
|
||||
LXC_CONF = '/etc/libvirt/lxc.conf'
|
||||
TEMPLATES = 'templates/'
|
||||
@ -36,6 +37,8 @@ PG_HN_CONF = '%s/conf/etc/hostname' % PG_LXC_DATA_PATH
|
||||
PG_HS_CONF = '%s/conf/etc/hosts' % PG_LXC_DATA_PATH
|
||||
PG_IFCS_CONF = '%s/conf/pg/ifcs.conf' % PG_LXC_DATA_PATH
|
||||
AUTH_KEY_PATH = '%s/root/.ssh/authorized_keys' % PG_LXC_DATA_PATH
|
||||
TEMP_LICENSE_FILE = '/tmp/license'
|
||||
|
||||
|
||||
BASE_RESOURCE_MAP = OrderedDict([
|
||||
(PG_KA_CONF, {
|
||||
@ -212,3 +215,44 @@ def add_lcm_key():
|
||||
fa.write(key)
|
||||
fa.write('\n')
|
||||
fa.close()
|
||||
return 1
|
||||
|
||||
|
||||
def post_pg_license():
|
||||
'''
|
||||
Posts PLUMgrid License if it hasnt been posted already.
|
||||
'''
|
||||
key = config('plumgrid-license-key')
|
||||
if key is None:
|
||||
log('PLUMgrid License Key not specified')
|
||||
return 0
|
||||
file_write_type = 'w+'
|
||||
if os.path.isfile(TEMP_LICENSE_FILE):
|
||||
file_write_type = 'w'
|
||||
try:
|
||||
fr = open(TEMP_LICENSE_FILE, 'r')
|
||||
except IOError:
|
||||
return 0
|
||||
for line in fr:
|
||||
if key in line:
|
||||
log('Key already Posted')
|
||||
return 0
|
||||
try:
|
||||
fa = open(TEMP_LICENSE_FILE, file_write_type)
|
||||
except IOError:
|
||||
log('Error opening file to append')
|
||||
return 0
|
||||
fa.write(key)
|
||||
fa.write('\n')
|
||||
fa.close()
|
||||
LICENSE_POST_PATH = 'https://%s/0/tenant_manager/license_key' % config('plumgrid-virtual-ip')
|
||||
PG_CURL = '/var/lib/libvirt/filesystems/plumgrid/opt/pg/scripts/pg_curl.sh'
|
||||
license = {"key1": {"license": key}}
|
||||
lisence_post_cmd = [PG_CURL, '-u', 'plumgrid:plumgrid', LICENSE_POST_PATH, '-d', json.dumps(license)]
|
||||
_exec_cmd(cmd=lisence_post_cmd, error_msg='Command exited with ERRORs', fatal=False)
|
||||
return 1
|
||||
|
||||
|
||||
def remove_pg_license():
|
||||
if os.path.isfile(TEMP_LICENSE_FILE):
|
||||
os.remove(TEMP_LICENSE_FILE)
|
||||
|
@ -28,6 +28,7 @@ TO_PATCH = [
|
||||
'ensure_mtu',
|
||||
'add_lcm_key',
|
||||
'determine_packages',
|
||||
'post_pg_license'
|
||||
]
|
||||
NEUTRON_CONF_DIR = "/etc/neutron"
|
||||
|
||||
@ -55,10 +56,13 @@ class PGDirHooksTests(CharmTestCase):
|
||||
])
|
||||
self.load_iovisor.assert_called_with()
|
||||
self.ensure_mtu.assert_called_with()
|
||||
self.post_pg_license.assert_called_with()
|
||||
self.add_lcm_key.assert_called_with()
|
||||
|
||||
def test_config_changed_hook(self):
|
||||
_pkgs = ['plumgrid-lxc', 'iovisor-dkms']
|
||||
self.add_lcm_key.return_value = 0
|
||||
self.post_pg_license.return_value = 0
|
||||
self.determine_packages.return_value = [_pkgs]
|
||||
self._call_hook('config-changed')
|
||||
self.stop_pg.assert_called_with()
|
||||
@ -69,11 +73,10 @@ class PGDirHooksTests(CharmTestCase):
|
||||
])
|
||||
self.load_iovisor.assert_called_with()
|
||||
self.ensure_mtu.assert_called_with()
|
||||
self.add_lcm_key.assert_called_with()
|
||||
|
||||
self.CONFIGS.write_all.assert_called_with()
|
||||
self.restart_pg.assert_called_with()
|
||||
|
||||
|
||||
def test_stop(self):
|
||||
_pkgs = ['plumgrid-lxc', 'iovisor-dkms']
|
||||
self._call_hook('stop')
|
||||
|
Loading…
x
Reference in New Issue
Block a user