Revision 86961519 snf-cyclades-app/synnefo/api/ports.py
b/snf-cyclades-app/synnefo/api/ports.py | ||
---|---|---|
31 | 31 |
# interpreted as representing official policies, either expressed |
32 | 32 |
# or implied, of GRNET S.A. |
33 | 33 |
|
34 |
from django.conf import settings |
|
34 |
#from django.conf import settings
|
|
35 | 35 |
from django.conf.urls import patterns |
36 | 36 |
from django.http import HttpResponse |
37 | 37 |
from django.utils import simplejson as json |
... | ... | |
41 | 41 |
from snf_django.lib import api |
42 | 42 |
|
43 | 43 |
from synnefo.api import util |
44 |
from synnefo.db.models import NetworkInterface, SecurityGroup, IPAddress
|
|
44 |
from synnefo.db.models import NetworkInterface |
|
45 | 45 |
from synnefo.logic import ports |
46 | 46 |
|
47 | 47 |
from logging import getLogger |
... | ... | |
81 | 81 |
log.debug('list_ports detail=%s', detail) |
82 | 82 |
|
83 | 83 |
user_ports = NetworkInterface.objects.filter( |
84 |
network__userid=request.user_uniq)
|
|
84 |
machine__userid=request.user_uniq)
|
|
85 | 85 |
|
86 | 86 |
port_dicts = [port_to_dict(port, detail) |
87 | 87 |
for port in user_ports.order_by('id')] |
... | ... | |
110 | 110 |
if network.public: |
111 | 111 |
raise api.faults.Forbidden('forbidden') |
112 | 112 |
|
113 |
vm = util.get_vm(dev_id, user_id) |
|
113 |
vm = util.get_vm(dev_id, user_id, non_deleted=True, non_suspended=True)
|
|
114 | 114 |
|
115 | 115 |
name = api.utils.get_attribute(port_dict, "name", required=False) |
116 |
|
|
117 | 116 |
if name is None: |
118 | 117 |
name = "" |
119 | 118 |
|
... | ... | |
179 | 178 |
@transaction.commit_on_success |
180 | 179 |
def delete_port(request, port_id): |
181 | 180 |
log.info('delete_port %s', port_id) |
182 |
port = util.get_port(port_id, request.user_uniq, for_update=True) |
|
183 |
''' |
|
184 |
FIXME delete the port |
|
185 |
skip the backend part... |
|
186 |
release the ips associated with the port |
|
187 |
''' |
|
181 |
user_id = request.user_uniq |
|
182 |
port = util.get_port(port_id, user_id, for_update=True) |
|
183 |
ports.delete(port) |
|
188 | 184 |
return HttpResponse(status=204) |
189 | 185 |
|
190 | 186 |
#util functions |
... | ... | |
193 | 189 |
def port_to_dict(port, detail=True): |
194 | 190 |
d = {'id': str(port.id), 'name': port.name} |
195 | 191 |
if detail: |
196 |
d['user_id'] = port.network.userid |
|
197 |
d['tenant_id'] = port.network.userid |
|
192 |
user_id = port.machine.id |
|
193 |
d['user_id'] = user_id |
|
194 |
d['tenant_id'] = user_id |
|
198 | 195 |
d['device_id'] = str(port.machine.id) |
196 |
# TODO: Change this based on the status of VM |
|
199 | 197 |
d['admin_state_up'] = True |
200 | 198 |
d['mac_address'] = port.mac |
201 | 199 |
d['status'] = port.state |
Also available in: Unified diff