Add adapters

This commit is contained in:
Liam Young 2020-03-12 13:27:12 +00:00
parent 829ce1042c
commit 60fad9e883
8 changed files with 60 additions and 19 deletions

View File

@ -9,6 +9,7 @@ git submodule update
(cd lib; ln -s ../mod/operator/ops;)
(cd lib; ln -s ../mod/interface-ceph-client/interface_ceph_client.py;)
(cd lib; ln -s ../mod/ops-openstack/ops_openstack.py)
(cd lib; ln -s ../mod/ops-openstack/adapters.py)
(cd mod/interface-ceph-client; git pull origin master)
(cd mod/operator; git pull origin master)
(cd mod/ops-openstack; git pull origin master)

@ -1 +1 @@
Subproject commit 67254df6458e78e53f0f85ce80c1af3d7cff3205
Subproject commit 6620d0d18e82f02401203ab29ea3712f93031989

@ -1 +1 @@
Subproject commit e8903fbe58fe76d23db9bebe0647fb9707a93460
Subproject commit 3c1ba3c3f2a25e92ac2d900448fba9e6714fd32c

View File

@ -18,11 +18,56 @@ import charmhelpers.core.templating as ch_templating
import interface_ceph_client
import interface_ceph_iscsi_peer
import adapters
import ops_openstack
logger = logging.getLogger()
class CephClientAdapter(adapters.OpenStackOperRelationAdapter):
def __init__(self, relation):
super(CephClientAdapter, self).__init__(relation)
@property
def mon_hosts(self):
hosts = self.relation.get_relation_data()['mon_hosts']
return ' '.join(sorted(hosts))
@property
def auth_supported(self):
return self.relation.get_relation_data()['auth']
@property
def key(self):
return self.relation.get_relation_data()['key']
class PeerAdapter(adapters.OpenStackOperRelationAdapter):
def __init__(self, relation):
super(PeerAdapter, self).__init__(relation)
class GatewayClientPeerAdapter(PeerAdapter):
def __init__(self, relation):
super(GatewayClientPeerAdapter, self).__init__(relation)
@property
def gw_hosts(self):
hosts = self.relation.peer_addresses
return ' '.join(sorted(hosts))
class CephISCSIGatewayAdapters(adapters.OpenStackRelationAdapters):
relation_adapters = {
'ceph-client': CephClientAdapter,
'cluster': GatewayClientPeerAdapter,
}
class GatewayClient():
def run(self, path, cmd):
@ -85,14 +130,17 @@ class CephISCSIGatewayCharm(ops_openstack.OSBaseCharm):
def __init__(self, framework, key):
super().__init__(framework, key)
self.state.set_default(target_created=False)
self.framework.observe(self.on.ceph_client_relation_joined, self)
self.ceph_client = interface_ceph_client.CephClientRequires(
self,
'ceph-client')
self.framework.observe(self.ceph_client.on.pools_available, self)
self.peers = interface_ceph_iscsi_peer.CephISCSIGatewayPeers(
self,
'cluster')
self.adapters = CephISCSIGatewayAdapters(
(self.ceph_client, self.peers),
self)
self.framework.observe(self.on.ceph_client_relation_joined, self)
self.framework.observe(self.ceph_client.on.pools_available, self)
self.framework.observe(self.peers.on.has_peers, self)
self.framework.observe(self.peers.on.ready_peers, self)
self.framework.observe(self.on.create_target_action, self)
@ -172,15 +220,6 @@ class CephISCSIGatewayCharm(ops_openstack.OSBaseCharm):
logging.info("Defering setup")
event.defer()
return
ceph_context = {
'use_syslog':
str(self.framework.model.config['use-syslog']).lower(),
'loglevel': self.framework.model.config['loglevel'],
'admin_password': self.peers.admin_password,
}
ceph_context.update(self.ceph_client.get_pool_data())
ceph_context['mon_hosts'] = ' '.join(ceph_context['mon_hosts'])
ceph_context['gw_hosts'] = ' '.join(sorted(self.peers.peer_addresses))
def daemon_reload_and_restart(service_name):
subprocess.check_call(['systemctl', 'daemon-reload'])
@ -195,7 +234,7 @@ class CephISCSIGatewayCharm(ops_openstack.OSBaseCharm):
ch_templating.render(
os.path.basename(config_file),
config_file,
ceph_context)
self.adapters)
logging.info("Rendering config")
render_configs()
logging.info("Setting started state")

View File

@ -1,3 +1,3 @@
[client.ceph-iscsi]
key = {{ key }}
key = {{ ceph_client.key }}

View File

@ -4,8 +4,8 @@
# local changes will be overwritten.
###############################################################################
[global]
auth_supported = {{ auth_supported }}
mon host = {{ mon_hosts }}
auth supported = {{ ceph_client.auth_supported }}
mon host = {{ ceph_client.mon_hosts }}
keyring = /etc/ceph/$cluster.$name.keyring
[client.ceph-iscsi]

View File

@ -25,8 +25,8 @@ gateway_keyring = ceph.client.ceph-iscsi.keyring
# # To support the API, the bear minimum settings are:
api_secure = false
api_user = admin
api_password = {{ admin_password }}
api_password = {{ cluster.admin_password }}
api_port = 5000
trusted_ip_list = {{ gw_hosts }}
trusted_ip_list = {{ cluster.gw_hosts }}
#
#

View File

@ -9,6 +9,7 @@ Todo
* Certificates interface
* security checklist
* zaza tests for pause/resume
* Ceph haeartbeat settings https://docs.ceph.com/docs/master/rbd/iscsi-requirements/
Mostly Done
* trusted_ips