From: schillinge Date: Mon, 3 Dec 2018 10:34:01 +0000 (+0100) Subject: Return actually reachable IP as part of the Floating IP API X-Git-Tag: v5.0.0^0 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fchanges%2F22%2F7022%2F1;p=osm%2Fvim-emu.git Return actually reachable IP as part of the Floating IP API The Floating-IP list API is only ever queried for getting the IP assigned to a specific port (if vim-emu is added with the manual floating-ip assignment turned off). Thus, the previous solution lead to fixed IPs being returned (which are not reachable). This solution tracks the assigned container for each port in order to be able to return the public IP assigned by docker. This is not perfect in the sense that multiple ports do not receive different floating ips, but at least the containers are actually reachable now. Change-Id: I233e5de35b3b7e7350faaef017711f7c1e919fff Signed-off-by: schillinge --- diff --git a/src/emuvim/api/openstack/compute.py b/src/emuvim/api/openstack/compute.py index 865b770..405fa6f 100755 --- a/src/emuvim/api/openstack/compute.py +++ b/src/emuvim/api/openstack/compute.py @@ -488,6 +488,7 @@ class OpenstackCompute(object): intf.setMAC(port.mac_address) else: port.mac_address = intf.MAC() + port.assigned_container = c # Start the real emulator command now as specified in the dockerfile # ENV SON_EMU_CMD diff --git a/src/emuvim/api/openstack/openstack_dummies/neutron_dummy_api.py b/src/emuvim/api/openstack/openstack_dummies/neutron_dummy_api.py index 154f1ca..e094f0e 100755 --- a/src/emuvim/api/openstack/openstack_dummies/neutron_dummy_api.py +++ b/src/emuvim/api/openstack/openstack_dummies/neutron_dummy_api.py @@ -972,30 +972,23 @@ class NeutronAddFloatingIp(Resource): 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') diff --git a/src/emuvim/api/openstack/resources/port.py b/src/emuvim/api/openstack/resources/port.py index 1d82e92..6b4929d 100755 --- a/src/emuvim/api/openstack/resources/port.py +++ b/src/emuvim/api/openstack/resources/port.py @@ -45,6 +45,7 @@ class Port: self.mac_address = mac_address self.floating_ip = floating_ip self.net_name = None + self.assigned_container = None def set_name(self, name): """