diff --git a/kuryr/binding.py b/kuryr/binding.py index c1da85b6..45d152d1 100644 --- a/kuryr/binding.py +++ b/kuryr/binding.py @@ -117,7 +117,7 @@ def port_bind(endpoint_id, neutron_port, neutron_subnets): try: stdout, stderr = processutils.execute( binding_exec_path, BINDING_SUBCOMMAND, port_id, ifname, - run_as_root=True) + endpoint_id, run_as_root=True) except processutils.ProcessExecutionError: with excutils.save_and_reraise_exception(): cleanup_veth(ifname) diff --git a/kuryr/controllers.py b/kuryr/controllers.py index 203c9bb0..d04de1ca 100644 --- a/kuryr/controllers.py +++ b/kuryr/controllers.py @@ -246,6 +246,7 @@ def _create_subnets_and_or_port(interface, neutron_network_id, endpoint_id): port = { 'name': utils.get_neutron_port_name(endpoint_id), 'admin_state_up': True, + "binding:host_id": utils.get_hostname(), 'network_id': neutron_network_id, 'device_owner': constants.DEVICE_OWNER, 'device_id': endpoint_id, diff --git a/kuryr/tests/test_kuryr.py b/kuryr/tests/test_kuryr.py index d22eed6f..7473b1c7 100644 --- a/kuryr/tests/test_kuryr.py +++ b/kuryr/tests/test_kuryr.py @@ -179,6 +179,7 @@ class TestKuryr(base.TestKuryrBase): 'port': { 'name': utils.get_neutron_port_name(docker_endpoint_id), 'admin_state_up': True, + "binding:host_id": utils.get_hostname(), 'mac_address': fake_mac_address, 'network_id': fake_neutron_network_id, 'device_owner': constants.DEVICE_OWNER, @@ -288,6 +289,7 @@ class TestKuryr(base.TestKuryrBase): 'port': { 'name': utils.get_neutron_port_name(docker_endpoint_id), 'admin_state_up': True, + "binding:host_id": utils.get_hostname(), 'mac_address': fake_mac_address, 'network_id': fake_neutron_network_id, 'device_owner': constants.DEVICE_OWNER, @@ -398,6 +400,7 @@ class TestKuryr(base.TestKuryrBase): 'port': { 'name': utils.get_neutron_port_name(docker_endpoint_id), 'admin_state_up': True, + "binding:host_id": utils.get_hostname(), 'device_owner': constants.DEVICE_OWNER, 'device_id': docker_endpoint_id, 'mac_address': "fa:16:3e:20:57:c3", diff --git a/kuryr/tests/test_kuryr_endpoint.py b/kuryr/tests/test_kuryr_endpoint.py index d6b6870e..d9b19b94 100644 --- a/kuryr/tests/test_kuryr_endpoint.py +++ b/kuryr/tests/test_kuryr_endpoint.py @@ -88,6 +88,7 @@ class TestKuryrEndpointFailures(base.TestKuryrFailures): 'port': { 'name': utils.get_neutron_port_name(docker_endpoint_id), 'admin_state_up': True, + "binding:host_id": utils.get_hostname(), 'device_owner': constants.DEVICE_OWNER, 'device_id': docker_endpoint_id, 'fixed_ips': [{ @@ -109,6 +110,7 @@ class TestKuryrEndpointFailures(base.TestKuryrFailures): "name": utils.get_neutron_port_name(docker_endpoint_id), "allowed_address_pairs": [], "admin_state_up": True, + "binding:host_id": utils.get_hostname(), "network_id": neutron_network_id, "tenant_id": "d6700c0c9ffa4f1cb322cd4a1f3906fa", "device_owner": constants.DEVICE_OWNER, diff --git a/kuryr/utils.py b/kuryr/utils.py index 2d8ffd8f..4a46a226 100644 --- a/kuryr/utils.py +++ b/kuryr/utils.py @@ -11,6 +11,7 @@ # under the License. import os +import socket import sys import traceback @@ -104,3 +105,8 @@ def get_neutron_port_name(docker_endpoint_id): :returns: the Neutron port name formatted appropriately """ return '-'.join([docker_endpoint_id, PORT_POSTFIX]) + + +def get_hostname(): + """Returns the host name.""" + return socket.gethostname() diff --git a/usr/libexec/kuryr/ovs b/usr/libexec/kuryr/ovs new file mode 100755 index 00000000..c391564c --- /dev/null +++ b/usr/libexec/kuryr/ovs @@ -0,0 +1,44 @@ +#!/bin/bash +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +INT_BRIDGE="br-int" + +bind_port() { + echo "plugging veth $2 (Neutron port $1)..." + mac=`ip link show dev $2 | tail -1 | awk '{print $2}'` + sudo ovs-vsctl add-port $INT_BRIDGE $2 + sudo ovs-vsctl set interface $2 external_ids:attached-mac=$mac \ + external_ids:iface-id=$1 external_ids:vm-id=$3 \ + external_ids:iface-status=active +} + +unbind_port() { + echo "unplugging veth $1..." +} + +case $1 in + "bind") + shift + bind_port "$@" + exit 0 + ;; + "unbind") + shift + unbind_port "$@" + exit 0 + ;; + *) + echo >&2 "$0: Invalid command $1." + exit 1 + ;; +esac