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