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

requires.py 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. # Licensed under the Apache License, Version 2.0 (the "License");
  2. # you may not use this file except in compliance with the License.
  3. # You may obtain a copy of the License at
  4. #
  5. # http://www.apache.org/licenses/LICENSE-2.0
  6. #
  7. # Unless required by applicable law or agreed to in writing, software
  8. # distributed under the License is distributed on an "AS IS" BASIS,
  9. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. # See the License for the specific language governing permissions and
  11. # limitations under the License.
  12. from charms.reactive import set_flag, clear_flag
  13. from charms.reactive import Endpoint
  14. from charms.reactive import when_not, when
  15. class CellRequires(Endpoint):
  16. @when('endpoint.{endpoint_name}.changed')
  17. def data_changed(self):
  18. """Set flag to indicate to charm relation data has changed."""
  19. if self.all_joined_units.received.get('network_manager'):
  20. set_flag(self.expand_name('{endpoint_name}.available'))
  21. @when_not('endpoint.{endpoint_name}.joined')
  22. def broken(self):
  23. """Remove flag to indicate to charm relation has gone.."""
  24. clear_flag(self.expand_name('{endpoint_name}.available'))
  25. @when('endpoint.{endpoint_name}.joined')
  26. def joined(self):
  27. """Set flag to indicate to charm relation has been joined."""
  28. set_flag(self.expand_name('{endpoint_name}.connected'))
  29. def send_cell_data(self, cell_name, amqp_svc_name, db_svc_name):
  30. """Send compute nodes data relating to network setup.
  31. :param cell_name: Name of the cell this controller is associated with.
  32. :type cell_name: str
  33. :param amqp_svc_name: URL for this cells nova message broker.
  34. :type amqp_svc_name: str
  35. :param db_svc_name: URL for this cells nova db.
  36. :type db_svc_name: str
  37. """
  38. for relation in self.relations:
  39. relation.to_publish_raw['amqp-service'] = amqp_svc_name
  40. relation.to_publish_raw['db-service'] = db_svc_name
  41. relation.to_publish_raw['cell-name'] = cell_name
  42. def get_settings(self, keys):
  43. """Retrieve setting(s) from remote units.
  44. :param keys: List of keys and their vaules to retrieve.
  45. :type keys: str
  46. :returns: Requested key value pairs.
  47. :rtype: dict
  48. """
  49. settings = {}
  50. for key in keys:
  51. settings[key] = self.all_joined_units.received.get(key)
  52. return settings
  53. def get_console_data(self):
  54. """Retrieve console settings from remote application.
  55. :returns: console settings
  56. :rtype: dict
  57. """
  58. return self.get_settings(
  59. ['enable_serial_console', 'serial_console_base_url'])
  60. def get_network_data(self):
  61. """Retrieve network settings from remote application.
  62. :returns: network settings
  63. :rtype: dict
  64. """
  65. return self.get_settings(
  66. ['network_manager', 'quantum_plugin', 'quantum_security_groups',
  67. 'quantum_url'])
  68. def get_region(self):
  69. """Retrieve region settings from remote application.
  70. :returns: region settings
  71. :rtype: dict
  72. """
  73. return self.get_settings(['region'])
  74. def get_volume_data(self):
  75. """Retrieve volume settings from remote application.
  76. :returns: volume settings
  77. :rtype: dict
  78. """
  79. return self.get_settings(['volume_service'])
  80. def get_ec2_data(self):
  81. """Retrieve ec2 settings from remote application.
  82. :returns: ec2 settings
  83. :rtype: dict
  84. """
  85. return self.get_settings(['ec2_host'])
  86. def get_restart_trigger(self):
  87. """Retrieve restart trigger from remote application.
  88. :returns: restart trigger
  89. :rtype: dict
  90. """
  91. return self.get_settings(['restart_trigger'])