| David Garcia | 009a5d6 | 2020-08-27 16:53:44 +0200 | [diff] [blame] | 1 | # Copyright 2020 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 | from charms.reactive import Endpoint |
| 15 | from charms.reactive import when |
| 16 | from charms.reactive import set_flag, clear_flag |
| 17 | |
| 18 | |
| 19 | class KeystoneProvides(Endpoint): |
| 20 | @when("endpoint.{endpoint_name}.joined") |
| 21 | def _joined(self): |
| 22 | set_flag(self.expand_name("{endpoint_name}.joined")) |
| 23 | |
| 24 | @when("endpoint.{endpoint_name}.changed") |
| 25 | def _changed(self): |
| 26 | set_flag(self.expand_name("{endpoint_name}.ready")) |
| 27 | |
| 28 | @when("endpoint.{endpoint_name}.departed") |
| 29 | def _departed(self): |
| 30 | set_flag(self.expand_name("{endpoint_name}.departed")) |
| 31 | clear_flag(self.expand_name("{endpoint_name}.joined")) |
| 32 | |
| 33 | def publish_info( |
| 34 | self, |
| 35 | host, |
| 36 | port, |
| 37 | keystone_db_password, |
| 38 | region_id, |
| 39 | user_domain_name, |
| 40 | project_domain_name, |
| 41 | admin_username, |
| 42 | admin_password, |
| 43 | admin_project_name, |
| 44 | username, |
| 45 | password, |
| 46 | service, |
| 47 | ): |
| 48 | for relation in self.relations: |
| 49 | relation.to_publish["host"] = host |
| 50 | relation.to_publish["port"] = port |
| 51 | relation.to_publish["keystone_db_password"] = keystone_db_password |
| 52 | relation.to_publish["region_id"] = region_id |
| 53 | relation.to_publish["user_domain_name"] = user_domain_name |
| 54 | relation.to_publish["project_domain_name"] = project_domain_name |
| 55 | relation.to_publish["admin_username"] = admin_username |
| 56 | relation.to_publish["admin_password"] = admin_password |
| 57 | relation.to_publish["admin_project_name"] = admin_project_name |
| 58 | relation.to_publish["username"] = username |
| 59 | relation.to_publish["password"] = password |
| 60 | relation.to_publish["service"] = service |
| 61 | |
| 62 | def mark_complete(self): |
| 63 | clear_flag(self.expand_name("{endpoint_name}.joined")) |