initial ceph-client commit

This commit is contained in:
Chris MacNaughton 2016-05-24 14:30:49 -04:00
commit 837ef5c9c0
2 changed files with 90 additions and 0 deletions

3
interface.yaml Normal file
View File

@ -0,0 +1,3 @@
name: ceph-client
summary: Ceph Client Interface
version: 1

87
provides.py Normal file
View File

@ -0,0 +1,87 @@
from charmhelpers.core import hookenv
from charms.reactive import RelationBase
from charms.reactive import hook
from charms.reactive import scopes
from charms.reactive import is_state
from charms.reactive import not_unless
class CephClientProvider(RelationBase):
scope = scopes.UNIT
@hook('{provides:ceph-client}-relation-{joined,changed}')
def changed(self):
self.set_state('{relation_name}.connected')
service = hookenv.remote_service_name()
conversation = self.conversation()
if conversation.get_remote('broker_req'):
self.set_state('{relation_name}.broker_requested')
def provide_auth(self, service, key, auth_supported, public_address):
"""
Provide a token to a requesting service.
:param str service: The service which requested the key
:param str key: The key to access Ceph
:param str auth_supported: Supported auth methods
:param str public_address: Ceph's public address
"""
conversation = self.conversation(scope=service)
conversation.set_remote({
'key': key,
'auth': auth_supported,
'ceph-public-address': public_address,
})
def requested_keys(self):
"""
Return a list of tuples mapping a service name to the key name
requested by that service.
Example usage::
for service, key in ceph.requested_keys():
ceph.provide_auth(service, key, auth, public_address)
"""
for conversation in self.conversations():
service = conversation.scope
key = self.requested_key(service)
yield service, key
def requested_key(self, service):
"""
Return the key provided to the requesting service.
"""
return self.conversation(scope=service).get_remote('key', '')
def provide_broker_token(self, service, unit_response_key, token):
"""
Provide a token to a requesting service.
:param str service: The service which requested the key
:param str unit_response_key: The unique key for the unit
:param str token: Broker token top provide
"""
conversation = self.conversation(scope=service)
# broker_rsp is being left for backward compatibility,
# unit_response_key superscedes it
conversation.set_remote({
'broker_rsp': token,
unit_response_key: token,
})
def requested_tokens(self):
"""
Return a list of tuples mapping a service name to the token name
requested by that service.
Example usage::
for service, token in ceph.requested_tokens():
ceph.provide_auth(service, token, auth, public_address)
"""
for conversation in self.conversations():
service = conversation.scope
token = self.requested_token(service)
yield service, token
def requested_token(self, service):
"""
Return the token provided to the requesting service.
"""
return self.conversation(scope=service).get_remote('broker_req', '')