Matteo Scandolo | eb0d11c | 2017-08-08 13:05:26 -0700 | [diff] [blame] | 1 | |
| 2 | # Copyright 2017-present Open Networking Foundation |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | |
Murat Parlakisik | 638c65f | 2017-05-31 11:10:24 +0300 | [diff] [blame] | 17 | sync_attributes = ("private_ip", "private_mac", |
| 18 | "nat_ip", "nat_mac", "ceilometer_enable_pub_sub") |
| 19 | |
| 20 | def get_instance(self): |
| 21 | for slice in self.slices.all(): |
| 22 | for instance in slice.instances.all(): |
| 23 | if instance.image.name in self.LOOK_FOR_IMAGES: |
| 24 | return instance |
| 25 | return None |
| 26 | |
| 27 | @property |
| 28 | def addresses(self): |
| 29 | if (not self.id) or (not self.get_instance()): |
| 30 | return {} |
| 31 | |
| 32 | addresses = {} |
| 33 | for ns in self.get_instance().ports.all(): |
| 34 | if "private" in ns.network.name.lower(): |
| 35 | addresses["private"] = (ns.ip, ns.mac) |
| 36 | elif ("nat" in ns.network.name.lower()) or ("management" in ns.network.name.lower()): |
| 37 | addresses["nat"] = (ns.ip, ns.mac) |
| 38 | #TODO: Do we need this client_access_network. Revisit in VTN context |
| 39 | #elif "ceilometer_client_access" in ns.network.labels.lower(): |
| 40 | # addresses["ceilometer"] = (ns.ip, ns.mac) |
| 41 | return addresses |
| 42 | |
| 43 | @property |
| 44 | def nat_ip(self): |
| 45 | return self.addresses.get("nat", (None, None))[0] |
| 46 | |
| 47 | @property |
| 48 | def nat_mac(self): |
| 49 | return self.addresses.get("nat", (None, None))[1] |
| 50 | |
| 51 | @property |
| 52 | def private_ip(self): |
| 53 | return self.addresses.get("private", (None, None))[0] |
| 54 | |
| 55 | @property |
| 56 | def private_mac(self): |
| 57 | return self.addresses.get("private", (None, None))[1] |
| 58 | |
| 59 | def get_controller(self): |
| 60 | if not self.slices.count: |
| 61 | raise XOSConfigurationError("The service has no slices") |
| 62 | cslice = self.slices.all()[0].controllerslices.all()[0] |
| 63 | controller = cslice.controller |
| 64 | if not controller: |
| 65 | raise XOSConfigurationError("The service slice has no controller") |
| 66 | return controller |
| 67 | |
| 68 | @property |
| 69 | def ceilometer_pub_sub_url(self): |
| 70 | if not self.get_instance(): |
| 71 | return self.get_attribute("ceilometer_pub_sub_url", None) |
| 72 | if not self.private_ip: |
| 73 | return None |
| 74 | return "http://" + self.private_ip + ":4455/" |
| 75 | |
| 76 | @ceilometer_pub_sub_url.setter |
| 77 | def ceilometer_pub_sub_url(self, value): |
| 78 | self.set_attribute("ceilometer_pub_sub_url", value) |
| 79 | |
| 80 | @property |
| 81 | def ceilometer_enable_pub_sub(self): |
| 82 | return self.get_attribute("ceilometer_enable_pub_sub", False) |
| 83 | |
| 84 | @ceilometer_enable_pub_sub.setter |
| 85 | def ceilometer_enable_pub_sub(self, value): |
| 86 | self.set_attribute("ceilometer_enable_pub_sub", value) |
| 87 | |
| 88 | @property |
| 89 | def ceilometer_auth_url(self): |
| 90 | #FIXME: Crude way to determine if monitoring service is getting deployed with its own ceilometer+keystone |
| 91 | if not self.get_instance(): |
| 92 | return self.get_controller().auth_url |
| 93 | if not self.private_ip: |
| 94 | return None |
| 95 | return "http://" + self.private_ip + ":5000/v2.0" |
| 96 | |
| 97 | @property |
| 98 | def ceilometer_admin_user(self): |
| 99 | if not self.get_instance(): |
| 100 | return self.get_controller().admin_user |
| 101 | return 'admin' |
| 102 | |
| 103 | @property |
| 104 | def ceilometer_admin_password(self): |
| 105 | if not self.get_instance(): |
| 106 | return self.get_controller().admin_password |
| 107 | return 'password' |
| 108 | |
| 109 | @property |
| 110 | def ceilometer_admin_tenant(self): |
| 111 | if not self.get_instance(): |
| 112 | return self.get_controller().admin_tenant |
| 113 | return 'admin' |
| 114 | |
| 115 | @property |
| 116 | def ceilometer_rabbit_compute_node(self): |
| 117 | if not self.get_instance(): |
| 118 | return None |
| 119 | return self.get_instance().node.name |
| 120 | |
| 121 | @property |
| 122 | def ceilometer_rabbit_host(self): |
| 123 | if not self.get_instance(): |
| 124 | return None |
| 125 | return self.nat_ip |
| 126 | |
| 127 | @property |
| 128 | def ceilometer_rabbit_user(self): |
| 129 | if not self.get_instance(): |
| 130 | return None |
| 131 | return 'openstack' |
| 132 | |
| 133 | @property |
| 134 | def ceilometer_rabbit_password(self): |
| 135 | if not self.get_instance(): |
| 136 | return None |
| 137 | return 'password' |
| 138 | |
| 139 | @property |
| 140 | def ceilometer_rabbit_uri(self): |
| 141 | if not self.get_instance(): |
| 142 | return None |
| 143 | if not self.private_ip: |
| 144 | return None |
| 145 | return 'rabbit://openstack:password@' + self.private_ip + ':5672' |
| 146 | |
| 147 | @property |
| 148 | def kafka_url(self): |
| 149 | if not self.get_instance(): |
| 150 | return None |
| 151 | if not self.private_ip: |
| 152 | return None |
| 153 | return 'kafka://' + self.private_ip + ':9092' |
| 154 | |
| 155 | def delete(self, *args, **kwargs): |
| 156 | instance = self.get_instance() |
| 157 | if instance: |
| 158 | instance.delete() |
| 159 | super(CeilometerService, self).delete(*args, **kwargs) |