blob: 380da81ec10ec73cc6bc185dae4aca806448a6ac [file] [log] [blame]
Murat Parlakisik638c65f2017-05-31 11:10:24 +03001sync_attributes = ("private_ip", "private_mac",
2 "nat_ip", "nat_mac", "ceilometer_enable_pub_sub")
3
4def 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
12def 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
28def nat_ip(self):
29 return self.addresses.get("nat", (None, None))[0]
30
31@property
32def nat_mac(self):
33 return self.addresses.get("nat", (None, None))[1]
34
35@property
36def private_ip(self):
37 return self.addresses.get("private", (None, None))[0]
38
39@property
40def private_mac(self):
41 return self.addresses.get("private", (None, None))[1]
42
43def 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
53def 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
61def ceilometer_pub_sub_url(self, value):
62 self.set_attribute("ceilometer_pub_sub_url", value)
63
64@property
65def ceilometer_enable_pub_sub(self):
66 return self.get_attribute("ceilometer_enable_pub_sub", False)
67
68@ceilometer_enable_pub_sub.setter
69def ceilometer_enable_pub_sub(self, value):
70 self.set_attribute("ceilometer_enable_pub_sub", value)
71
72@property
73def 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
82def ceilometer_admin_user(self):
83 if not self.get_instance():
84 return self.get_controller().admin_user
85 return 'admin'
86
87@property
88def ceilometer_admin_password(self):
89 if not self.get_instance():
90 return self.get_controller().admin_password
91 return 'password'
92
93@property
94def ceilometer_admin_tenant(self):
95 if not self.get_instance():
96 return self.get_controller().admin_tenant
97 return 'admin'
98
99@property
100def ceilometer_rabbit_compute_node(self):
101 if not self.get_instance():
102 return None
103 return self.get_instance().node.name
104
105@property
106def ceilometer_rabbit_host(self):
107 if not self.get_instance():
108 return None
109 return self.nat_ip
110
111@property
112def ceilometer_rabbit_user(self):
113 if not self.get_instance():
114 return None
115 return 'openstack'
116
117@property
118def ceilometer_rabbit_password(self):
119 if not self.get_instance():
120 return None
121 return 'password'
122
123@property
124def 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
132def 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
139def delete(self, *args, **kwargs):
140 instance = self.get_instance()
141 if instance:
142 instance.delete()
143 super(CeilometerService, self).delete(*args, **kwargs)