
The ``nova-compute`` charm gates enablement of the local Nova metadata service on presence of the ``metadata-shared-secret`` key in the relation data in the subordinate relation with ``neutron-plugin`` interface. This is implemented in the classic ``neutron-openvswitch`` charm today. Add the bits necessary for a reactive charm to participate in this part of the relation. Also adds units tests to the interface. Change-Id: I358e60c40a7f7c0cd33b31f2b7a8c58d6cb83326
52 lines
1.5 KiB
Python
52 lines
1.5 KiB
Python
import json
|
|
import uuid
|
|
|
|
from charms.reactive import hook
|
|
from charms.reactive import RelationBase
|
|
from charms.reactive import scopes
|
|
|
|
|
|
METADATA_KEY = 'metadata-shared-secret'
|
|
|
|
|
|
class NeutronPluginProvides(RelationBase):
|
|
scope = scopes.GLOBAL
|
|
|
|
@hook('{provides:neutron-plugin}-relation-{joined,changed}')
|
|
def changed(self):
|
|
self.set_state('{relation_name}.connected')
|
|
|
|
@hook('{provides:neutron-plugin}-relation-{broken,departed}')
|
|
def broken(self):
|
|
self.remove_state('{relation_name}.connected')
|
|
|
|
def configure_plugin(self, plugin, config):
|
|
conversation = self.conversation()
|
|
relation_info = {
|
|
'neutron-plugin': plugin,
|
|
'subordinate_configuration': json.dumps(config),
|
|
}
|
|
conversation.set_remote(**relation_info)
|
|
|
|
def get_or_create_shared_secret(self):
|
|
"""Retrieves a shared secret from local unit storage.
|
|
|
|
The secret is created if it does not already exist.
|
|
|
|
:returns: Shared secret
|
|
:rtype: str
|
|
"""
|
|
secret = self.get_local(METADATA_KEY)
|
|
if secret is None:
|
|
secret = str(uuid.uuid4())
|
|
self.set_local(METADATA_KEY, secret)
|
|
return secret
|
|
|
|
def publish_shared_secret(self):
|
|
"""Publish the shared secret on the relation."""
|
|
conversation = self.conversation()
|
|
relation_info = {
|
|
METADATA_KEY: self.get_or_create_shared_secret(),
|
|
}
|
|
conversation.set_remote(**relation_info)
|