lots of cleanup, fixed relation handling, etc
This commit is contained in:
parent
19528a8dce
commit
7d3b847ec7
|
@ -1,2 +1,5 @@
|
|||
includes:
|
||||
- 'layer:openstack'
|
||||
- 'interface:cinder-backend'
|
||||
|
||||
repo: https://github.com/mskalka/charm-cinder-purestorage
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import json
|
||||
import subprocess
|
||||
|
||||
from charmhelpers.core.hookenv import (
|
||||
config,
|
||||
|
@ -23,20 +24,13 @@ class PureStorageCharm(OpenStackCharm):
|
|||
packages = ['']
|
||||
release = 'queens'
|
||||
|
||||
def set_relation_data(self):
|
||||
rel_id = relation_ids('storage-backend')
|
||||
if not len(rel_id):
|
||||
log("No 'storage-backend' relation detected, skipping.")
|
||||
else:
|
||||
relation_set(
|
||||
relation_id=rel_id[0],
|
||||
backend_name=config('volume-backend-name') or service_name(),
|
||||
subordinate_configuration=json.dumps(
|
||||
PureStorageSubordinateContext()()),
|
||||
stateless=True,
|
||||
)
|
||||
log('Relation data set for {}'.format(rel_id[0]))
|
||||
def install(self):
|
||||
subprocess.check_call(['pip', 'install', 'purestorage', '--no-deps'])
|
||||
|
||||
def get_purestorage_config(self):
|
||||
status_set('active', 'Unit is ready')
|
||||
name = config('volume-backend-name') or service_name()
|
||||
return name, PureStorageSubordinateContext()()
|
||||
|
||||
|
||||
class PureStorageSubordinateContext(OSContextGenerator):
|
||||
|
@ -61,16 +55,12 @@ class PureStorageSubordinateContext(OSContextGenerator):
|
|||
raise ProtocolNotImplimented(
|
||||
config('protocol'), ' is not an implimented protocol driver, '
|
||||
'please choose between `iscsi` and `fc`.')
|
||||
|
||||
for rid in relation_ids(self.interfaces[0]):
|
||||
log('Setting relation data for {}'.format(rid))
|
||||
self.related = True
|
||||
return {
|
||||
"cinder": {
|
||||
"/etc/cinder/cinder.conf": {
|
||||
"sections": {
|
||||
service: ctxt
|
||||
}
|
||||
return {
|
||||
"cinder": {
|
||||
"/etc/cinder/cinder.conf": {
|
||||
"sections": {
|
||||
service: ctxt
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,20 +5,22 @@ import charms.reactive as reactive
|
|||
import charm.openstack.cinder_purestorage as cinder_pure
|
||||
assert cinder_pure
|
||||
|
||||
charm.use_defaults('charm.installed')
|
||||
|
||||
|
||||
@reactive.when_any('storage-backend.joined', 'storage-backend.changed')
|
||||
@reactive.when_not('storage-backend.available')
|
||||
def storage_backend():
|
||||
@reactive.when_any('install')
|
||||
def install_pure_driver():
|
||||
with charm.provide_charm_instance() as charm_class:
|
||||
charm_class.set_relation_data()
|
||||
reactive.set_state('storage-backend.available')
|
||||
charm_class.install()
|
||||
|
||||
|
||||
@reactive.when('config.changed')
|
||||
@reactive.when('storage-backend.available')
|
||||
@reactive.when_not('cinder.configured')
|
||||
def storage_backend(principle):
|
||||
with charm.provide_charm_instance() as charm_class:
|
||||
name, config = charm_class.get_purestorage_config()
|
||||
principle.configure_principal(name, config)
|
||||
reactive.set_state('cinder.configured')
|
||||
|
||||
|
||||
@reactive.hook('config-changed')
|
||||
def update_config():
|
||||
reactive.remove_state('storage-backend.available')
|
||||
with charm.provide_charm_instance() as charm_class:
|
||||
charm_class.set_relation_data()
|
||||
reactive.set_state('storage-backend.available')
|
||||
reactive.remove_state('cinder.configured')
|
||||
|
|
Loading…
Reference in New Issue