# partner consortium (www.sonata-nfv.eu).
from flask_restful import Resource
from flask import request, Response
-from emuvim.api.openstack.openstack_dummies.base_openstack_dummy import BaseOpenstackDummy
+from emuvim.api.openstack.openstack_dummies.base_openstack_dummy import \
+ BaseOpenstackDummy
from datetime import datetime
-import neutron_sfc_dummy_api as SFC
+import emuvim.api.openstack.openstack_dummies.neutron_sfc_dummy_api as SFC
import logging
import json
import uuid
except Exception as ex:
LOG.exception("Neutron: List networks exception.")
- return Response(ex.message, status=500,
+ return Response(str(ex), status=500,
mimetype='application/json')
except Exception as ex:
logging.exception("Neutron: Show network exception.")
- return Response(ex.message, status=500,
+ return Response(str(ex), status=500,
mimetype='application/json')
{"network": net.create_network_dict()}), status=201, mimetype='application/json')
except Exception as ex:
LOG.exception("Neutron: Create network excepiton.")
- return Response(ex.message, status=500,
+ return Response(str(ex), status=500,
mimetype='application/json')
except Exception as ex:
LOG.exception("Neutron: Show networks exception.")
- return Response(ex.message, status=500,
+ return Response(str(ex), status=500,
mimetype='application/json')
return Response('', status=204, mimetype='application/json')
except Exception as ex:
LOG.exception("Neutron: Delete network exception.")
- return Response(ex.message, status=500,
+ return Response(str(ex), status=500,
mimetype='application/json')
except Exception as ex:
LOG.exception("Neutron: List subnets exception.")
- return Response(ex.message, status=500,
+ return Response(str(ex), status=500,
mimetype='application/json')
except Exception as ex:
LOG.exception("Neutron: Show subnet exception.")
- return Response(ex.message, status=500,
+ return Response(str(ex), status=500,
mimetype='application/json')
except Exception as ex:
LOG.exception("Neutron: Create network excepiton.")
- return Response(ex.message, status=500,
+ return Response(str(ex), status=500,
mimetype='application/json')
except Exception as ex:
LOG.exception("Neutron: Show networks exception.")
- return Response(ex.message, status=500,
+ return Response(str(ex), status=500,
mimetype='application/json')
status=404, mimetype='application/json')
except Exception as ex:
LOG.exception("Neutron: Delete subnet exception.")
- return Response(ex.message, status=500,
+ return Response(str(ex), status=500,
mimetype='application/json')
show_port = NeutronShowPort(self.api)
return show_port.get_port(request.args.get('id'), True)
- port_list = list()
- port_dict = dict()
+ ports = self.api.compute.ports.values()
+ if len(id_list) != 0:
+ ports = filter(lambda port: port.id in id_list, ports)
+
+ device_id = request.args.get('device_id')
+ if device_id:
+ server = self.api.compute.find_server_by_name_or_id(device_id)
+ if not server:
+ raise RuntimeError("Unable to find server '%s' in order to return it's ports" % server)
+
+ ports = filter(lambda port: (
+ any(
+ filter(
+ lambda server_port_name_or_id: (
+ port.id == server_port_name_or_id or port.name == server_port_name_or_id
+ ),
+ server.port_names
+ )
+ )
+ ), ports)
- if len(id_list) == 0:
- for port in self.api.compute.ports.values():
- tmp_port_dict = port.create_port_dict(self.api.compute)
- port_list.append(tmp_port_dict)
- else:
- for port in self.api.compute.ports.values():
- if port.id in id_list:
- tmp_port_dict = port.create_port_dict(self.api.compute)
- port_list.append(tmp_port_dict)
-
- port_dict["ports"] = port_list
+ port_dict = dict()
+ port_dict["ports"] = list(map(lambda x: x.create_port_dict(self.api.compute), ports))
return Response(json.dumps(port_dict), status=200,
mimetype='application/json')
except Exception as ex:
LOG.exception("Neutron: List ports exception.")
- return Response(ex.message, status=500,
+ return Response(str(ex), status=500,
mimetype='application/json')
mimetype='application/json')
except Exception as ex:
LOG.exception("Neutron: Show port exception.")
- return Response(ex.message, status=500,
+ return Response(str(ex), status=500,
mimetype='application/json')
mimetype='application/json')
except Exception as ex:
LOG.exception("Neutron: Show port exception.")
- return Response(ex.message, status=500,
+ return Response(str(ex), status=500,
mimetype='application/json')
mimetype='application/json')
except Exception as ex:
LOG.exception("Neutron: Update port exception.")
- return Response(ex.message, status=500,
+ return Response(str(ex), status=500,
mimetype='application/json')
except Exception as ex:
LOG.exception("Neutron: Delete port exception.")
- return Response(ex.message, status=500,
+ return Response(str(ex), status=500,
mimetype='application/json')
mimetype='application/json')
except Exception as ex:
LOG.exception("Neutron: Create FloatingIP exception %s.", ex)
- return Response(ex.message, status=500,
+ return Response(str(ex), status=500,
mimetype='application/json')