Murat Parlakisik | 638c65f | 2017-05-31 11:10:24 +0300 | [diff] [blame^] | 1 | sync_attributes = ("private_ip", "private_mac", |
| 2 | "nat_ip", "nat_mac", "ceilometer_enable_pub_sub") |
| 3 | |
| 4 | def get_instance(self): |
| 5 | for slice in self.slices.all(): |
| 6 | for instance in slice.instances.all(): |
| 7 | if instance.image.name in self.LOOK_FOR_IMAGES: |
| 8 | return instance |
| 9 | return None |
| 10 | |
| 11 | @property |
| 12 | def addresses(self): |
| 13 | if (not self.id) or (not self.get_instance()): |
| 14 | return {} |
| 15 | |
| 16 | addresses = {} |
| 17 | for ns in self.get_instance().ports.all(): |
| 18 | if "private" in ns.network.name.lower(): |
| 19 | addresses["private"] = (ns.ip, ns.mac) |
| 20 | elif ("nat" in ns.network.name.lower()) or ("management" in ns.network.name.lower()): |
| 21 | addresses["nat"] = (ns.ip, ns.mac) |
| 22 | #TODO: Do we need this client_access_network. Revisit in VTN context |
| 23 | #elif "ceilometer_client_access" in ns.network.labels.lower(): |
| 24 | # addresses["ceilometer"] = (ns.ip, ns.mac) |
| 25 | return addresses |
| 26 | |
| 27 | @property |
| 28 | def nat_ip(self): |
| 29 | return self.addresses.get("nat", (None, None))[0] |
| 30 | |
| 31 | @property |
| 32 | def nat_mac(self): |
| 33 | return self.addresses.get("nat", (None, None))[1] |
| 34 | |
| 35 | @property |
| 36 | def private_ip(self): |
| 37 | return self.addresses.get("private", (None, None))[0] |
| 38 | |
| 39 | @property |
| 40 | def private_mac(self): |
| 41 | return self.addresses.get("private", (None, None))[1] |
| 42 | |
| 43 | def get_controller(self): |
| 44 | if not self.slices.count: |
| 45 | raise XOSConfigurationError("The service has no slices") |
| 46 | cslice = self.slices.all()[0].controllerslices.all()[0] |
| 47 | controller = cslice.controller |
| 48 | if not controller: |
| 49 | raise XOSConfigurationError("The service slice has no controller") |
| 50 | return controller |
| 51 | |
| 52 | @property |
| 53 | def ceilometer_pub_sub_url(self): |
| 54 | if not self.get_instance(): |
| 55 | return self.get_attribute("ceilometer_pub_sub_url", None) |
| 56 | if not self.private_ip: |
| 57 | return None |
| 58 | return "http://" + self.private_ip + ":4455/" |
| 59 | |
| 60 | @ceilometer_pub_sub_url.setter |
| 61 | def ceilometer_pub_sub_url(self, value): |
| 62 | self.set_attribute("ceilometer_pub_sub_url", value) |
| 63 | |
| 64 | @property |
| 65 | def ceilometer_enable_pub_sub(self): |
| 66 | return self.get_attribute("ceilometer_enable_pub_sub", False) |
| 67 | |
| 68 | @ceilometer_enable_pub_sub.setter |
| 69 | def ceilometer_enable_pub_sub(self, value): |
| 70 | self.set_attribute("ceilometer_enable_pub_sub", value) |
| 71 | |
| 72 | @property |
| 73 | def ceilometer_auth_url(self): |
| 74 | #FIXME: Crude way to determine if monitoring service is getting deployed with its own ceilometer+keystone |
| 75 | if not self.get_instance(): |
| 76 | return self.get_controller().auth_url |
| 77 | if not self.private_ip: |
| 78 | return None |
| 79 | return "http://" + self.private_ip + ":5000/v2.0" |
| 80 | |
| 81 | @property |
| 82 | def ceilometer_admin_user(self): |
| 83 | if not self.get_instance(): |
| 84 | return self.get_controller().admin_user |
| 85 | return 'admin' |
| 86 | |
| 87 | @property |
| 88 | def ceilometer_admin_password(self): |
| 89 | if not self.get_instance(): |
| 90 | return self.get_controller().admin_password |
| 91 | return 'password' |
| 92 | |
| 93 | @property |
| 94 | def ceilometer_admin_tenant(self): |
| 95 | if not self.get_instance(): |
| 96 | return self.get_controller().admin_tenant |
| 97 | return 'admin' |
| 98 | |
| 99 | @property |
| 100 | def ceilometer_rabbit_compute_node(self): |
| 101 | if not self.get_instance(): |
| 102 | return None |
| 103 | return self.get_instance().node.name |
| 104 | |
| 105 | @property |
| 106 | def ceilometer_rabbit_host(self): |
| 107 | if not self.get_instance(): |
| 108 | return None |
| 109 | return self.nat_ip |
| 110 | |
| 111 | @property |
| 112 | def ceilometer_rabbit_user(self): |
| 113 | if not self.get_instance(): |
| 114 | return None |
| 115 | return 'openstack' |
| 116 | |
| 117 | @property |
| 118 | def ceilometer_rabbit_password(self): |
| 119 | if not self.get_instance(): |
| 120 | return None |
| 121 | return 'password' |
| 122 | |
| 123 | @property |
| 124 | def ceilometer_rabbit_uri(self): |
| 125 | if not self.get_instance(): |
| 126 | return None |
| 127 | if not self.private_ip: |
| 128 | return None |
| 129 | return 'rabbit://openstack:password@' + self.private_ip + ':5672' |
| 130 | |
| 131 | @property |
| 132 | def kafka_url(self): |
| 133 | if not self.get_instance(): |
| 134 | return None |
| 135 | if not self.private_ip: |
| 136 | return None |
| 137 | return 'kafka://' + self.private_ip + ':9092' |
| 138 | |
| 139 | def delete(self, *args, **kwargs): |
| 140 | instance = self.get_instance() |
| 141 | if instance: |
| 142 | instance.delete() |
| 143 | super(CeilometerService, self).delete(*args, **kwargs) |