diff --git a/actions.yaml b/actions.yaml index c33671a..39d0036 100644 --- a/actions.yaml +++ b/actions.yaml @@ -1,8 +1,8 @@ restart-pg: description: Restart the plumgrid-director unit's service. -post-ips: +sapi-post-ips: description: Post PLUMgrid nodes IPs to Solutions API server. -post-zone-info: +sapi-post-zone-info: description: Post Zone info to Solutions API server. -post-license: +sapi-post-license: description: Post PLUMgrid License to Solutions API server. diff --git a/actions/actions.py b/actions/actions.py index f1163d5..67068e5 100755 --- a/actions/actions.py +++ b/actions/actions.py @@ -44,8 +44,8 @@ def post_license(args): # A dictionary of all the defined actions to callables (which take # parsed arguments). -ACTIONS = {"restart-pg": restart_pg, "post-ips": post_ips, "post-zone-info": post_zone_info, - "post-license": post_license} +ACTIONS = {"restart-pg": restart_pg, "sapi-post-ips": post_ips, "sapi-post-zone-info": post_zone_info, + "sapi-post-license": post_license} def main(args): diff --git a/actions/post-ips b/actions/sapi-post-ips similarity index 100% rename from actions/post-ips rename to actions/sapi-post-ips diff --git a/actions/post-license b/actions/sapi-post-license similarity index 100% rename from actions/post-license rename to actions/sapi-post-license diff --git a/actions/post-zone-info b/actions/sapi-post-zone-info similarity index 100% rename from actions/post-zone-info rename to actions/sapi-post-zone-info diff --git a/config.yaml b/config.yaml index 9b9dea1..1a3a15a 100644 --- a/config.yaml +++ b/config.yaml @@ -67,3 +67,9 @@ options: default: pgzone type: string description: Zone name used by Solutions API to get/post cloud information. + openstack-release: + default: kilo + type: string + description: | + OpenStack release to determine solution version that will be posted to + Solutions API server. diff --git a/hooks/pg_dir_hooks.py b/hooks/pg_dir_hooks.py index 88a13a0..020f3f4 100755 --- a/hooks/pg_dir_hooks.py +++ b/hooks/pg_dir_hooks.py @@ -160,7 +160,6 @@ def config_changed(): for rid in relation_ids('plumgrid'): plumgrid_joined(rid) stop_pg() - # TODO if (charm_config.changed('sapi-port') or charm_config.changed('lcm-ip') or charm_config.changed('sapi-zone')): diff --git a/hooks/pg_dir_utils.py b/hooks/pg_dir_utils.py index 9839d08..6993613 100644 --- a/hooks/pg_dir_utils.py +++ b/hooks/pg_dir_utils.py @@ -62,6 +62,14 @@ OPS_CONF = '%s/conf/etc/00-pg.conf' % PG_LXC_DATA_PATH AUTH_KEY_PATH = '%s/root/.ssh/authorized_keys' % PG_LXC_DATA_PATH TEMP_LICENSE_FILE = '/tmp/license' +# Constant values for OpenStack releases as Canonical-Ubuntu +# doesn't have any specific solution version associated +OPENSTACK_RELEASE_VERS = { + 'kilo': '10', + 'liberty': '11', + 'mitaka': '12' +} + BASE_RESOURCE_MAP = OrderedDict([ (PG_KA_CONF, { 'services': ['plumgrid'], @@ -435,10 +443,13 @@ def sapi_post_ips(): 'PUT -d \'{{{0}}}\' http://{1}' + ':' + '{2}/v1/zones/{3}/allIps' ).format(JSON_IPS, config('lcm-ip'), config('sapi-port'), config('sapi-zone')) - if 'success' in _exec_cmd_output( + POST_ZONE_IPs = _exec_cmd_output( status, - 'No response from specified LCM IP!'): - log('Successfully posted Zone IPs to Solutions API server!') + 'Posting Zone IPs to Solutions API server failed!') + if POST_ZONE_IPs: + if 'success' in POST_ZONE_IPs: + log('Successfully posted Zone IPs to Solutions API server!') + log(POST_ZONE_IPs) def _exec_cmd_output(cmd=None, error_msg='Command exited with ERRORs', @@ -472,11 +483,14 @@ def sapi_post_license(): 'PUT -d \'{{{0}}}\' http://{1}' + ':' + '{2}/v1/zones/{3}/pgLicense' ).format(JSON_LICENSE, config('lcm-ip'), config('sapi-port'), config('sapi-zone')) - if 'success' in _exec_cmd_output( + POST_LICENSE = _exec_cmd_output( status, - 'No response from specified LCM IP!'): - log('Successfully posted license file for zone "{}"!' - .format(config('sapi-zone'))) + 'Posting PLUMgrid License to Solutions API server failed!') + if POST_LICENSE: + if 'success' in POST_LICENSE: + log('Successfully posted license file for zone "{}"!' + .format(config('sapi-zone'))) + log(POST_LICENSE) def sapi_post_zone_info(): @@ -484,9 +498,13 @@ def sapi_post_zone_info(): Posts zone information to solutions api server ''' sol_name = '"solution_name":"Ubuntu OpenStack"' - # As there is no solution version for Ubuntu OpenStack, - # so, passing a random value - sol_version = '"solution_version":"12"' + release = config('openstack-release') + for key, value in OPENSTACK_RELEASE_VERS.iteritems(): + if release == value: + sol_version = value + else: + sol_version = 10 + sol_version = '"solution_version":"{}"'.format(sol_version) pg_ons_version = _exec_cmd_output( 'dpkg -l | grep plumgrid | awk \'{print $3}\' | ' 'sed \'s/-/./\' | cut -f1 -d"-"', @@ -536,10 +554,14 @@ def sapi_post_zone_info(): 'PUT -d \'{{{0}}}\' http://{1}:{2}/v1/zones/{3}/zoneinfo' ).format(JSON_ZONE_INFO, config('lcm-ip'), config('sapi-port'), config('sapi-zone')) - if 'success' in _exec_cmd_output( + POST_ZONE_INFO = _exec_cmd_output( status, - 'No response from specified LCM IP!'): - log('Successfully posted Zone info to Solutions API server!') + 'Posting Zone Information to Solutions API server failed!') + if POST_ZONE_INFO: + if 'success' in POST_ZONE_INFO: + log('Successfully posted Zone information to Solutions API' + ' server!') + log(POST_ZONE_INFO) def load_iptables():