Revision 316787ab snf-cyclades-app/synnefo/api/subnets.py
b/snf-cyclades-app/synnefo/api/subnets.py | ||
---|---|---|
88 | 88 |
|
89 | 89 |
@api.api_method(http_method='POST', user_required=True, logger=log) |
90 | 90 |
def create_subnet(request): |
91 |
""" |
|
92 |
Create a subnet |
|
91 |
"""Create a subnet |
|
93 | 92 |
network_id and the desired cidr are mandatory, everything else is optional |
93 |
|
|
94 | 94 |
""" |
95 | 95 |
dictionary = utils.get_request_dict(request) |
96 | 96 |
log.info('create subnet %s', dictionary) |
... | ... | |
150 | 150 |
|
151 | 151 |
@api.api_method(http_method='DELETE', user_required=True, logger=log) |
152 | 152 |
def delete_subnet(request, sub_id): |
153 |
""" |
|
154 |
Delete a subnet, raises BadRequest |
|
153 |
"""Delete a subnet, raises BadRequest |
|
155 | 154 |
A subnet is deleted ONLY when the network that it belongs to is deleted |
155 |
|
|
156 | 156 |
""" |
157 | 157 |
raise api.faults.BadRequest("Deletion of a subnet is not supported") |
158 | 158 |
|
159 | 159 |
|
160 | 160 |
@api.api_method(http_method='PUT', user_required=True, logger=log) |
161 | 161 |
def update_subnet(request, sub_id): |
162 |
""" |
|
163 |
Update the fields of a subnet |
|
162 |
"""Update the fields of a subnet |
|
164 | 163 |
Only the name can be updated, everything else returns BadRequest |
164 |
|
|
165 | 165 |
""" |
166 | 166 |
|
167 | 167 |
dictionary = utils.get_request_dict(request) |
... | ... | |
217 | 217 |
|
218 | 218 |
|
219 | 219 |
def string_to_ipaddr(pools): |
220 |
""" |
|
221 |
Convert [["192.168.42.1", "192.168.42.15"], |
|
222 |
["192.168.42.30", "192.168.42.60"]] |
|
220 |
"""Convert [["192.168.42.1", "192.168.42.15"], |
|
221 |
["192.168.42.30", "192.168.42.60"]] |
|
223 | 222 |
to |
224 |
[[IPv4Address('192.168.42.1'), IPv4Address('192.168.42.15')], |
|
225 |
[IPv4Address('192.168.42.30'), IPv4Address('192.168.42.60')]] |
|
223 |
[[IPv4Address('192.168.42.1'), IPv4Address('192.168.42.15')],
|
|
224 |
[IPv4Address('192.168.42.30'), IPv4Address('192.168.42.60')]]
|
|
226 | 225 |
and sort the output |
226 |
|
|
227 | 227 |
""" |
228 | 228 |
pool_list = [(map(lambda ip_str: IPAddress(ip_str), pool)) |
229 | 229 |
for pool in pools] |
... | ... | |
246 | 246 |
|
247 | 247 |
|
248 | 248 |
def get_subnet_fromdb(subnet_id, user_id, for_update=False): |
249 |
""" |
|
250 |
Return a Subnet instance or raise ItemNotFound. |
|
249 |
"""Return a Subnet instance or raise ItemNotFound. |
|
251 | 250 |
This is the same as util.get_network |
251 |
|
|
252 | 252 |
""" |
253 | 253 |
try: |
254 | 254 |
subnet_id = int(subnet_id) |
... | ... | |
262 | 262 |
|
263 | 263 |
|
264 | 264 |
def parse_ip_pools(pools): |
265 |
""" |
|
266 |
Convert [{'start': '192.168.42.1', 'end': '192.168.42.15'}, |
|
265 |
"""Convert [{'start': '192.168.42.1', 'end': '192.168.42.15'}, |
|
267 | 266 |
{'start': '192.168.42.30', 'end': '192.168.42.60'}] |
268 | 267 |
to |
269 | 268 |
[["192.168.42.1", "192.168.42.15"], |
270 | 269 |
["192.168.42.30", "192.168.42.60"]] |
270 |
|
|
271 | 271 |
""" |
272 | 272 |
pool_list = list() |
273 | 273 |
for pool in pools: |
Also available in: Unified diff