From 38b99826ad04a1050503a7401a9b881607298380 Mon Sep 17 00:00:00 2001 From: Bilal Baqar Date: Mon, 17 Aug 2015 06:30:36 -0700 Subject: [PATCH] Improved PLUMgrid License Posting --- README.ex | 4 ++++ hooks/pg_dir_hooks.py | 2 -- hooks/pg_dir_utils.py | 45 ++++++++++++++++--------------------------- 3 files changed, 21 insertions(+), 30 deletions(-) diff --git a/README.ex b/README.ex index fc08251..a0ebbe1 100644 --- a/README.ex +++ b/README.ex @@ -41,6 +41,10 @@ Provide the source repo path for PLUMgrid Debs in 'install_sources' and the corr You can access the PG Console at https://192.168.100.250 +In order to configure networking, PLUMgrid License needs to be posted. + + juju set plumgrid-director plumgrid-license-key="$LICENSE_KEY" + # Contact Information Bilal Baqar diff --git a/hooks/pg_dir_hooks.py b/hooks/pg_dir_hooks.py index 0d194a7..aaab4f5 100755 --- a/hooks/pg_dir_hooks.py +++ b/hooks/pg_dir_hooks.py @@ -29,7 +29,6 @@ from pg_dir_utils import ( ensure_mtu, add_lcm_key, post_pg_license, - remove_pg_license, ) hooks = Hooks() @@ -91,7 +90,6 @@ def stop(): ''' stop_pg() remove_iovisor() - remove_pg_license() pkgs = determine_packages() for pkg in pkgs: apt_purge(pkg, fatal=False) diff --git a/hooks/pg_dir_utils.py b/hooks/pg_dir_utils.py index 9afd485..5d218fc 100644 --- a/hooks/pg_dir_utils.py +++ b/hooks/pg_dir_utils.py @@ -29,6 +29,7 @@ import json LXC_CONF = '/etc/libvirt/lxc.conf' TEMPLATES = 'templates/' PG_LXC_DATA_PATH = '/var/lib/libvirt/filesystems/plumgrid-data' +PG_LXC_PATH = '/var/lib/libvirt/filesystems/plumgrid' PG_CONF = '%s/conf/pg/plumgrid.conf' % PG_LXC_DATA_PATH PG_KA_CONF = '%s/conf/etc/keepalived.conf' % PG_LXC_DATA_PATH @@ -226,33 +227,21 @@ def post_pg_license(): 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' + PG_VIP = config('plumgrid-virtual-ip') + LICENSE_POST_PATH = 'https://%s/0/tenant_manager/license_key' % PG_VIP + LICENSE_GET_PATH = 'https://%s/0/tenant_manager/licenses' % PG_VIP + PG_CURL = '%s/opt/pg/scripts/pg_curl.sh' % PG_LXC_PATH 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) + licence_post_cmd = [PG_CURL, '-u', 'plumgrid:plumgrid', LICENSE_POST_PATH, '-d', json.dumps(license)] + licence_get_cmd = [PG_CURL, '-u', 'plumgrid:plumgrid', LICENSE_GET_PATH] + try: + old_license = subprocess.check_output(licence_get_cmd) + except subprocess.CalledProcessError: + log('Virtual IP Changed') + return 0 + _exec_cmd(cmd=licence_post_cmd, error_msg='Unable to post License', fatal=False) + new_license = subprocess.check_output(licence_get_cmd) + if old_license == new_license: + log('PLUMgrid License already posted') + return 0 return 1 - - -def remove_pg_license(): - if os.path.isfile(TEMP_LICENSE_FILE): - os.remove(TEMP_LICENSE_FILE)