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"] = map(lambda x: x.create_port_dict(self.api.compute), ports)
return Response(json.dumps(port_dict), status=200,
mimetype='application/json')
num_ports = len(self.api.compute.ports)
name = "port:cp%s:man:%s" % (num_ports, str(uuid.uuid4()))
- if self.api.compute.find_port_by_name_or_id(name):
- return Response("Port with name %s already exists.\n" %
- name, status=500, mimetype='application/json')
-
port = self.api.compute.create_port(name)
port.net_name = net.name
def get(self):
"""
- Added a quick and dirty fake for the OSM integration. Returns a list of
- floating IPs. Has nothing to do with the setup inside the emulator.
- But its enough to make the OSM driver happy.
- @PG Sandman: Feel free to improve this and let it do something meaningful.
+ Returns a Floating IP for a port.
+
+ Currently ports are not mapped to individual IPs, but the
+ (potentially shared) Docker external IP is returned.
"""
+ port_id = request.args.get("port_id")
+ if not port_id:
+ message = "Neutron: List API for FloatingIPs is not implemented"
+ LOG.exception(message)
+ return Response(message, status=500,
+ mimetype='application/json')
+ port = self.api.compute.find_port_by_name_or_id(port_id)
+ ip = port.assigned_container.dcinfo["NetworkSettings"]["IPAddress"]
resp = dict()
- resp["floatingips"] = list()
- # create a list of floting IP definitions and return it
- for i in range(100, 110):
- ip = dict()
- ip["router_id"] = "router_id"
- ip["description"] = "hardcoded in api"
- ip["created_at"] = "router_id"
- ip["updated_at"] = "router_id"
- ip["revision_number"] = 1
- ip["tenant_id"] = "tenant_id"
- ip["project_id"] = "project_id"
- ip["floating_network_id"] = str(i)
- ip["status"] = "ACTIVE"
- ip["id"] = str(i)
- ip["port_id"] = "port_id"
- ip["floating_ip_address"] = "172.0.0.%d" % i
- ip["fixed_ip_address"] = "10.0.0.%d" % i
- resp["floatingips"].append(ip)
+ resp["floatingips"] = [
+ {'floating_ip_address': ip}
+ ]
return Response(json.dumps(resp), status=200,
mimetype='application/json')