Juju Charm - Neutron Dynamic Routing
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.

91 lines
2.8 KiB

  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 charms_openstack.bus
  18. import charms_openstack.charm as charm
  19. charms_openstack.bus.discover()
  20. # Use the charms.openstack defaults for common states and hooks
  21. charm.use_defaults(
  22. 'charm.installed',
  23. 'config.changed',
  24. 'update-status',
  25. 'upgrade-charm')
  26. @reactive.when('endpoint.bgp-speaker.changed')
  27. def publish_bgp_info(endpoint):
  28. """Publish BGP information about this unit to interface-bgp peers
  29. """
  30. with charm.provide_charm_instance() as instance:
  31. if instance.get_os_codename() in ['ocata', 'pike']:
  32. use_16bit_asn = True
  33. else:
  34. use_16bit_asn = False
  35. endpoint.publish_info(passive=True,
  36. bindings=instance.bgp_speaker_bindings(),
  37. use_16bit_asn=use_16bit_asn)
  38. instance.assess_status()
  39. @reactive.when('amqp.connected')
  40. def setup_amqp_req(amqp):
  41. """Use the amqp interface to request access to the amqp broker using our
  42. local configuration.
  43. """
  44. amqp.request_access(username='neutron',
  45. vhost='openstack')
  46. with charm.provide_charm_instance() as instance:
  47. instance.assess_status()
  48. @reactive.when('amqp.available.ssl')
  49. def configure_ssl(amqp):
  50. with charm.provide_charm_instance() as instance:
  51. instance.configure_ssl()
  52. @reactive.when('charm.installed')
  53. @reactive.when_not('config.rendered')
  54. def disable_services():
  55. with charm.provide_charm_instance() as instance:
  56. instance.disable_services()
  57. instance.assess_status()
  58. @reactive.when('config.rendered')
  59. def enable_services():
  60. with charm.provide_charm_instance() as instance:
  61. instance.enable_services()
  62. instance.assess_status()
  63. @reactive.when('amqp.available')
  64. def render_configs(*args):
  65. """Render the configuration for dynamic routing when all the interfaces are
  66. available.
  67. """
  68. with charm.provide_charm_instance() as instance:
  69. instance.upgrade_if_available(args)
  70. instance.render_with_interfaces(args)
  71. reactive.set_flag('config.rendered')
  72. instance.assess_status()