diff --git a/README.md b/README.md new file mode 100644 index 0000000..80a66ef --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# Trustee interface + +This interface implements the trustee domain interface. You will need a version of the keystone charm that implements the trustee interface. \ No newline at end of file diff --git a/copyright b/copyright new file mode 100644 index 0000000..6b650e1 --- /dev/null +++ b/copyright @@ -0,0 +1,7 @@ +Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0 + +Files: * +Copyright: 2018, Cloudbase Solutions SRL +License: Proprietary + +License: Proprietary diff --git a/interface.yaml b/interface.yaml new file mode 100644 index 0000000..0566441 --- /dev/null +++ b/interface.yaml @@ -0,0 +1,12 @@ +name: trustee +summary: Interface for requesting the creation of trustee domains +maintainer: Gabriel Adrian Samfira +ignore: + - 'unit_tests' + - 'Makefile' + - '.testr.conf' + - 'test-requirements.txt' + - 'tox.ini' + - '.gitignore' + - '.gitreview' + - '.unit-state.db' diff --git a/requires.py b/requires.py new file mode 100644 index 0000000..ccd8b27 --- /dev/null +++ b/requires.py @@ -0,0 +1,53 @@ +#!/usr/bin/python +# Copyright 2018 Cloudbase Solutions SRL + +from charms.reactive import RelationBase +from charms.reactive import hook +from charms.reactive import scopes + + +class TrusteeRequires(RelationBase): + scope = scopes.GLOBAL + + # These remote data fields will be automatically mapped to accessors + # with a basic documentation string provided. + + auto_accessors = [ + 'domain_name', 'domain_admin_name', 'domain_admin_password'] + + @hook('{requires:trustee}-relation-joined') + def joined(self): + self.set_state('{relation_name}.connected') + self.update_state() + + def update_state(self): + if self.base_data_complete(): + self.remove_state('{relation_name}.departed') + self.set_state('{relation_name}.available') + else: + self.remove_state('{relation_name}.available') + + @hook('{requires:trustee}-relation-changed') + def changed(self): + self.update_state() + + @hook('{requires:trustee}-relation-{broken,departed}') + def departed(self): + self.remove_state('{relation_name}.available') + self.set_state('{relation_name}.departed') + + def base_data_complete(self): + data = { + "domain_name": self.domain_name(), + "domain_admin_password": self.domain_admin_password(), + "domain_admin_name": self.domain_admin_name(), + } + return all(data.values()) + + def request_domain(self, domain_name, admin_user): + relation_info = { + 'domain': domain_name, + 'username': admin_user, + } + self.set_local(**relation_info) + self.set_remote(**relation_info)