Juju Charm - Mistral workflow service
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
2.7KB

  1. # Copyright 2016 Canonical Ltd
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. import subprocess
  15. import charms_openstack.charm as charm
  16. import charms.reactive as reactive
  17. # This charm's library contains all of the handler code associated with
  18. # sdn_charm
  19. import charm.openstack.mistral as mistral # noqa
  20. charm.use_defaults(
  21. 'charm.installed',
  22. 'amqp.connected',
  23. 'shared-db.connected',
  24. 'identity-service.connected',
  25. 'identity-service.available', # enables SSL support
  26. 'config.changed',
  27. 'update-status')
  28. def horrible_hack_to_workaround_missing_package_files():
  29. import tarfile
  30. import shutil
  31. resource_tar = 'files/resources.tar'
  32. archive = tarfile.open(resource_tar)
  33. archive.extractall('/usr/lib/python2.7/dist-packages/mistral')
  34. shutil.copyfile(
  35. 'files/mapping.json',
  36. '/usr/lib/python2.7/dist-packages/mistral/actions/openstack/mapping.json')
  37. @reactive.when('charm.installed')
  38. @reactive.when_not('config.rendered')
  39. def mask_svc():
  40. mistral_svcs = ['mistral-api', 'mistral-engine', 'mistral-executor']
  41. for svc in mistral_svcs:
  42. subprocess.check_call(['systemctl', 'stop', svc])
  43. subprocess.check_call(['systemctl', 'mask', svc])
  44. @reactive.when('config.rendered')
  45. def unmask_svc():
  46. mistral_svcs = ['mistral-api', 'mistral-engine', 'mistral-executor']
  47. for svc in mistral_svcs:
  48. subprocess.check_call(['systemctl', 'unmask', svc])
  49. subprocess.check_call(['systemctl', 'start', svc])
  50. @reactive.when('shared-db.available')
  51. @reactive.when('identity-service.available')
  52. @reactive.when('amqp.available')
  53. def render_config(*args):
  54. """Render the configuration for charm when all the interfaces are
  55. available.
  56. """
  57. horrible_hack_to_workaround_missing_package_files()
  58. with charm.provide_charm_instance() as charm_class:
  59. charm_class.render_with_interfaces(args)
  60. charm_class.db_sync()
  61. charm_class.upgrade_if_available(args)
  62. charm_class.assess_status()
  63. reactive.set_state('config.rendered')
  64. @reactive.when('ha.connected')
  65. def cluster_connected(hacluster):
  66. """Configure HA resources in corosync"""
  67. with charm.provide_charm_instance() as charm_class:
  68. charm_class.configure_ha_resources(hacluster)
  69. charm_class.assess_status()