Juju Charm - Nova Cell Controller
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.

nova_cell_controller_handlers.py 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. # Copyright 2018 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. # this is just for the reactive handlers and calls into the charm.
  15. from __future__ import absolute_import
  16. import charms.reactive as reactive
  17. import charmhelpers.core.hookenv as hookenv
  18. import charms_openstack.charm as charm
  19. from charms.reactive.relations import (
  20. endpoint_from_flag,
  21. )
  22. from charms.reactive.flags import (
  23. is_flag_set,
  24. set_flag,
  25. clear_flag,
  26. )
  27. # This charm's library contains all of the handler code associated with
  28. # nova_cell_controller -- we need to import it to get the definitions for the
  29. # charm.
  30. import charm.openstack.nova_cell_controller as nova_cell_controller # noqa
  31. # Use the charms.openstack defaults for common states and hooks
  32. charm.use_defaults(
  33. 'charm.installed',
  34. 'amqp.connected',
  35. 'shared-db.connected',
  36. 'config.changed',
  37. 'update-status')
  38. # Note that because of the way reactive.when works, (which is to 'find' the
  39. # __code__ segment of the decorated function, it's very, very difficult to add
  40. # other kinds of decorators here. This rules out adding other things into the
  41. # charm args list. It is also CPython dependent.
  42. @reactive.when('shared-db.available')
  43. @reactive.when('amqp.available')
  44. def render_stuff(*args):
  45. """Render the configuration for Nova cell controller when all the interfaces
  46. are available.
  47. """
  48. hookenv.log("about to call the render_configs with {}".format(args))
  49. with charm.provide_charm_instance() as nova_cell_controller_charm:
  50. nova_cell_controller_charm.render_with_interfaces(args)
  51. nova_cell_controller_charm.assess_status()
  52. set_flag('config.rendered')
  53. @reactive.when_not('shared-db.synced')
  54. @reactive.when('config.rendered')
  55. def db_setup(*args):
  56. with charm.provide_charm_instance() as cell_charm:
  57. cell_charm.db_sync()
  58. cell_charm.restart_all()
  59. set_flag('shared-db.synced')
  60. @reactive.when('endpoint.nova-cell-compute.changed')
  61. @reactive.when('endpoint.cloud-compute.joined')
  62. def send_compute_data():
  63. nc = endpoint_from_flag('endpoint.cloud-compute.joined')
  64. ncc_ep = endpoint_from_flag('endpoint.nova-cell-compute.changed')
  65. ncc_console_data = ncc_ep.get_console_data()
  66. ncc_network_data = ncc_ep.get_network_data()
  67. nc.set_network_data(
  68. ncc_network_data['quantum_url'],
  69. neutron_plugin=ncc_network_data['quantum_plugin'],
  70. network_manager=ncc_network_data['network_manager'],
  71. enable_security_groups=ncc_network_data['quantum_security_groups'])
  72. nc.set_console_data(
  73. serial_console_base_url=ncc_console_data['serial_console_base_url'],
  74. enable_serial_console=ncc_console_data['enable_serial_console'])
  75. nc.set_region(ncc_ep.get_region()['region'])
  76. nc.set_volume_data(ncc_ep.get_volume_data()['volume_service'])
  77. nc.set_ec2_data(ncc_ep.get_ec2_data()['ec2_host'])
  78. @reactive.when('shared-db.available')
  79. @reactive.when('amqp.available')
  80. @reactive.when('endpoint.nova-cell-compute.joined')
  81. def send_cell_data():
  82. ncc_ep = endpoint_from_flag('endpoint.nova-cell-compute.joined')
  83. amqp_conv = endpoint_from_flag('amqp.available').conversation()
  84. # Push this calculation of service names down into the interfaces
  85. amqp_service_names = [u.split('/')[0] for u in amqp_conv.units if u]
  86. db_conv = endpoint_from_flag('shared-db.available').conversation()
  87. db_service_names = [u.split('/')[0] for u in db_conv.units if u]
  88. ncc_ep.send_cell_data(
  89. hookenv.config('cell-name'),
  90. amqp_service_names[0],
  91. db_service_names[0])