commit d9cfff2e4fef9d37c7430b4d1e4f4a966c9c1ef7 Author: Michael Skalka Date: Mon Aug 6 10:12:39 2018 -0400 initial commit, fleshed out basic interface function, readme, etc diff --git a/README.md b/README.md new file mode 100644 index 0000000..20c1d82 --- /dev/null +++ b/README.md @@ -0,0 +1,32 @@ +# Overview + +Basic interface for sending Cinder subordinate backend configuration to +principle Cinder charms. + +# Usage + +## Requires + +This interface layer will set the following state: + + * `{relation_name}.connected` The relation is established, but the charm may + not have provided any backend information. + +For example, the subordinate would handle the `cinder-backend.connected` state +with something like: + +```python +@when('cinder-backend.connected') +def configure_cinder(cinder_principal): + config = {'api-endpoint': '1.2.3.4', + 'admin-username': 'admin', + 'admin-password': 'openstack', + 'api-version': '1.0'} + cinder_principle.configure_principal( + backend_name='my_backend', configuration=config) +``` + + +# Contact Information + +- diff --git a/interface.yaml b/interface.yaml new file mode 100644 index 0000000..fd2a39c --- /dev/null +++ b/interface.yaml @@ -0,0 +1,4 @@ +name: cinder-backend +summary: OpenStack Cinder backend interface +version: 1 +repo: https://github.com/mskalka/interface-cinder-backend diff --git a/provides.py b/provides.py new file mode 100644 index 0000000..fff78f3 --- /dev/null +++ b/provides.py @@ -0,0 +1,44 @@ +#!/usr/bin/python + +import json + +from charms.reactive import RelationBase +from charms.reactive import hook +from charms.reactive import scopes + + +class CinderBackendProvides(RelationBase): + + scope = scopes.GLOBAL + + @hook('{provides:cinder-backend}-relation-joined') + def cinder_backend_joined(self): + conv = self.conversation() + conv.set_state('{relation_name}.joined') + self.set_state('{relation_name}.connected') + self.set_state('{relation_name}.available') + + @hook('{provides:cinder-backend}-relation-{broken, departed}') + def cinder_backend_departed(self): + conv = self.conversation() + conv.remove_state('{relation_name}.joined') + self.remove_state('{relation_name}.available') + self.remove_state('{relation_name}.connected') + conv.set_state('{relation_name}.departing') + + def configure_principal(self, backend_name, configuration): + """Send principle cinder-backend information""" + conv = self.conversation() + + subordinate_configuration = { + "cinder": { + "/etc/cinder/cinder.conf": { + "sections": { + backend_name: configuration + } + } + } + } + + conv.set_remote(backend_name=backend_name + subordinate_configuration=configuration)