36
37
from contrail_configuration_utils import (
40
contrail_floating_ip_create,
41
contrail_floating_ip_deactivate,
42
contrail_floating_ip_delete,
43
contrail_floating_ip_use,
40
45
provision_metadata,
145
def configure_floating_ip_pools():
146
floating_pools = config.get("floating-ip-pools")
147
previous_floating_pools = config_get("floating-ip-pools-prev")
148
if floating_pools != previous_floating_pools:
149
pools = { (pool["project"],
151
pool["pool-name"]): set(pool["target-projects"])
152
for pool in yaml.safe_load(floating_pools) } \
153
if floating_pools else {}
155
if previous_floating_pools:
156
for pool in yaml.safe_load(previous_floating_pools):
157
projects = pool["target-projects"]
158
name = (pool["project"], pool["network"], pool["pool-name"])
160
previous_pools[name] = set(projects)
162
floating_ip_pool_delete(name, projects)
163
for name, projects in pools.iteritems():
164
if name not in previous_pools:
165
floating_ip_pool_create(name, projects)
167
floating_ip_pool_update(name, projects, previous_pools[name])
169
config["floating-ip-pools-prev"] = floating_pools
140
171
@hooks.hook("contrail-api-relation-joined")
141
172
def contrail_api_joined():
142
173
if config_get("contrail-api-configured"):
171
202
write_ifmap_config()
172
203
service_restart("ifmap-server")
205
def floating_ip_pool_create(name, projects):
206
fq_network = "default-domain:" + ":".join(name[:2])
207
contrail_floating_ip_create(fq_network, name[2])
209
fq_pool_name = "default-domain:" + ":".join(name)
210
for project in projects:
211
fq_project = "default-domain:" + project
212
contrail_floating_ip_use(fq_project, fq_pool_name)
214
def floating_ip_pool_delete(name, projects):
215
fq_pool_name = "default-domain:" + ":".join(name)
216
for project in projects:
217
fq_project = "default-domain:" + project
218
contrail_floating_ip_deactivate(fq_project, fq_pool_name)
220
fq_network = "default-domain:" + ":".join(name[:2])
221
contrail_floating_ip_delete(fq_network, name[2])
223
def floating_ip_pool_update(name, projects, previous_projects):
224
fq_pool_name = "default-domain:" + ":".join(name)
225
for project in (previous_projects - projects):
226
fq_project = "default-domain:" + project
227
contrail_floating_ip_deactivate(fq_project, fq_pool_name)
228
for project in (projects - previous_projects):
229
fq_project = "default-domain:" + project
230
contrail_floating_ip_use(fq_project, fq_pool_name)
174
232
@hooks.hook("identity-admin-relation-changed")
175
233
def identity_admin_changed():
176
234
if not relation_get("service_hostname"):