Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriel-samfira committed Aug 19, 2018
0 parents commit b5abfee
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
7 changes: 7 additions & 0 deletions copyright
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions interface.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: trustee
summary: Interface for requesting the creation of trustee domains
maintainer: Gabriel Adrian Samfira <[email protected]>
ignore:
- 'unit_tests'
- 'Makefile'
- '.testr.conf'
- 'test-requirements.txt'
- 'tox.ini'
- '.gitignore'
- '.gitreview'
- '.unit-state.db'
53 changes: 53 additions & 0 deletions requires.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit b5abfee

Please sign in to comment.