Merge lp:~saviq/charms/trusty/neutron-contrail/config-vhost-interface into lp:~sdn-charmers/charms/trusty/neutron-contrail/trunk

Proposed by Michał Sawicz on 2015-06-26
Status: Merged
Merged at revision: 28
Proposed branch: lp:~saviq/charms/trusty/neutron-contrail/config-vhost-interface
Merge into: lp:~sdn-charmers/charms/trusty/neutron-contrail/trunk
Diff against target: 312 lines (+178/-31)
7 files modified
config.yaml (+14/-0)
hooks/neutron_contrail_hooks.py (+12/-0)
hooks/neutron_contrail_utils.py (+11/-2)
scripts/br-interfaces.awk (+35/-0)
scripts/create-vrouter.sh (+93/-28)
scripts/vhost-phys.awk (+12/-0)
scripts/vhost-phys.sh (+1/-1)
To merge this branch: bzr merge lp:~saviq/charms/trusty/neutron-contrail/config-vhost-interface
Reviewer Review Type Date Requested Status
Robert Ayres (community) 2015-06-26 Approve on 2015-07-10
Review via email: mp+263129@code.launchpad.net

Commit message

Add fold-juju-bridge and optional vhost-interface config options to deal with more complex network configurations

To post a comment you must log in.
45. By Michał Sawicz on 2015-06-29

Clarify the warning

46. By Michał Sawicz on 2015-06-30

Do not back up our own configs

47. By Michał Sawicz on 2015-06-30

Fix config var name

48. By Michał Sawicz on 2015-06-30

Change ifdown order, otherwise vif tries to delete interfaces that are already down

49. By Michał Sawicz on 2015-06-30

Fix vhost-phys.sh script

50. By Michał Sawicz on 2015-06-30

Take down vhost0, agent and toggle module before configuring vrouter

Otherwise `vif --add` has no effect and networking is gone

51. By Michał Sawicz on 2015-07-01

Merge trunk

52. By Michał Sawicz on 2015-07-01

Need to start the service in case the physical interface does not change

Robert Ayres (robert-ayres) wrote :

