Support added for metadata

This commit is contained in:
Bilal Baqar 2015-08-09 08:32:44 -07:00
parent da41392cc9
commit d82ab896f2
7 changed files with 130 additions and 30 deletions

View File

@ -11,6 +11,22 @@ from charmhelpers.core.hookenv import (
from charmhelpers.contrib.openstack import context
def _edge_settings():
'''
Inspects plumgrid-edge relation to get metadata shared secret.
'''
ctxt = {
'metadata_shared_secret': 'plumgrid',
}
for rid in relation_ids('plumgrid-plugin'):
for unit in related_units(rid):
rdata = relation_get(rid=rid, unit=unit)
if 'metadata-shared-secret' in rdata:
ctxt['metadata_shared_secret'] = \
rdata['metadata-shared-secret']
return ctxt
def _container_settings():
'''
Inspects current container relation to get keystone context.
@ -87,11 +103,16 @@ class NeutronPGPluginContext(context.NeutronContext):
return {}
conf = config()
pg_ctxt['enable_metadata'] = conf['enable-metadata']
enable_metadata = conf['enable-metadata']
pg_ctxt['enable_metadata'] = enable_metadata
pg_ctxt['pg_metadata_ip'] = '169.254.169.254'
pg_ctxt['pg_metadata_port'] = '8775'
pg_ctxt['nova_metadata_proxy_secret'] = 'plumgrid'
pg_ctxt['metadata_mode'] = 'tunnel'
if enable_metadata:
plumgrid_edge_settings = _edge_settings()
pg_ctxt['nova_metadata_proxy_secret'] = plumgrid_edge_settings['metadata_shared_secret']
else:
pg_ctxt['nova_metadata_proxy_secret'] = 'plumgrid'
neutron_api_settings = _container_settings()
pg_ctxt['admin_user'] = neutron_api_settings['service_username']

View File

@ -61,21 +61,13 @@ def config_changed():
@hooks.hook('neutron-plugin-api-relation-joined')
def neutron_plugin_api_joined():
'''
This hook is run when relation between neutron-api and
neutron-api-plumgrid is made.
'''
ensure_files()
CONFIGS.write_all()
@hooks.hook('plumgrid-plugin-relation-changed')
@hooks.hook('container-relation-changed')
@restart_on_change(restart_map())
def container_changed():
def relation_changed():
'''
This hook is run when relation between neutron-api and
neutron-api-plumgrid is changed.
This hook is run when relation between neutron-api-plumgrid and
neutron-api or plumgrid-edge is made.
'''
ensure_files()
CONFIGS.write_all()
@ -91,14 +83,6 @@ def stop():
apt_purge(pkg, fatal=False)
@hooks.hook('start')
def start():
'''
This hook is run after all relations are joined.
'''
ensure_files()
def main():
try:
hooks.execute(sys.argv)

View File

@ -0,0 +1,94 @@
#!/usr/bin/python
# Copyright (c) 2015, PLUMgrid Inc, http://plumgrid.com
# The hooks of this charm have been symlinked to functions
# in this file.
import sys
from charmhelpers.core.hookenv import (
Hooks,
UnregisteredHookError,
log,
)
from charmhelpers.core.host import (
restart_on_change,
)
from charmhelpers.fetch import (
apt_install,
apt_update,
configure_sources,
apt_purge,
)
from neutron_plumgrid_utils import (
determine_packages,
register_configs,
restart_map,
ensure_files,
)
hooks = Hooks()
CONFIGS = register_configs()
@hooks.hook()
def install():
'''
Install hook is run when the charm is first deployed on a node.
'''
configure_sources()
apt_update()
apt_install(determine_packages(), options=['--force-yes'], fatal=True)
ensure_files()
@hooks.hook('config-changed')
def config_changed():
'''
This hook is run when a config parameter is changed.
It also runs on node reboot.
'''
stop()
configure_sources()
apt_update()
apt_install(determine_packages(), options=['--force-yes'], fatal=True)
ensure_files()
CONFIGS.write_all()
@hooks.hook('neutron-plugin-api-relation-joined')
@hooks.hook('plumgrid-plugin-relation-changed')
@hooks.hook('container-relation-changed')
@restart_on_change(restart_map())
def relation_changed():
'''
This hook is run when relation between neutron-api-plumgrid and
neutron-api or plumgrid-edge is made.
'''
ensure_files()
CONFIGS.write_all()
@hooks.hook('stop')
def stop():
'''
This hook is run when the charm is destroyed.
'''
pkgs = determine_packages()
for pkg in pkgs:
apt_purge(pkg, fatal=False)
def main():
try:
hooks.execute(sys.argv)
except UnregisteredHookError as e:
log('Unknown hook {} - skipping.'.format(e))
if __name__ == '__main__':
main()

View File

@ -1 +0,0 @@
neutron_plumgrid_hooks.py

View File

@ -18,9 +18,9 @@ vapp_flag = False
# namespace for metadata won't be created on this node
[PLUMgridMetadata]
enable_pg_metadata = {{ enable_metadata }}
metadata_ip = {{ pg_metadata_ip }}
metadata_port = {{ pg_metadata_port }}
metadata_key = {{ nova_metadata_proxy_secret }}
nova_metadata_ip = {{ pg_metadata_ip }}
nova_metadata_port = {{ pg_metadata_port }}
metadata_proxy_shared_secret = {{ nova_metadata_proxy_secret }}
metadata_ns = True

View File

@ -87,5 +87,9 @@ class NeutronPGContextTest(CharmTestCase):
'service_protocol': 'http',
'auth_port': '35357',
'auth_host': '10.0.0.1',
'metadata_mode': 'tunnel',
'nova_metadata_proxy_secret': 'plumgrid',
'pg_metadata_ip': '169.254.169.254',
'pg_metadata_port': '8775',
}
self.assertEquals(expect, napi_ctxt())

View File

@ -47,8 +47,7 @@ class NeutronPGHooksTests(CharmTestCase):
self.apt_update.assert_called_with()
self.apt_install.assert_has_calls([
call(_pkgs, fatal=True,
options=['--force-yes',
'--option=Dpkg::Options::=--force-confold']),
options=['--force-yes']),
])
self.ensure_files.assert_called_with()
@ -60,8 +59,7 @@ class NeutronPGHooksTests(CharmTestCase):
self.apt_update.assert_called_with()
self.apt_install.assert_has_calls([
call(_pkgs, fatal=True,
options=['--force-yes',
'--option=Dpkg::Options::=--force-confold']),
options=['--force-yes']),
])
self.ensure_files.assert_called_with()
self.CONFIGS.write_all.assert_called_with()