Signed-off-by: Gurucharan Shetty <gshe...@nicira.com> --- v1-v2: No change --- ovn/utilities/.gitignore | 1 + ovn/utilities/automake.mk | 9 ++- ovn/utilities/ovn-integrate.in | 167 ++++++++++++++++++++++++++++++++++++++++ rhel/openvswitch-fedora.spec.in | 1 + 4 files changed, 177 insertions(+), 1 deletion(-) create mode 100755 ovn/utilities/ovn-integrate.in
diff --git a/ovn/utilities/.gitignore b/ovn/utilities/.gitignore index 1ddc63e..76adb89 100644 --- a/ovn/utilities/.gitignore +++ b/ovn/utilities/.gitignore @@ -1 +1,2 @@ /ovn-ctl.8 +/ovn-integrate diff --git a/ovn/utilities/automake.mk b/ovn/utilities/automake.mk index a55c1ad..1a1a159 100644 --- a/ovn/utilities/automake.mk +++ b/ovn/utilities/automake.mk @@ -4,6 +4,13 @@ scripts_SCRIPTS += \ man_MANS += \ ovn/utilities/ovn-ctl.8 +bin_SCRIPTS += \ + ovn/utilities/ovn-integrate + EXTRA_DIST += \ ovn/utilities/ovn-ctl \ - ovn/utilities/ovn-ctl.8.xml + ovn/utilities/ovn-ctl.8.xml \ + ovn/utilities/ovn-integrate.in + +DISTCLEANFILES += \ + utilities/ovn-integrate diff --git a/ovn/utilities/ovn-integrate.in b/ovn/utilities/ovn-integrate.in new file mode 100755 index 0000000..ef3653e --- /dev/null +++ b/ovn/utilities/ovn-integrate.in @@ -0,0 +1,167 @@ +#! /bin/sh + +datadir=${OVS_PKGDATADIR-'@pkgdatadir@'} + +OVSLIB="$datadir/scripts/ovs-lib" +if [ ! -e "${OVSLIB}" ]; then + echo "$0 needs ${OVSLIB} to work." 1>&2 + exit 1 +fi + +if (ovs-vsctl --version) > /dev/null 2>&1; then :; else + log_failure_msg "missing ovs-vsctl, cannot proceed." + exit 1 +fi + +ovs_vsctl () { + ovs-vsctl --timeout=5 "$@" +} + +. ${OVSLIB} || exit 1 + +nics_to_bridge() { + if (ip -V) > /dev/null 2>&1; then :; else + log_failure_msg "missing ip command, cannot proceed." + exit 1 + fi + + if (mktemp --version) > /dev/null 2>&1; then :; else + log_failure_msg "missing mktemp command, cannot proceed." + exit 1 + fi + + for iface in "$@" + do + if [ -d /sys/class/net/"${iface}" ]; then :; else + log_failure_msg "interface ${iface} does not exist, skipping." + continue + fi + + if [ -e /sys/class/net/"${iface}/address" ]; then + mac_address=`cat /sys/class/net/"${iface}"/address` + else + log_failure_msg "interface ${iface} does not have a mac address." + continue + fi + + OVSBR="br${iface}" + if (ovs_vsctl add-br "${OVSBR}" \ + -- br-set-external-id "${OVSBR}" bridge-id "${OVSBR}"\ + -- set bridge "${OVSBR}" fail-mode=standalone \ + other_config:hwaddr="$mac_address" \ + -- add-port "${OVSBR}" "${iface}") ; then + log_success_msg "successfully created OVS bridge ${OVSBR}" + + # Move the ip address and ip route of the added port to the bridge. + # To do this, save the current configuration of the NIC interface + # as commands in a temp file and then re-execute it for the bridge. + script=`mktemp` + echo "#! /bin/sh" > ${script} + + move_ip_address "${iface}" "${OVSBR}" >> ${script} + + move_ip_routes "${iface}" "${OVSBR}" >> ${script} + + chmod +x ${script} + if (${script}) then :; else + log_failure_msg "failed to transfer IP address or routes from\ + ${iface} to ${OVSBR}. Do it manually." + fi + rm -f ${script} + else + log_failure_msg "failed to create OVS bridge ${OVSBR}" + fi + done +} + +create_integration_bridge() { + if (ovs_vsctl -- --may-exist add-br br-int\ + -- br-set-external-id br-int bridge-id br-int\ + -- set bridge br-int other-config:disable-in-band=true\ + -- set bridge br-int fail-mode=secure) ; then + log_success_msg "successfully created the integration bridge." + else + log_failure_msg "failed to create the integration bridge." + fi +} + +set_ipam() { + if (ovs_vsctl -- set Open_vSwitch . external_ids:ipam="$1" \ + external_ids:ovn-remote="tcp:$1:6640") ; then + log_success_msg "successfully set the ipam server ip address" + else + log_failure_msg "failed to set the ipam server ip address" + fi +} + +set_tep() { + if (ovs_vsctl -- set Open_vSwitch . external_ids:ovn-encap-ip="$1"); then + log_success_msg "successfully set the local tunnel endpoint" + else + log_failure_msg "failed to set the local tunnel endpoint" + fi +} + +set_encap_type() { + if (ovs_vsctl -- set Open_vSwitch . external_ids:ovn-encap-type="$1"); then + log_success_msg "successfully set the encap type" + else + log_failure_msg "failed to set the encap type" + fi +} + +usage() { + UTIL=$(basename $0) + cat << EOF +${UTIL}: Utilities for OVN integration in a host. +usage: ${UTIL} COMMAND + +Commands: + nics-to-bridge creates an OVS bridge for each of the nic interfaces + provided after this command as arguments. + ex: ${UTIL} nics-to-bridge eth0 eth1 eth2 + create-integration-bridge + creates a OVS integration bridge. + set-ipam set the IP address of the ipam host + set-tep set the local tunnel-endpoint + set-encap-type set the tunnel encapsulation type +Options: + -h, --help display this help message. +EOF + exit 0 +} + +if [ $# -eq 0 ]; then + usage +fi + +case $1 in + "nics-to-bridge") + shift + nics_to_bridge "$@" + exit 0 + ;; + "create-integration-bridge") + create_integration_bridge + exit 0 + ;; + "set-ipam") + shift + set_ipam "$1" + exit 0 + ;; + "set-tep") + shift + set_tep "$1" + exit 0 + ;; + "set-encap-type") + shift + set_encap_type "$1" + exit 0 + ;; +-h | --help) + usage + exit 0 + ;; +esac diff --git a/rhel/openvswitch-fedora.spec.in b/rhel/openvswitch-fedora.spec.in index 08cd5ef..dfdcdca 100644 --- a/rhel/openvswitch-fedora.spec.in +++ b/rhel/openvswitch-fedora.spec.in @@ -318,6 +318,7 @@ rm -rf $RPM_BUILD_ROOT %files ovn %{_bindir}/ovn-controller +%{_bindir}/ovn-integrate %{_bindir}/ovn-nbctl %{_bindir}/ovn-northd %{_datadir}/openvswitch/scripts/ovn-ctl -- 1.9.1 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev