Commit 8575ca71 authored by Christos Stavrakakis's avatar Christos Stavrakakis
Browse files

cyclades: Handle 'drained' flag of networks

* Export 'SNF:DRAINED' status for drained networks.
* Do not allow creation of new ports in drained networks.
* Do not allow allocation of new IPs in drained networks.
parent a62b7257
......@@ -163,12 +163,13 @@ def network_to_dict(network, detail=True):
d = {'id': str(network.id), 'name': network.name}
d['links'] = util.network_to_links(network.id)
if detail:
state = "SNF:DRAINED" if network.drained else network.state
d['user_id'] = network.userid
d['tenant_id'] = network.userid
d['type'] = network.flavor
d['updated'] = api.utils.isoformat(network.updated)
d['created'] = api.utils.isoformat(network.created)
d['status'] = network.state
d['status'] = state
d['public'] = network.public
d['external_router'] = network.external_router
d['admin_state_up'] = True
......
......@@ -46,6 +46,10 @@ def allocate_ip(network, userid, address=None, floating_ip=False):
if network.action == "DESTROY":
raise faults.Conflict("Cannot allocate IP. Network %s is being"
" deleted" % network.id)
elif network.drained:
raise faults.Conflict("Can not allocate IP while network '%s' is in"
" 'SNF:DRAINED' status" % network.id)
ip_pools = IPPoolTable.objects.select_for_update()\
.filter(subnet__network=network)
try:
......
......@@ -401,11 +401,15 @@ def _create_port(userid, network, machine=None, use_ipaddress=None,
"""
if network.state != "ACTIVE":
raise faults.BuildInProgress("Cannot create port while network is in"
" state %s" % network.state)
if network.action == "DESTROY":
raise faults.Conflict("Cannot create port while network '%s' is in"
" '%s' status" % (network.id, network.state))
elif network.drained:
raise faults.Conflict("Cannot create port while network %s is in"
" 'SNF:DRAINED' status" % network.id)
elif network.action == "DESTROY":
msg = "Cannot create port. Network %s is being deleted."
raise faults.Conflict(msg % network.id)
ipaddress = None
if use_ipaddress is not None:
# Use an existing IPAddress object.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment