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
=== modified file 'debian/maas-region-controller.postinst'
--- debian/maas-region-controller.postinst 2016-07-28 02:25:35 +0000
+++ debian/maas-region-controller.postinst 2016-09-20 21:31:44 +0000
@@ -21,25 +21,38 @@
2121
22configure_maas_default_url() {22configure_maas_default_url() {
23 local ipaddr="$1"23 local ipaddr="$1"
24 local local_port=$(echo "$ipaddr" | cut -d":" -f2)24 # The given address is either "[IPv6_IP]" or "IPv4_IP" or "name", such as
25 if [ -z "$local_port" ]; then25 # [2001:db8::3:1]:5555 or 127.0.0.1 or maas.example.com.
26 # Ensure MAAS binds to 5240 by default.26 # The ugly sed splits the given thing as:
27 ipaddr=${ipaddr}:524027 # (string of anything but ":", or [ipv6_ip]),
28 # optionally followed by :port.
29 local address=$(echo "$ipaddr" |
30 sed -rn 's/^([^:]*|\[[0-9a-fA-F:]*\])(|:[0-9]*)?$/\1/p')
31 local port=$(echo "$ipaddr" |
32 sed -rn 's/^([^:]*|\[[0-9a-fA-F:]*\])(|:[0-9]*)?$/\2/p')
33 test -n "$port" || port=":5240"
34 ipaddr="${ipaddr}${port}"
35 maas-region local_config_set --maas-url "http://${ipaddr}/MAAS"
36}
37
38get_default_route_ip6() {
39 while read Src SrcPref Dest DestPref Gateway Metric RefCnt Use Flags Iface
40 do
41 [ "$SrcPref" = 00 ] && [ "$Iface" != lo ] && break
42 done < /proc/net/ipv6_route
43 if [ -n "$Iface" ]; then
44 LC_ALL=C /sbin/ip -6 addr list dev "$Iface" scope global permanent |
45 sed -n '/ inet6 /s/.*inet6 \([0-9a-fA-F:]*\).*/[\1]/p' | head -1
28 fi46 fi
29 maas-region local_config_set \
30 --maas-url "http://${ipaddr}/MAAS"
31}47}
3248
33get_default_route_ip_or_localhost() {49get_default_route_ip4() {
34 while read Iface Destination Gateway Flags RefCnt Use Metric Mask MTU Window IRTT50 while read Iface Destination Gateway Flags RefCnt Use Metric Mask MTU Window IRTT
35 do51 do
36 [ "$Mask" = "00000000" ] && break52 [ "$Mask" = "00000000" ] && break
37 done < /proc/net/route53 done < /proc/net/route
38 interface="$Iface"54 if [ -n "$Iface" ]; then
39 if [ -z "$interface" ]; then55 ipaddr=$(LC_ALL=C /sbin/ip -4 addr list dev "$Iface" scope global)
40 echo "localhost"
41 else
42 ipaddr=$(LC_ALL=C /sbin/ip -4 addr list dev "$interface" scope global)
43 ipaddr=${ipaddr#* inet }56 ipaddr=${ipaddr#* inet }
44 ipaddr=${ipaddr%%/*}57 ipaddr=${ipaddr%%/*}
45 echo $ipaddr58 echo $ipaddr
@@ -67,18 +80,25 @@
67 #########################################################80 #########################################################
6881
69 # Obtain IP address of default route and change DEFAULT_MAAS_URL82 # Obtain IP address of default route and change DEFAULT_MAAS_URL
70 # if default-maas-url has not been preseeded.83 # if default-maas-url has not been preseeded. Prefer ipv4 addresses if
84 # present, and use "localhost" only if there is no default route in either
85 # address family.
71 db_get maas/default-maas-url86 db_get maas/default-maas-url
72 ipaddr="$RET"87 ipaddr="$RET"
73 if [ -z "$RET" ]; then88 if [ -z "$ipaddr" ]; then
74 ipaddr=$(get_default_route_ip_or_localhost)89 ipaddr=$(get_default_route_ip4)
90 fi
91 if [ -z "$ipaddr" ]; then
92 ipaddr=$(get_default_route_ip6)
93 fi
94 # Fallback default is "localhost"
95 if [ -z "$ipaddr" ]; then
96 ipaddr=localhost
75 fi97 fi
76 # Set the IP address of the interface with default route98 # Set the IP address of the interface with default route
77 if [ -n "$ipaddr" ]; then99 configure_maas_default_url "$ipaddr"
78 configure_maas_default_url "$ipaddr"100 db_subst maas/installation-note MAAS_URL "$ipaddr"
79 db_subst maas/installation-note MAAS_URL "$ipaddr"101 db_set maas/default-maas-url "$ipaddr"
80 db_set maas/default-maas-url "$ipaddr"
81 fi
82102
83 #########################################################103 #########################################################
84 ################ Configure Database ###################104 ################ Configure Database ###################

Subscribers

People subscribed via source and target branches