Adding plug/unplug for OVS

Adding the binary that includes plug and unplug
operations for the OVS.

Change-Id: I2672b246fb8e775c4f80318400c75a49e98df281
This commit is contained in:
Mohammad Banikazemi 2015-12-03 20:34:42 -05:00
parent f8a30cc5b1
commit 6198e2ce8a
6 changed files with 57 additions and 1 deletions

View File

@ -117,7 +117,7 @@ def port_bind(endpoint_id, neutron_port, neutron_subnets):
try: try:
stdout, stderr = processutils.execute( stdout, stderr = processutils.execute(
binding_exec_path, BINDING_SUBCOMMAND, port_id, ifname, binding_exec_path, BINDING_SUBCOMMAND, port_id, ifname,
run_as_root=True) endpoint_id, run_as_root=True)
except processutils.ProcessExecutionError: except processutils.ProcessExecutionError:
with excutils.save_and_reraise_exception(): with excutils.save_and_reraise_exception():
cleanup_veth(ifname) cleanup_veth(ifname)

View File

@ -246,6 +246,7 @@ def _create_subnets_and_or_port(interface, neutron_network_id, endpoint_id):
port = { port = {
'name': utils.get_neutron_port_name(endpoint_id), 'name': utils.get_neutron_port_name(endpoint_id),
'admin_state_up': True, 'admin_state_up': True,
"binding:host_id": utils.get_hostname(),
'network_id': neutron_network_id, 'network_id': neutron_network_id,
'device_owner': constants.DEVICE_OWNER, 'device_owner': constants.DEVICE_OWNER,
'device_id': endpoint_id, 'device_id': endpoint_id,

View File

@ -179,6 +179,7 @@ class TestKuryr(base.TestKuryrBase):
'port': { 'port': {
'name': utils.get_neutron_port_name(docker_endpoint_id), 'name': utils.get_neutron_port_name(docker_endpoint_id),
'admin_state_up': True, 'admin_state_up': True,
"binding:host_id": utils.get_hostname(),
'mac_address': fake_mac_address, 'mac_address': fake_mac_address,
'network_id': fake_neutron_network_id, 'network_id': fake_neutron_network_id,
'device_owner': constants.DEVICE_OWNER, 'device_owner': constants.DEVICE_OWNER,
@ -288,6 +289,7 @@ class TestKuryr(base.TestKuryrBase):
'port': { 'port': {
'name': utils.get_neutron_port_name(docker_endpoint_id), 'name': utils.get_neutron_port_name(docker_endpoint_id),
'admin_state_up': True, 'admin_state_up': True,
"binding:host_id": utils.get_hostname(),
'mac_address': fake_mac_address, 'mac_address': fake_mac_address,
'network_id': fake_neutron_network_id, 'network_id': fake_neutron_network_id,
'device_owner': constants.DEVICE_OWNER, 'device_owner': constants.DEVICE_OWNER,
@ -398,6 +400,7 @@ class TestKuryr(base.TestKuryrBase):
'port': { 'port': {
'name': utils.get_neutron_port_name(docker_endpoint_id), 'name': utils.get_neutron_port_name(docker_endpoint_id),
'admin_state_up': True, 'admin_state_up': True,
"binding:host_id": utils.get_hostname(),
'device_owner': constants.DEVICE_OWNER, 'device_owner': constants.DEVICE_OWNER,
'device_id': docker_endpoint_id, 'device_id': docker_endpoint_id,
'mac_address': "fa:16:3e:20:57:c3", 'mac_address': "fa:16:3e:20:57:c3",

View File

@ -88,6 +88,7 @@ class TestKuryrEndpointFailures(base.TestKuryrFailures):
'port': { 'port': {
'name': utils.get_neutron_port_name(docker_endpoint_id), 'name': utils.get_neutron_port_name(docker_endpoint_id),
'admin_state_up': True, 'admin_state_up': True,
"binding:host_id": utils.get_hostname(),
'device_owner': constants.DEVICE_OWNER, 'device_owner': constants.DEVICE_OWNER,
'device_id': docker_endpoint_id, 'device_id': docker_endpoint_id,
'fixed_ips': [{ 'fixed_ips': [{
@ -109,6 +110,7 @@ class TestKuryrEndpointFailures(base.TestKuryrFailures):
"name": utils.get_neutron_port_name(docker_endpoint_id), "name": utils.get_neutron_port_name(docker_endpoint_id),
"allowed_address_pairs": [], "allowed_address_pairs": [],
"admin_state_up": True, "admin_state_up": True,
"binding:host_id": utils.get_hostname(),
"network_id": neutron_network_id, "network_id": neutron_network_id,
"tenant_id": "d6700c0c9ffa4f1cb322cd4a1f3906fa", "tenant_id": "d6700c0c9ffa4f1cb322cd4a1f3906fa",
"device_owner": constants.DEVICE_OWNER, "device_owner": constants.DEVICE_OWNER,

View File

@ -11,6 +11,7 @@
# under the License. # under the License.
import os import os
import socket
import sys import sys
import traceback import traceback
@ -104,3 +105,8 @@ def get_neutron_port_name(docker_endpoint_id):
:returns: the Neutron port name formatted appropriately :returns: the Neutron port name formatted appropriately
""" """
return '-'.join([docker_endpoint_id, PORT_POSTFIX]) return '-'.join([docker_endpoint_id, PORT_POSTFIX])
def get_hostname():
"""Returns the host name."""
return socket.gethostname()

44
usr/libexec/kuryr/ovs Executable file
View File

@ -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