Merge lp:~lamont/maas/ipv6-rack-n-region.packaging into lp:~maas-maintainers/maas/packaging

Proposed by LaMont Jones
Status: Merged
Approved by: LaMont Jones
Approved revision: no longer in the source branch.
Merged at revision: 525
Proposed branch: lp:~lamont/maas/ipv6-rack-n-region.packaging
Merge into: lp:~maas-maintainers/maas/packaging
Diff against target: 88 lines (+40/-20)
1 file modified
debian/maas-region-controller.postinst (+40/-20)
To merge this branch: bzr merge lp:~lamont/maas/ipv6-rack-n-region.packaging
Reviewer Review Type Date Requested Status
Andres Rodriguez (community) Approve
Review via email: mp+302592@code.launchpad.net

Commit message

During maas-region-controller postinst, prefer IPv4 addresses if maas_url has not been preseeded, and IPv6 addresses only if no IPv4 addresses are present.

Description of the change

During maas-region-controller postinst, prefer IPv4 addresses if maas_url has not been preseeded, and IPv6 addresses only if no IPv4 addresses are present.

To post a comment you must log in.
Revision history for this message
Andres Rodriguez (andreserl) wrote :

Questions inline.

review: Needs Fixing
Revision history for this message
Andres Rodriguez (andreserl) wrote :

I thought we agreed we would do IPv4 first? Judging by the comment it is doing IPv6 first.

review: Needs Fixing
Revision history for this message
LaMont Jones (lamont) wrote :

No, I just failed to update the commit message and comment to reflect the new reality. :(

Revision history for this message
Andres Rodriguez (andreserl) wrote :

lgtm!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/maas-region-controller.postinst'
2--- debian/maas-region-controller.postinst 2016-07-28 02:25:35 +0000
3+++ debian/maas-region-controller.postinst 2016-09-20 21:31:44 +0000
4@@ -21,25 +21,38 @@
5
6 configure_maas_default_url() {
7 local ipaddr="$1"
8- local local_port=$(echo "$ipaddr" | cut -d":" -f2)
9- if [ -z "$local_port" ]; then
10- # Ensure MAAS binds to 5240 by default.
11- ipaddr=${ipaddr}:5240
12+ # The given address is either "[IPv6_IP]" or "IPv4_IP" or "name", such as
13+ # [2001:db8::3:1]:5555 or 127.0.0.1 or maas.example.com.
14+ # The ugly sed splits the given thing as:
15+ # (string of anything but ":", or [ipv6_ip]),
16+ # optionally followed by :port.
17+ local address=$(echo "$ipaddr" |
18+ sed -rn 's/^([^:]*|\[[0-9a-fA-F:]*\])(|:[0-9]*)?$/\1/p')
19+ local port=$(echo "$ipaddr" |
20+ sed -rn 's/^([^:]*|\[[0-9a-fA-F:]*\])(|:[0-9]*)?$/\2/p')
21+ test -n "$port" || port=":5240"
22+ ipaddr="${ipaddr}${port}"
23+ maas-region local_config_set --maas-url "http://${ipaddr}/MAAS"
24+}
25+
26+get_default_route_ip6() {
27+ while read Src SrcPref Dest DestPref Gateway Metric RefCnt Use Flags Iface
28+ do
29+ [ "$SrcPref" = 00 ] && [ "$Iface" != lo ] && break
30+ done < /proc/net/ipv6_route
31+ if [ -n "$Iface" ]; then
32+ LC_ALL=C /sbin/ip -6 addr list dev "$Iface" scope global permanent |
33+ sed -n '/ inet6 /s/.*inet6 \([0-9a-fA-F:]*\).*/[\1]/p' | head -1
34 fi
35- maas-region local_config_set \
36- --maas-url "http://${ipaddr}/MAAS"
37 }
38
39-get_default_route_ip_or_localhost() {
40+get_default_route_ip4() {
41 while read Iface Destination Gateway Flags RefCnt Use Metric Mask MTU Window IRTT
42 do
43 [ "$Mask" = "00000000" ] && break
44 done < /proc/net/route
45- interface="$Iface"
46- if [ -z "$interface" ]; then
47- echo "localhost"
48- else
49- ipaddr=$(LC_ALL=C /sbin/ip -4 addr list dev "$interface" scope global)
50+ if [ -n "$Iface" ]; then
51+ ipaddr=$(LC_ALL=C /sbin/ip -4 addr list dev "$Iface" scope global)
52 ipaddr=${ipaddr#* inet }
53 ipaddr=${ipaddr%%/*}
54 echo $ipaddr
55@@ -67,18 +80,25 @@
56 #########################################################
57
58 # Obtain IP address of default route and change DEFAULT_MAAS_URL
59- # if default-maas-url has not been preseeded.
60+ # if default-maas-url has not been preseeded. Prefer ipv4 addresses if
61+ # present, and use "localhost" only if there is no default route in either
62+ # address family.
63 db_get maas/default-maas-url
64 ipaddr="$RET"
65- if [ -z "$RET" ]; then
66- ipaddr=$(get_default_route_ip_or_localhost)
67+ if [ -z "$ipaddr" ]; then
68+ ipaddr=$(get_default_route_ip4)
69+ fi
70+ if [ -z "$ipaddr" ]; then
71+ ipaddr=$(get_default_route_ip6)
72+ fi
73+ # Fallback default is "localhost"
74+ if [ -z "$ipaddr" ]; then
75+ ipaddr=localhost
76 fi
77 # Set the IP address of the interface with default route
78- if [ -n "$ipaddr" ]; then
79- configure_maas_default_url "$ipaddr"
80- db_subst maas/installation-note MAAS_URL "$ipaddr"
81- db_set maas/default-maas-url "$ipaddr"
82- fi
83+ configure_maas_default_url "$ipaddr"
84+ db_subst maas/installation-note MAAS_URL "$ipaddr"
85+ db_set maas/default-maas-url "$ipaddr"
86
87 #########################################################
88 ################ Configure Database ###################

Subscribers

People subscribed via source and target branches