Merged with some reworkings.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'config.yaml'
--- config.yaml 2015-06-02 12:50:23 +0000
+++ config.yaml 2015-07-01 11:55:34 +0000
@@ -35,3 +35,17 @@
35 discovery-server-ip:35 discovery-server-ip:
36 type: string36 type: string
37 description: Specify discovery server ip manually37 description: Specify discovery server ip manually
38 vhost-interface:
39 type: string
40 description: |
41 Specify the interface to install vhost0 on. If left empty, vhost0 will
42 be installed on the default gateway interface.
43 fold-juju-bridge:
44 type: boolean
45 default: False
46 description: |
47 Juju on MAAS creates a juju-br0 bridge for deploying LXC and KVM
48 workloads. Enable this to remove this bridge if you want to install
49 vhost0 directly on the underlying interface. WARNING: this will
50 break current and future juju-deployed LXC or KVM workloads on all
51 machines where this is set to True.
3852
=== modified file 'hooks/neutron_contrail_hooks.py'
--- hooks/neutron_contrail_hooks.py 2015-05-21 16:05:07 +0000
+++ hooks/neutron_contrail_hooks.py 2015-07-01 11:55:34 +0000
@@ -14,6 +14,8 @@
1414
15from charmhelpers.core.host import (15from charmhelpers.core.host import (
16 restart_on_change,16 restart_on_change,
17 service_stop,
18 service_start,
17 service_restart19 service_restart
18)20)
1921
@@ -32,6 +34,7 @@
32 ifdown,34 ifdown,
33 ifup,35 ifup,
34 modprobe,36 modprobe,
37 rmmod,
35 provision_vrouter,38 provision_vrouter,
36 units,39 units,
37 unprovision_vrouter,40 unprovision_vrouter,
@@ -59,8 +62,17 @@
5962
60@hooks.hook("config-changed")63@hooks.hook("config-changed")
61def config_changed():64def config_changed():
65 # Need to take down vhost0, the agent and toggle the module
66 # in case we change physical interfaces, otherwise vif --add
67 # does not work
68 ifdown(["vhost0"])
69 service_stop("contrail-vrouter-agent")
70 rmmod("vrouter")
71 modprobe("vrouter")
72 configure_vrouter()
62 configure_virtual_gateways()73 configure_virtual_gateways()
63 write_config()74 write_config()
75 service_start("contrail-vrouter-agent")
64 if not units("contrail-discovery") and not units("control-node"):76 if not units("contrail-discovery") and not units("control-node"):
65 config["control-node-ready"] = True if config.get("discovery-server-ip") \77 config["control-node-ready"] = True if config.get("discovery-server-ip") \
66 else False78 else False
6779
=== modified file 'hooks/neutron_contrail_utils.py'
--- hooks/neutron_contrail_utils.py 2015-06-30 18:42:39 +0000
+++ hooks/neutron_contrail_utils.py 2015-07-01 11:55:34 +0000
@@ -28,7 +28,12 @@
28 return 808228 return 8082
2929
30def configure_vrouter():30def configure_vrouter():
31 check_call(["./create-vrouter.sh"], cwd="scripts")31 args = ["./create-vrouter.sh"]
32 if config.get("fold-juju-bridge", False):
33 args.append("-j")
34 if config.get("vhost-interface", ""):
35 args.append(config["vhost-interface"])
36 check_call(args, cwd="scripts")
3237
33def contrail_api_ctx():38def contrail_api_ctx():
34 ip = config.get("contrail-api-ip")39 ip = config.get("contrail-api-ip")
@@ -117,6 +122,10 @@
117 modules.write(module)122 modules.write(module)
118 modules.write("\n")123 modules.write("\n")
119124
125def rmmod(module):
126 log("Unloading kernel module {}".format(module))
127 check_call(["rmmod", module])
128
120def neutron_metadata_ctx():129def neutron_metadata_ctx():
121 ctxs = [ { "metadata_secret": relation_get("shared-secret", unit, rid) }130 ctxs = [ { "metadata_secret": relation_get("shared-secret", unit, rid) }
122 for rid in relation_ids("neutron-metadata")131 for rid in relation_ids("neutron-metadata")
@@ -208,7 +217,7 @@
208 return ip + "/" + str(cidr)217 return ip + "/" + str(cidr)
209218
210def vhost_phys():219def vhost_phys():
211 return check_output(["scripts/vhost-phys.sh"]).rstrip()220 return check_output(["./vhost-phys.sh"], cwd="scripts").rstrip()
212221
213def vrouter_ctx():222def vrouter_ctx():
214 return { "hostname": vrouter_hostname(),223 return { "hostname": vrouter_hostname(),
215224
=== added file 'scripts/br-interfaces.awk'
--- scripts/br-interfaces.awk 1970-01-01 00:00:00 +0000
+++ scripts/br-interfaces.awk 2015-07-01 11:55:34 +0000
@@ -0,0 +1,35 @@
1function strip(s)
2{
3 sub(/^[[:blank:]]+/, "", s)
4 sub(/[[:blank:]]+$/, "", s)
5 return s
6}
7
8/^[[:blank:]]*(iface|mapping|auto|allow-[^ ]+|source) / {
9 iface = 0
10}
11
12$0 ~ "^[[:blank:]]*(iface|auto) (" interface "|juju-br0)" {
13 if ($1 == "auto" && $2 == "juju-br0") {
14 print "auto", interface > interface_head
15 }
16 if ($1 == "iface") {
17 iface = 1
18 if ($2 == "juju-br0") {
19 print "iface", interface, $3, $4 > interface_head
20 }
21 }
22
23 print "#" $0
24 next
25}
26
27iface == 1 {
28 if (!match($0, "^[[:blank:]]*(bridge_|#|$)")) {
29 print " " strip($0) > interface_cfg
30 }
31 print "#" $0
32 next
33}
34
35{ print $0 }
036
=== modified file 'scripts/create-vrouter.sh'
--- scripts/create-vrouter.sh 2014-12-03 16:51:47 +0000
+++ scripts/create-vrouter.sh 2015-07-01 11:55:34 +0000
@@ -1,5 +1,12 @@
1#!/bin/sh -e1#!/bin/sh -e
22
3configJujuBr()
4{
5 cat juju-header
6 cat "$1"
7 cat "$2" 2> /dev/null || true
8}
9
3configVRouter()10configVRouter()
4{11{
5 cat juju-header12 cat juju-header
@@ -39,43 +46,101 @@
3946
40restoreIfaces()47restoreIfaces()
41{48{
42 cat $TMP/$1.ifaces | xargs -n 1 brctl addif $1 || true49 [ -e $TMP/$1.ifaces ] && cat $TMP/$1.ifaces | xargs -n 1 brctl addif $1 || true
43}50}
4451
45saveIfaces()52saveIfaces()
46{53{
47 find /sys/class/net/$1/brif | tail -n +2 | xargs -n 1 basename \54 find /sys/class/net/$1/brif | tail -n +2 | xargs -n 1 basename > $TMP/$1.ifaces
48 > $TMP/$1.ifaces55}
49}56
5057mangleConfigs()
58{
59 for cfg in /etc/network/interfaces /etc/network/interfaces.d/*.cfg \
60 /etc/network/*.config; do
61 [ -e "$cfg" ] || continue
62 awk $@ "$cfg" > $TMP/interfaces.cfg
63 if ! diff $TMP/interfaces.cfg "$cfg" > /dev/null; then
64 if [ "$cfg" != "$JUJUBR_CFG" -a "$cfg" != "$VROUTER_CFG" ]; then
65 [ -e "$cfg.save" ] || mv "$cfg" "$cfg.save"
66 fi
67 cat juju-header $TMP/interfaces.cfg > "$cfg"
68 fi
69 done
70}
71
72restoreConfigs()
73{
74 rm $JUJUBR_CFG $VROUTER_CFG 2> /dev/null || true
75 for file in `find /etc/network -name '*.save'`
76 do
77 mv "$file" "${file%.save}"
78 done
79}
80
81JUJUBR_CFG=/etc/network/interfaces.d/jujubr.cfg
82VROUTER_CFG=/etc/network/interfaces.d/vrouter.cfg
51TMP=$(mktemp -d /tmp/create-vrouter.XXX)83TMP=$(mktemp -d /tmp/create-vrouter.XXX)
5284
53if [ $# -ne 0 ]; then85# determine base juju-br0 and vhost0 interfaces
54 interface=$186vhost_interface=$(grep -e "iface.*inet manual" $VROUTER_CFG | awk '{ print $2 }') 2> /dev/null || true
55else87br_interface=$(ls /sys/class/net/juju-br0/brif | head -n1) 2> /dev/null || true
56 interface=$(route -n | awk '$1 == "0.0.0.0" { print $8 }')88
57fi89# restore original configs
5890ifacedown juju-br0 $br_interface $vhost_interface; sleep 5
59ifacedown $interface vhost0; sleep 591restoreConfigs
92ifaceup $br_interface $vhost_interface juju-br0; sleep 5
93
94# determine restored juju-br0 interface
95br_interface=$(ls /sys/class/net/juju-br0/brif | head -n1) 2> /dev/null || true
96
97# ensure interfaces.d support
60if ! grep -q '^[[:blank:]]*source /etc/network/interfaces\.d/\*\.cfg[[:blank:]]*$' \98if ! grep -q '^[[:blank:]]*source /etc/network/interfaces\.d/\*\.cfg[[:blank:]]*$' \
61 /etc/network/interfaces; then99 /etc/network/interfaces; then
100 [ -e /etc/network/interfaces.save ] || cp /etc/network/interfaces /etc/network/interfaces.save
62 printf "\n%s\n" "source /etc/network/interfaces.d/*.cfg" \101 printf "\n%s\n" "source /etc/network/interfaces.d/*.cfg" \
63 >> /etc/network/interfaces102 >> /etc/network/interfaces
64fi103fi
65mkdir -p /etc/network/interfaces.d104mkdir -p /etc/network/interfaces.d
66for cfg in /etc/network/interfaces /etc/network/interfaces.d/*.cfg \105
67 /etc/network/*.config; do106# drop juju bridge
68 [ -e "$cfg" ] || continue107if [ "$1" = "-j" ]; then
69 awk -v interface=$interface -v interface_cfg=$TMP/interface.cfg \108 shift
70 -v vrouter_cfg=$TMP/vrouter.cfg -f vrouter-interfaces.awk "$cfg" \109 if [ ! -e "/sys/class/net/juju-br0" ]; then
71 > $TMP/interfaces.cfg110 echo "WARNING: did not find juju-br0, ignoring \"-j\""
72 if ! diff $TMP/interfaces.cfg "$cfg" > /dev/null; then111 else
73 mv "$cfg" "$cfg.save"112 ifacedown juju-br0 $br_interface
74 cat juju-header $TMP/interfaces.cfg > "$cfg"113 mangleConfigs -v interface=$br_interface -v interface_cfg=$TMP/interface.cfg \
114 -v interface_head=$TMP/interface.head -f br-interfaces.awk
115 configJujuBr $TMP/interface.head $TMP/interface.cfg \
116 > $JUJUBR_CFG
117 ifaceup $br_interface
75 fi118 fi
76done119 rm -f $TMP/*
77configVRouter $interface $TMP/interface.cfg $TMP/vrouter.cfg \120fi
78 > /etc/network/interfaces.d/vrouter.cfg121
79ifaceup $interface vhost0122# determine/validate vhost interface
80123if [ -n "$1" ]; then
124 interface=$1
125else
126 interface=$(route -n | awk '$1 == "0.0.0.0" { print $8 }')
127fi
128
129if [ -z "$interface" -o ! -e "/sys/class/net/$interface" ]; then
130 echo "WARNING: invalid interface for vhost0: \"$interface\"," >&2
131 echo "skipping vhost0 configuration" >&2
132 interface=""
133fi
134
135# configure vhost0
136if [ -n "$interface" ]; then
137 ifacedown vhost0 $interface $vhost_interface; sleep 5
138 mangleConfigs -v interface=$interface -v interface_cfg=$TMP/interface.cfg \
139 -v vrouter_cfg=$TMP/vrouter.cfg -f vrouter-interfaces.awk
140
141 configVRouter $interface $TMP/interface.cfg $TMP/vrouter.cfg \
142 > $VROUTER_CFG
143 ifaceup $interface $vhost_interface vhost0
144 rm -f $TMP/*
145fi
81rm -rf $TMP146rm -rf $TMP
82147
=== added file 'scripts/vhost-phys.awk'
--- scripts/vhost-phys.awk 1970-01-01 00:00:00 +0000
+++ scripts/vhost-phys.awk 2015-07-01 11:55:34 +0000
@@ -0,0 +1,12 @@
1/^vif/ {
2 if ($3 != "vhost0") {
3 iface = $3
4 }
5 next
6}
7
8$2 == "HWaddr:" mac {
9 print iface
10 exit
11}
12
013
=== modified file 'scripts/vhost-phys.sh'
--- scripts/vhost-phys.sh 2014-10-31 18:30:28 +0000
+++ scripts/vhost-phys.sh 2015-07-01 11:55:34 +0000
@@ -1,4 +1,4 @@
1#!/bin/sh -e1#!/bin/sh -e
22
3mac=$(cat /sys/class/net/vhost0/address)3mac=$(cat /sys/class/net/vhost0/address)
4vif --list | awk -v mac=$mac 'BEGIN { RS="\n\n" }; $3 != "vhost0" && $5 == "HWaddr:" mac { print $3; exit 0 }'4vif --list | awk -v mac=$mac -f vhost-phys.awk

Subscribers

People subscribed via source and target branches