~joeborg/charms/trusty/contrail-configuration/rbac-switch

« back to all changes in this revision

Viewing changes to hooks/contrail_configuration_utils.py

  • Committer: Robert Ayres
  • Date: 2015-04-24 14:27:43 UTC
  • Revision ID: robert.ayres@canonical.com-20150424142743-3mnfmmgs50sdqysh
Add floating pool functionality

Show diffs side-by-side

added added

removed removed

Lines of Context:
92
92
    addr = gethostbyname(unit_get("private-address"))
93
93
    return { "api_port": api_port(), "ifmap_server": addr, "disc_server": addr }
94
94
 
 
95
def contrail_floating_ip_create(network, name):
 
96
    user, password, tenant = [ (relation_get("service_username", unit, rid),
 
97
                                relation_get("service_password", unit, rid),
 
98
                                relation_get("service_tenant_name", unit, rid))
 
99
                               for rid in relation_ids("identity-admin")
 
100
                               for unit in related_units(rid) ][0]
 
101
    log("Creating floating ip pool {} for network {}".format(name, network))
 
102
    check_call(["python", "/usr/share/contrail-utils/create_floating_pool.py",
 
103
                "--public_vn_name", network,
 
104
                "--floating_ip_pool_name", name,
 
105
                "--api_server_ip", "127.0.0.1",
 
106
                "--api_server_port", str(api_port()),
 
107
                "--admin_user", user,
 
108
                "--admin_password", password,
 
109
                "--admin_tenant", tenant])
 
110
 
 
111
def contrail_floating_ip_deactivate(project, name):
 
112
    user, password, tenant = [ (relation_get("service_username", unit, rid),
 
113
                                relation_get("service_password", unit, rid),
 
114
                                relation_get("service_tenant_name", unit, rid))
 
115
                               for rid in relation_ids("identity-admin")
 
116
                               for unit in related_units(rid) ][0]
 
117
    log("Deactivating floating ip pool {} for project {}".format(name, project))
 
118
    check_call(["scripts/deactivate_floating_pool.py",
 
119
                "--api_server_ip", "127.0.0.1",
 
120
                "--api_server_port", str(api_port()),
 
121
                "--admin_user", user,
 
122
                "--admin_password", password,
 
123
                "--admin_tenant", tenant,
 
124
                project, name])
 
125
 
 
126
def contrail_floating_ip_delete(network, name):
 
127
    user, password, tenant = [ (relation_get("service_username", unit, rid),
 
128
                                relation_get("service_password", unit, rid),
 
129
                                relation_get("service_tenant_name", unit, rid))
 
130
                               for rid in relation_ids("identity-admin")
 
131
                               for unit in related_units(rid) ][0]
 
132
    log("Deleting floating ip pool {} for network {}".format(name, network))
 
133
    check_call(["scripts/delete_floating_pool.py",
 
134
                "--api_server_ip", "127.0.0.1",
 
135
                "--api_server_port", str(api_port()),
 
136
                "--admin_user", user,
 
137
                "--admin_password", password,
 
138
                "--admin_tenant", tenant,
 
139
                network, name])
 
140
 
 
141
def contrail_floating_ip_use(project, name):
 
142
    user, password, tenant = [ (relation_get("service_username", unit, rid),
 
143
                                relation_get("service_password", unit, rid),
 
144
                                relation_get("service_tenant_name", unit, rid))
 
145
                               for rid in relation_ids("identity-admin")
 
146
                               for unit in related_units(rid) ][0]
 
147
    log("Activating floating ip pool {} for project {}".format(name, project))
 
148
    check_call(["python", "/usr/share/contrail-utils/use_floating_pool.py",
 
149
                "--project_name", project,
 
150
                "--floating_ip_pool_name", name,
 
151
                "--api_server_ip", "127.0.0.1",
 
152
                "--api_server_port", str(api_port()),
 
153
                "--admin_user", user,
 
154
                "--admin_password", password,
 
155
                "--admin_tenant", tenant])
 
156
 
95
157
def contrail_ifmap_ctx():
96
158
    creds = []
97
159
    unit = local_unit()