1. Drop the common(COE agnostic) code such as binding, exceptions 2. Renamed kuryr-libnetwork/kuryr to kuryr-libnetwork/kuryr_libnetwork 3. change default kuryr port from 2377 to 23750 4. Add Kuryr-lib(Kuryr) to requirements.txt: Kuryr-lib(Kuryr) has also been cleaned to remove libnetwork specific code(which is active in this repo such as libnetwork api handlers and test cases). This patch is under review, [1]_. Meanwhile kuryr-lib dependency is being resolved from external repo [2]. Exacltly same changes, as present in under review kuryr-lib patch [1], are there on external repo, [2] [1] https://review.openstack.org/#/c/336784/ [2] https://github.com/vikaschoudhary16/kuryr/tree/drop_libnet_specific_code Implements blueprint common-code-drop Change-Id: If0823791463011dc395cd3390a7f4c187c9c2653changes/50/337350/6
parent
8953d58edc
commit
9c94d3ccc5
@ -1,4 +1,4 @@
|
||||
[DEFAULT]
|
||||
test_command=OS_STDOUT_CAPTURE=1 OS_STDERR_CAPTURE=1 OS_LOG_CAPTURE=1 ${PYTHON:-python} -m subunit.run discover -t ./ ${OS_TEST_PATH:-./kuryr/tests/unit} $LISTOPT $IDOPTION | cat
|
||||
test_command=OS_STDOUT_CAPTURE=1 OS_STDERR_CAPTURE=1 OS_LOG_CAPTURE=1 ${PYTHON:-python} -m subunit.run discover -t ./ ${OS_TEST_PATH:-./kuryr_libnetwork/tests/unit} $LISTOPT $IDOPTION | cat
|
||||
test_id_option=--load-list $IDFILE
|
||||
test_list_option=--list
|
||||
|
@ -1,4 +1,4 @@
|
||||
{
|
||||
"Name": "kuryr",
|
||||
"Addr": "http://127.0.0.1:2377"
|
||||
"Addr": "http://127.0.0.1:23750"
|
||||
}
|
||||
|
@ -1 +1 @@
|
||||
http://127.0.0.1:2377
|
||||
http://127.0.0.1:23750
|
||||
|
@ -1,42 +0,0 @@
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# 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.
|
||||
|
||||
import oslo_i18n
|
||||
|
||||
DOMAIN = "kuryr"
|
||||
|
||||
_translators = oslo_i18n.TranslatorFactory(domain=DOMAIN)
|
||||
|
||||
# The primary translation function using the well-known name "_"
|
||||
_ = _translators.primary
|
||||
|
||||
# The contextual translation function using the name "_C"
|
||||
_C = _translators.contextual_form
|
||||
|
||||
# The plural translation function using the name "_P"
|
||||
_P = _translators.plural_form
|
||||
|
||||
# Translators for log levels.
|
||||
#
|
||||
# The abbreviated names are meant to reflect the usual use of a short
|
||||
# name like '_'. The "L" is for "log" and the other letter comes from
|
||||
# the level.
|
||||
_LI = _translators.log_info
|
||||
_LW = _translators.log_warning
|
||||
_LE = _translators.log_error
|
||||
_LC = _translators.log_critical
|
||||
|
||||
|
||||
def get_available_languages():
|
||||
return oslo_i18n.get_available_languages(DOMAIN)
|
@ -1,195 +0,0 @@
|
||||
# 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.
|
||||
|
||||
import os
|
||||
|
||||
import netaddr
|
||||
from oslo_concurrency import processutils
|
||||
from oslo_utils import excutils
|
||||
import pyroute2
|
||||
|
||||
from kuryr.common import config
|
||||
from kuryr.common import exceptions
|
||||
from kuryr import utils
|
||||
|
||||
|
||||
BINDING_SUBCOMMAND = 'bind'
|
||||
DOWN = 'DOWN'
|
||||
FALLBACK_VIF_TYPE = 'unbound'
|
||||
FIXED_IP_KEY = 'fixed_ips'
|
||||
IFF_UP = 0x1 # The last bit represents if the interface is up
|
||||
IP_ADDRESS_KEY = 'ip_address'
|
||||
KIND_VETH = 'veth'
|
||||
MAC_ADDRESS_KEY = 'mac_address'
|
||||
SUBNET_ID_KEY = 'subnet_id'
|
||||
UNBINDING_SUBCOMMAND = 'unbind'
|
||||
VIF_TYPE_KEY = 'binding:vif_type'
|
||||
VIF_DETAILS_KEY = 'binding:vif_details'
|
||||
|
||||
_IPDB_CACHE = None
|
||||
_IPROUTE_CACHE = None
|
||||
|
||||
|
||||
def get_ipdb():
|
||||
"""Returns the already cached or a newly created IPDB instance.
|
||||
|
||||
IPDB reads the Linux specific file when it's instantiated. This behaviour
|
||||
prevents Mac OSX users from running unit tests. This function makes the
|
||||
loading IPDB lazyily and therefore it can be mocked after the import of
|
||||
modules that import this module.
|
||||
|
||||
:returns: The already cached or newly created ``pyroute2.IPDB`` instance
|
||||
"""
|
||||
global _IPDB_CACHE
|
||||
if not _IPDB_CACHE:
|
||||
_IPDB_CACHE = pyroute2.IPDB()
|
||||
return _IPDB_CACHE
|
||||
|
||||
|
||||
def get_iproute():
|
||||
"""Returns the already cached or a newly created IPRoute instance.
|
||||
|
||||
IPRoute reads the Linux specific file when it's instantiated. This
|
||||
behaviour prevents Mac OSX users from running unit tests. This function
|
||||
makes the loading IPDB lazyily and therefore it can be mocked after the
|
||||
import of modules that import this module.
|
||||
|
||||
:returns: The already cached or newly created ``pyroute2.IPRoute`` instance
|
||||
"""
|
||||
global _IPROUTE_CACHE
|
||||
if not _IPROUTE_CACHE:
|
||||
_IPROUTE_CACHE = pyroute2.IPRoute()
|
||||
return _IPROUTE_CACHE
|
||||
|
||||
|
||||
def _is_up(interface):
|
||||
flags = interface['flags']
|
||||
if not flags:
|
||||
return False
|
||||
return (flags & IFF_UP) == 1
|
||||
|
||||
|
||||
def cleanup_veth(ifname):
|
||||
"""Cleans the veth passed as an argument up.
|
||||
|
||||
:param ifname: the name of the veth endpoint
|
||||
:returns: the index of the interface which name is the given ifname if it
|
||||
exists, otherwise None
|
||||
:raises: pyroute2.NetlinkError
|
||||
"""
|
||||
ipr = get_iproute()
|
||||
|
||||
veths = ipr.link_lookup(ifname=ifname)
|
||||
if veths:
|
||||
host_veth_index = veths[0]
|
||||
ipr.link_remove(host_veth_index)
|
||||
return host_veth_index
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
def port_bind(endpoint_id, neutron_port, neutron_subnets):
|
||||
"""Binds the Neutron port to the network interface on the host.
|
||||
|
||||
:param endpoint_id: the ID of the endpoint as string
|
||||
:param neutron_port: a port dictionary returned from
|
||||
python-neutronclient
|
||||
:param neutron_subnets: a list of all subnets under network to which this
|
||||
endpoint is trying to join
|
||||
:returns: the tuple of the names of the veth pair and the tuple of stdout
|
||||
and stderr returned by processutils.execute invoked with the
|
||||
executable script for binding
|
||||
:raises: kuryr.common.exceptions.VethCreationFailure,
|
||||
processutils.ProcessExecutionError
|
||||
"""
|
||||
ip = get_ipdb()
|
||||
|
||||
port_id = neutron_port['id']
|
||||
ifname, peer_name = utils.get_veth_pair_names(port_id)
|
||||
subnets_dict = {subnet['id']: subnet for subnet in neutron_subnets}
|
||||
|
||||
try:
|
||||
with ip.create(ifname=ifname, kind=KIND_VETH,
|
||||
reuse=True, peer=peer_name) as host_veth:
|
||||
if not _is_up(host_veth):
|
||||
host_veth.up()
|
||||
with ip.interfaces[peer_name] as peer_veth:
|
||||
fixed_ips = neutron_port.get(FIXED_IP_KEY, [])
|
||||
if not fixed_ips and (IP_ADDRESS_KEY in neutron_port):
|
||||
peer_veth.add_ip(neutron_port[IP_ADDRESS_KEY])
|
||||
for fixed_ip in fixed_ips:
|
||||
if IP_ADDRESS_KEY in fixed_ip and (SUBNET_ID_KEY in fixed_ip):
|
||||
subnet_id = fixed_ip[SUBNET_ID_KEY]
|
||||
subnet = subnets_dict[subnet_id]
|
||||
cidr = netaddr.IPNetwork(subnet['cidr'])
|
||||
peer_veth.add_ip(fixed_ip[IP_ADDRESS_KEY], cidr.prefixlen)
|
||||
peer_veth.address = neutron_port[MAC_ADDRESS_KEY].lower()
|
||||
if not _is_up(peer_veth):
|
||||
peer_veth.up()
|
||||
except pyroute2.CreateException:
|
||||
raise exceptions.VethCreationFailure(
|
||||
'Creating the veth pair was failed.')
|
||||
except pyroute2.CommitException:
|
||||
raise exceptions.VethCreationFailure(
|
||||
'Could not configure the veth endpoint for the container.')
|
||||
|
||||
vif_type = neutron_port.get(VIF_TYPE_KEY, FALLBACK_VIF_TYPE)
|
||||
vif_details = utils.string_mappings(neutron_port.get(VIF_DETAILS_KEY))
|
||||
binding_exec_path = os.path.join(config.CONF.bindir, vif_type)
|
||||
if not os.path.exists(binding_exec_path):
|
||||
cleanup_veth(ifname)
|
||||
raise exceptions.BindingNotSupportedFailure(
|
||||
"vif_type({0}) is not supported. A binding script for "
|
||||
"this type can't be found.".format(vif_type))
|
||||
port_id = neutron_port['id']
|
||||
network_id = neutron_port['network_id']
|
||||
tenant_id = neutron_port['tenant_id']
|
||||
mac_address = neutron_port['mac_address']
|
||||
try:
|
||||
stdout, stderr = processutils.execute(
|
||||
binding_exec_path, BINDING_SUBCOMMAND, port_id, ifname,
|
||||
endpoint_id, mac_address, network_id, tenant_id, vif_details,
|
||||
run_as_root=True)
|
||||
except processutils.ProcessExecutionError:
|
||||
with excutils.save_and_reraise_exception():
|
||||
cleanup_veth(ifname)
|
||||
|
||||
return (ifname, peer_name, (stdout, stderr))
|
||||
|
||||
|
||||
def port_unbind(endpoint_id, neutron_port):
|
||||
"""Unbinds the Neutron port from the network interface on the host.
|
||||
|
||||
:param endpoint_id: the ID of the Docker container as string
|
||||
:param neutron_port: a port dictionary returned from python-neutronclient
|
||||
:returns: the tuple of stdout and stderr returned by processutils.execute
|
||||
invoked with the executable script for unbinding
|
||||
:raises: processutils.ProcessExecutionError, pyroute2.NetlinkError
|
||||
"""
|
||||
|
||||
vif_type = neutron_port.get(VIF_TYPE_KEY, FALLBACK_VIF_TYPE)
|
||||
vif_details = utils.string_mappings(neutron_port.get(VIF_DETAILS_KEY))
|
||||
unbinding_exec_path = os.path.join(config.CONF.bindir, vif_type)
|
||||
|
||||
port_id = neutron_port['id']
|
||||
ifname, _ = utils.get_veth_pair_names(port_id)
|
||||
|
||||
mac_address = neutron_port['mac_address']
|
||||
stdout, stderr = processutils.execute(
|
||||
unbinding_exec_path, UNBINDING_SUBCOMMAND, port_id, ifname,
|
||||
endpoint_id, mac_address, vif_details, run_as_root=True)
|
||||
try:
|
||||
cleanup_veth(ifname)
|
||||
except pyroute2.NetlinkError:
|
||||
raise exceptions.VethDeleteionFailure(
|
||||
'Deleting the veth pair failed.')
|
||||
return (stdout, stderr)
|
@ -1,88 +0,0 @@
|
||||
# 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.
|
||||
|
||||
|
||||
class KuryrException(Exception):
|
||||
"""Default Kuryr exception"""
|
||||
|
||||
|
||||
class BindingFailure(KuryrException):
|
||||
"""Exception represents the binding is failed.
|
||||
|
||||
This exception is thrown when the executable script for the binding is
|
||||
failed and Kuryr can't proceed further.
|
||||
"""
|
||||
|
||||
|
||||
class BindingNotSupportedFailure(KuryrException):
|
||||
"""Exception represents the vif type binding not support.
|
||||
|
||||
This exception is thrown when the executable script for the binding does
|
||||
not exist and Kuryr can't proceed further.
|
||||
"""
|
||||
|
||||
|
||||
class DuplicatedResourceException(KuryrException):
|
||||
"""Exception represents there're multiple resources for the ID.
|
||||
|
||||
For example, this exception is thrown when you query the Neutron resource
|
||||
associated with the ID and you get multiple resources.
|
||||
"""
|
||||
|
||||
|
||||
class GatewayConflictFailure(KuryrException):
|
||||
"""Exception represents gateway ip is conflict.
|
||||
|
||||
This exception is thrown when request gateway ip is conflict with the
|
||||
gateway ip in existed network.
|
||||
"""
|
||||
|
||||
|
||||
class MandatoryApiMissing(KuryrException):
|
||||
"""Exception represents that mandatory api is not found.
|
||||
|
||||
For example, this exception is thrown when expected neutron
|
||||
extension(subnetpools) APIs are not found.
|
||||
"""
|
||||
|
||||
|
||||
class NoResourceException(KuryrException):
|
||||
"""Exception represents there's no resource for the given query.
|
||||
|
||||
This exception is thrown when you query the Neutron resource associated
|
||||
with the given query and you get none of them actually.
|
||||
"""
|
||||
|
||||
|
||||
class InactiveResourceException(KuryrException):
|
||||
"""Exception represents the resource for the given query is not active.
|
||||
|
||||
This exception is thrown when you query the Neutron resource associated
|
||||
with the given query and you get the status of the resource as something
|
||||
other than ACTIVE.
|
||||
"""
|
||||
|
||||
|
||||
class VethCreationFailure(KuryrException):
|
||||
"""Exception represents the veth pair creation is failed.
|
||||
|
||||
This exception is thrown when the veth pair is not created appropriately
|
||||
and Kuryr can't proceed the binding further.
|
||||
"""
|
||||
|
||||
|
||||
class VethDeletionFailure(KuryrException):
|
||||
"""Exception represents the veth pair deletion is failed.
|
||||
|
||||
This exception is thrown when the veth pair is not deleted appropriately
|
||||
and Kuryr can't proceed the unbinding further.
|
||||
"""
|
@ -1,55 +0,0 @@
|
||||
# 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.
|
||||
|
||||
__all__ = [
|
||||
'list_kuryr_opts',
|
||||
]
|
||||
|
||||
import copy
|
||||
import itertools
|
||||
|
||||
from oslo_log import _options
|
||||
|
||||
from kuryr.common import config
|
||||
|
||||
|
||||
_core_opts_with_logging = config.core_opts
|
||||
_core_opts_with_logging += _options.common_cli_opts
|
||||
_core_opts_with_logging += _options.logging_cli_opts
|
||||
_core_opts_with_logging += _options.generic_log_opts
|
||||
|
||||
_kuryr_opts = [
|
||||
(None, list(itertools.chain(_core_opts_with_logging))),
|
||||
('neutron_client', config.neutron_opts),
|
||||
('keystone_client', config.keystone_opts),
|
||||
('binding', config.binding_opts),
|
||||
]
|
||||
|
||||
|
||||
def list_kuryr_opts():
|
||||
"""Return a list of oslo_config options available in Kuryr service.
|
||||
|
||||
Each element of the list is a tuple. The first element is the name of the
|
||||
group under which the list of elements in the second element will be
|
||||
registered. A group name of None corresponds to the [DEFAULT] group in
|
||||
config files.
|
||||
|
||||
This function is also discoverable via the 'kuryr' entry point under
|
||||
the 'oslo_config.opts' namespace.
|
||||
|
||||
The purpose of this is to allow tools like the Oslo sample config file
|
||||
generator to discover the options exposed to users by Kuryr.
|
||||
|
||||
:returns: a list of (group_name, opts) tuples
|
||||
"""
|
||||
|
||||
return [(k, copy.deepcopy(o)) for k, o in _kuryr_opts]
|
@ -1,17 +0,0 @@
|
||||
# Copyright 2015 OpenStack Foundation
|
||||
#
|
||||
# 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.
|
||||
|
||||
import pbr.version
|
||||
|
||||
version_info = pbr.version.VersionInfo('kuryr')
|
@ -1,59 +0,0 @@
|
||||
#!/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.
|
||||
|
||||
bind_port() {
|
||||
echo "plugging veth $2 (Neutron port $1)..."
|
||||
|
||||
# create a linux bridge
|
||||
br_name="br"${4:0:12}
|
||||
ip link show $br_name
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Bridge $br_name does not exist, create it"
|
||||
ip link add name $br_name type bridge
|
||||
echo 0 > /sys/devices/virtual/net/$br_name/bridge/forward_delay
|
||||
echo 0 > /sys/devices/virtual/net/$br_name/bridge/stp_state
|
||||
ip link set $br_name up
|
||||
else
|
||||
echo "Bridge $br_name exists"
|
||||
fi
|
||||
|
||||
# connect the veth outside to linux bridge
|
||||
ip link set dev $2 master $br_name
|
||||
ip link set $2 up
|
||||
}
|
||||
|
||||
unbind_port() {
|
||||
echo "unplugging veth $1..."
|
||||
br_name="br"${3:0:12}
|
||||
|
||||
ip link set dev $2 nomaster
|
||||
ip link set $br_name down
|
||||
ip link delete $br_name type bridge
|
||||
}
|
||||
|
||||
case $1 in
|
||||
"bind")
|
||||
shift
|
||||
bind_port "$@"
|
||||
exit 0
|
||||
;;
|
||||
"unbind")
|
||||
shift
|
||||
unbind_port "$@"
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
echo >&2 "$0: Invalid command $1."
|
||||
exit 1
|
||||
;;
|
||||
esac
|
@ -1,42 +0,0 @@
|
||||
#!/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.
|
||||
|
||||
bind_port() {
|
||||
echo "plugging veth $2 (Neutron port $1)..."
|
||||
/opt/pg/bin/ifc_ctl gateway add_port $2
|
||||
/opt/pg/bin/ifc_ctl gateway ifup $2 access_vm $1 $4 pgtag2=$5 pgtag1=$6
|
||||
}
|
||||
|
||||
unbind_port() {
|
||||
echo "unplugging veth $1..."
|
||||
/opt/pg/bin/ifc_ctl gateway ifdown $2 access_vm $1 $4
|
||||
/opt/pg/bin/ifc_ctl gateway del_port $2
|
||||
|
||||
}
|
||||
|
||||
case $1 in
|
||||
"bind")
|
||||
shift
|
||||
bind_port "$@"
|
||||
exit 0
|
||||
;;
|
||||
"unbind")
|
||||
shift
|
||||
unbind_port "$@"
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
echo >&2 "$0: Invalid command $1."
|
||||
exit 1
|
||||
;;
|
||||
esac
|
@ -1,39 +0,0 @@
|
||||
#!/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.
|
||||
|
||||
bind_port() {
|
||||
echo "Binding Neutron port $1 to the veth $2..."
|
||||
mm-ctl --bind-port $1 $2
|
||||
}
|
||||
|
||||
unbind_port() {
|
||||
echo "Unbinding Neutron port $1..."
|
||||
mm-ctl --unbind-port $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
|
@ -1,115 +0,0 @@
|
||||
#!/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"
|
||||
HYBRID_PLUG="'ovs_hybrid_plug': True"
|
||||
|
||||
OPERATION=$1
|
||||
PORT=$2
|
||||
VETH=$3
|
||||
CONTAINER_UUID=$4
|
||||
MAC_ADDRESS=$5
|
||||
|
||||
ovs_bind_port() {
|
||||
echo "plugging veth $VETH (Neutron port $PORT)..."
|
||||
ovs-vsctl -- --may-exist add-port $INT_BRIDGE $VETH -- \
|
||||
set interface $VETH external_ids:attached-mac=$MAC_ADDRESS \
|
||||
external_ids:iface-id=$PORT external_ids:vm-uuid=$CONTAINER_UUID \
|
||||
external_ids:iface-status=active external_ids:owner=kuryr
|
||||
}
|
||||
|
||||
ovs_unbind_port() {
|
||||
echo "unplugging port $PORT..."
|
||||
MYPORT=`ovs-vsctl --data=bare --no-heading --columns=name \
|
||||
find interface external_ids:iface-id=$PORT \
|
||||
external_ids:owner=kuryr`
|
||||
if [ -z "$MYPORT" ]; then
|
||||
echo >&2 "Failed to find port $PORT."
|
||||
exit 1
|
||||
fi
|
||||
ovs-vsctl del-port $INT_BRIDGE $MYPORT
|
||||
}
|
||||
|
||||
ovs_hybrid_bind_port() {
|
||||
echo "... plugging veth $VETH (Neutron port $PORT) ..."
|
||||
# create a linux bridge
|
||||
br_name="qbr"${PORT:0:11}
|
||||
ip link add name $br_name type bridge
|
||||
# Using brctl allows containerized usage not to need privileged mode
|
||||
# as sysfs is mounted read-only when running with just CAP_NET_ADMIN
|
||||
brctl setfd $br_name 0
|
||||
brctl stp $br_name off
|
||||
|
||||
# connect the veth outside to linux bridge
|
||||
ip link set $VETH up
|
||||
ip link set dev $VETH master $br_name
|
||||
# create a veth pair to connect linux bridge and the integration bridge
|
||||
veth_lb="qvb"${PORT:0:11}
|
||||
veth_ovs="qvo"${PORT:0:11}
|
||||
ip link add $veth_lb type veth peer name $veth_ovs
|
||||
|
||||
# connect one end to the linux bridge
|
||||
ip link set dev $veth_lb master $br_name
|
||||
ip link set $br_name up
|
||||
|
||||
# connect one end to the ovs integration bridge
|
||||
ovs-vsctl add-port $INT_BRIDGE $veth_ovs -- \
|
||||
set interface $veth_ovs external_ids:attached-mac=$MAC_ADDRESS \
|
||||
external_ids:iface-id=$PORT external_ids:vm-id=$CONTAINER_UUID \
|
||||
external_ids:iface-status=active external_ids:owner=kuryr
|
||||
|
||||
ip link set $veth_lb up
|
||||
ip link set $veth_ovs up
|
||||
}
|
||||
|
||||
ovs_hybrid_unbind_port() {
|
||||
echo "unplugging port $PORT ..."
|
||||
br_name="qbr"${PORT:0:11}
|
||||
veth_lb="qvb"${PORT:0:11}
|
||||
veth_ovs="qvo"${PORT:0:11}
|
||||
|
||||
ip link set dev $veth_lb nomaster
|
||||
ovs-vsctl del-port $veth_ovs
|
||||
ip link delete $veth_lb type veth
|
||||
|
||||
ip link set $br_name down
|
||||
ip link delete $br_name type bridge
|
||||
}
|
||||
|
||||
|
||||
case $OPERATION in
|
||||
"bind")
|
||||
shift
|
||||
if [ "${7/$HYBRID_PLUG}" = "$7" ]
|
||||
then
|
||||
ovs_bind_port
|
||||
else
|
||||
ovs_hybrid_bind_port
|
||||
fi
|
||||
exit 0
|
||||
;;
|
||||
"unbind")
|
||||
shift
|
||||
if [ "${5/$HYBRID_PLUG}" = "$5" ]
|
||||
then
|
||||
ovs_unbind_port
|
||||
else
|
||||
ovs_hybrid_unbind_port
|
||||
fi
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
echo >&2 "$0: Invalid command $OPERATION."
|
||||
exit 1
|
||||
;;
|
||||
esac
|
@ -1,47 +0,0 @@
|
||||
#!/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.
|
||||
|
||||
bind_port() {
|
||||
echo "Binding VIF_TYPE_TAP Neutron port $1 / veth $2..."
|
||||
#
|
||||
# No real code is needed here, because VIF_TYPE_TAP means that the
|
||||
# host-side TAP or veth device should be left unbridged. The core Kuryr
|
||||
# code has already created the Linux TAP/veth device on the host side, so
|
||||
# there is nothing further for this script to do.
|
||||
}
|
||||
|
||||
unbind_port() {
|
||||
echo "Unbinding VIF_TYPE_TAP Neutron port $1..."
|
||||
#
|
||||
# As with bind_port(), there is actually nothing to do here. The core
|
||||
# Kuryr code will delete the Linux TAP/veth device on the host side after
|
||||
# this script returns, and for VIF_TYPE_TAP we don't need to do anything to
|
||||
# 'unbind' before that happens.
|
||||
}
|
||||
|
||||
case $1 in
|
||||
"bind")
|
||||
shift
|
||||
bind_port "$@"
|
||||
exit 0
|
||||
;;
|
||||
"unbind")
|
||||
shift
|
||||
unbind_port "$@"
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
echo >&2 "$0: Invalid command $1."
|
||||
exit 1
|
||||
;;
|
||||
esac
|
@ -1,16 +0,0 @@
|
||||
#!/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.
|
||||
|
||||
|
||||
echo "binding:vif_type is invalid."
|
||||
exit 1
|
Loading…
Reference in new issue