Skip to content

Commit 4e70134

Browse files
committed
ipv6: add ipv6 support to control scripts, bind9 and more dhcp6 fixes
1 parent c03c408 commit 4e70134

File tree

5 files changed

+50
-29
lines changed

5 files changed

+50
-29
lines changed

chef/cookbooks/bind9/recipes/default.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@ def make_zone(zone)
152152

153153
zonefile_entries
154154
end
155+
def address_version(address)
156+
'ip6addr' if IPAddr.new(address).ipv6?
157+
'ip4addr' if IPAddr.new(address).ipv4?
158+
end
155159

156160
# Create our basic zone infrastructure.
157161
zones = Mash.new
@@ -207,7 +211,7 @@ def make_zone(zone)
207211
alias_name = "#{net_name}-#{alias_name_no_net}" if alias_name_no_net
208212
end
209213
cluster_zone[:hosts][base_name] = Mash.new
210-
cluster_zone[:hosts][base_name][:ip4addr] = network.address
214+
cluster_zone[:hosts][base_name][address_version(network.address)] = network.address
211215
cluster_zone[:hosts][base_name][:alias] = alias_name if alias_name
212216
end
213217

@@ -238,7 +242,7 @@ def make_zone(zone)
238242
temporary_dhcp.each_pair do |address, value|
239243
_, base_name, alias_name = value
240244
cluster_zone[:hosts][base_name] = Mash.new
241-
cluster_zone[:hosts][base_name][:ip4addr] = address
245+
cluster_zone[:hosts][base_name][address_version(address)] = address
242246
cluster_zone[:hosts][base_name][:alias] = alias_name if alias_name
243247
end
244248

@@ -257,7 +261,8 @@ def make_zone(zone)
257261
base_name="#{net_name}-#{base_name}"
258262
end
259263
cluster_zone[:hosts][base_name] = Mash.new
260-
cluster_zone[:hosts][base_name][:ip4addr] = network[:allocated_by_name][host][:address]
264+
address = network[:allocated_by_name][host][:address]
265+
cluster_zone[:hosts][base_name][address_version(address)] = address
261266
end
262267
end
263268

@@ -388,8 +393,7 @@ def make_zone(zone)
388393
end
389394
end
390395

391-
### FIXME Change to "any" once IPv6 support has been implemented
392-
admin_addr6 = "none"
396+
admin_addr6 = "any"
393397
if node[:dns][:enable_designate] && !node[:dns][:master]
394398
node[:dns][:forwarders].push master_ip
395399
end

chef/cookbooks/provisioner/recipes/dhcp_update.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
if admin_ip_version == "6"
6868
pool_opts["dhcp"] = ipv6_dhcp_opts
6969
subnet_options = [
70-
"option domain-name \"#{domain_name}\"",
70+
"option dhcp6.domain-search \"#{domain_name}\"",
7171
"option dhcp6.name-servers #{dns_servers.join(", ")}"
7272
]
7373
else

chef/cookbooks/provisioner/recipes/update_nodes.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,10 @@ def find_node_boot_mac_addresses(node, admin_data_net)
5454
states = node["provisioner"]["dhcp"]["state_machine"]
5555
tftproot = node["provisioner"]["root"]
5656
timezone = node["provisioner"]["timezone"]
57-
admin_ip = Chef::Recipe::Barclamp::Inventory.get_network_by_type(node, "admin").address
57+
admin_net = Chef::Recipe::Barclamp::Inventory.get_network_by_type(node, "admin")
58+
admin_ip = admin_net.address
5859
web_port = node[:provisioner][:web_port]
59-
provisioner_web = "http://#{admin_ip}:#{web_port}"
60+
provisioner_web = "http://#{NetworkHelper.wrap_ip(admin_ip)}:#{web_port}"
6061
dhcp_hosts_dir = node["provisioner"]["dhcp_hosts"]
6162
virtual_intfs = ["tap", "qbr", "qvo", "qvb", "brq", "ovs", "vxl"]
6263

@@ -153,6 +154,7 @@ def find_node_boot_mac_addresses(node, admin_data_net)
153154
admin_mac_addresses = find_node_boot_mac_addresses(mnode, admin_data_net)
154155
admin_ip_address = admin_data_net.nil? ? mnode[:ipaddress] : admin_data_net.address
155156
admin_prefix = admin_data_net.nil? ? "" : "#{admin_data_net.subnet}/#{admin_data_net.netmask}"
157+
admin_ip_version = admin_data_net.nil? ? "4" : admin_data_net.ip_version
156158

157159
####
158160
# First deal with states that don't require PXE booting
@@ -222,7 +224,7 @@ def find_node_boot_mac_addresses(node, admin_data_net)
222224
####
223225
# Everything below is for states that require PXE booting
224226

225-
if admin_data_net.ip_version == "6"
227+
if admin_ip_version == "6"
226228
admin6_uri = "http://[#{admin_ip}]:#{web_port}/discovery"
227229
dchp_options = [
228230
"option dhcp6.vendor-class 0 10 \"HTTPClient\"",
@@ -275,7 +277,7 @@ def find_node_boot_mac_addresses(node, admin_data_net)
275277
ipaddress admin_ip_address
276278
options dchp_options
277279
prefix admin_prefix
278-
ip_version admin_data_net.ip_version
280+
ip_version admin_ip_version
279281
end
280282
action :add
281283
end
@@ -379,7 +381,7 @@ def find_node_boot_mac_addresses(node, admin_data_net)
379381
if node[:provisioner][:use_serial_console]
380382
append << "textmode=1"
381383
end
382-
append << "ifcfg=dhcp4 netwait=60"
384+
append << "ifcfg=dhcp#{admin_net.ip_version} netwait=60"
383385
append << "squash=0" # workaround bsc#962397
384386
append << "autoupgrade=1" if mnode[:state] == "os-upgrading"
385387

updates/control.sh

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#
1818

1919
# We get the following variables from start-up.sh
20-
# MAC BOOTDEV ADMIN_IP DOMAIN HOSTNAME HOSTNAME_MAC MYIP
20+
# MAC BOOTDEV ADMIN_IP ADMIN_IP_WRAPPED DOMAIN HOSTNAME HOSTNAME_MAC MYIP IP_VERSION
2121

2222
if [[ ! $IN_SCRIPT ]]; then
2323
export IN_SCRIPT=true
@@ -58,10 +58,21 @@ function is_suse() {
5858
# kernel variable (pre-install).
5959
#
6060
hostname_re='crowbar\.hostname=([^ ]+)'
61-
[[ $(cat /proc/cmdline) =~ $hostname_re ]] && \
62-
HOSTNAME="${BASH_REMATCH[1]}" || \
63-
HOSTNAME="d${MAC//:/-}.${DOMAIN}"
61+
if [[ $(cat /proc/cmdline) =~ $hostname_re ]]; then
62+
HOSTNAME="${BASH_REMATCH[1]}"
63+
else
64+
if [ -n "$DOMAIN" ]; then
65+
HOSTNAME="d${MAC//:/-}.${DOMAIN}"
66+
else
67+
HOSTNAME="d${MAC//:/-}"
68+
fi
69+
fi
6470
sed -i -e "s/\(127\.0\.0\.1.*\)/127.0.0.1 $HOSTNAME ${HOSTNAME%%.*} localhost.localdomain localhost/" /etc/hosts
71+
ADMIN_IP_WRAPPED="$ADMIN_IP"
72+
if (( $IP_VERSION == 6 )); then
73+
sed -i -e "s/\(\:\:1.*\)/::1 $HOSTNAME ${HOSTNAME%%.*} localhost.localdomain localhost ipv6-localhost ipv6-loopback/" /etc/hosts
74+
ADMIN_IP_WRAPPED="[$ADMIN_IP]"
75+
fi
6576
if is_suse; then
6677
echo "$HOSTNAME" > /etc/HOSTNAME
6778
else
@@ -88,15 +99,15 @@ is_suse && {
8899
# enable remote logging to our admin node.
89100
if ! grep -q "${ADMIN_IP}" /etc/rsyslog.conf; then
90101
echo "# Sledgehammer added to log to the admin node" >> /etc/rsyslog.conf
91-
echo "*.* @@${ADMIN_IP}" >> /etc/rsyslog.conf
102+
echo "*.* @@${ADMIN_IP_WRAPPED}" >> /etc/rsyslog.conf
92103
service $RSYSLOGSERVICE restart
93104
fi
94105

95106
# enable SSH access from admin node (same keys).
96107
(umask 077 ; mkdir -p /root/.ssh)
97108
curl -L -o /root/.ssh/authorized_keys \
98109
--connect-timeout 60 -s \
99-
"http://$ADMIN_IP:8091/authorized_keys"
110+
"http://$ADMIN_IP_WRAPPED:8091/authorized_keys"
100111

101112
MYINDEX=${MYIP##*.}
102113
DHCP_STATE=$(grep -o -E 'crowbar\.state=[^ ]+' /proc/cmdline)
@@ -110,8 +121,8 @@ BMC_ADDRESS=""
110121
BMC_NETMASK=""
111122
BMC_ROUTER=""
112123
ALLOCATED=false
113-
export DHCP_STATE MYINDEX ADMIN_ADDRESS BMC_ADDRESS BMC_NETMASK BMC_ROUTER ADMIN_IP
114-
export ALLOCATED HOSTNAME CROWBAR_KEY CROWBAR_STATE
124+
export DHCP_STATE MYINDEX ADMIN_ADDRESS BMC_ADDRESS BMC_NETMASK BMC_ROUTER ADMIN_IP ADMIN_IP_WRAPPED
125+
export ALLOCATED HOSTNAME CROWBAR_KEY CROWBAR_STATE IP_VERSION
115126

116127
# Make sure date is up-to-date
117128
until /usr/sbin/ntpdate $ADMIN_IP || [[ $DHCP_STATE = 'debug' ]]; do
@@ -139,7 +150,7 @@ then
139150
# Other gem dependency installs.
140151
cat > /etc/gemrc <<EOF
141152
:sources:
142-
- http://$ADMIN_IP:8091/gemsite/
153+
- http://$ADMIN_IP_WRAPPED:8091/gemsite/
143154
gem: --no-ri --no-rdoc --bindir /usr/local/bin
144155
EOF
145156
gem install rest-client
@@ -158,7 +169,7 @@ fi
158169
for retry in $(seq 1 30); do
159170
curl -f --retry 2 -o /etc/chef/validation.pem \
160171
--connect-timeout 60 -s -L \
161-
"http://$ADMIN_IP:8091/validation.pem"
172+
"http://$ADMIN_IP_WRAPPED:8091/validation.pem"
162173
[ -f /etc/chef/validation.pem ] && break
163174
sleep $retry
164175
done
@@ -248,7 +259,7 @@ renew_dhcp_after_hwinstalling () {
248259
echo "Forcing DHCP renewal after Admin IP allocation"
249260
ifup $BOOTDEV > /dev/null
250261
echo "New local IP Addresses:"
251-
ip a | awk '/127.0.0./ { next; } /inet / { print }'
262+
ip a | awk '/127.0.0./ { next; } /inet / { print } /inet6 / { print }'
252263
fi
253264
return 0
254265
}
@@ -263,7 +274,7 @@ walk_node_through () {
263274
post_state "$name" "$1" && \
264275
renew_dhcp_after_hwinstalling $1 && \
265276
run_hooks "$HOSTNAME" "$1" pre && \
266-
chef-client -S http://$ADMIN_IP:4000/ -N "$name" && \
277+
chef-client -S http://$ADMIN_IP_WRAPPED:4000/ -N "$name" && \
267278
run_hooks "$HOSTNAME" "$1" post || \
268279
{ post_state "$name" problem; reboot_system; }
269280
shift

updates/control_lib.sh

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ parse_node_data() {
4040
echo "ADMIN_ADDRESS=${ADMIN_ADDRESS}"
4141
echo "ALLOCATED=${ALLOCATED}"
4242
echo "Local IP addresses:"
43-
ip a | awk '/127.0.0./ { next; } /inet / { print }'
43+
ip a | awk '/127.0.0./ { next; } /inet / { print } /inet6 / { print }'
4444
}
4545

4646
try_to() {
@@ -64,7 +64,7 @@ __post_state() {
6464
# $1 = hostname, $2 = target state
6565
USER="$(sed -e 's/:[^:]*$//' <<< $CROWBAR_KEY)"
6666
PASS="$(sed -e 's/^.*://' <<< $CROWBAR_KEY)"
67-
crowbarctl restricted transition "$1" "$2" -s "http://$ADMIN_IP" -U $USER -P $PASS --no-verify-ssl
67+
crowbarctl restricted transition "$1" "$2" -s "http://$ADMIN_IP_WRAPPED" -U $USER -P $PASS --no-verify-ssl
6868
local RET=$?
6969
__get_state "$1"
7070
return $RET
@@ -74,7 +74,7 @@ __get_state() {
7474
# $1 = hostname
7575
USER="$(sed -e 's/:[^:]*$//' <<< $CROWBAR_KEY)"
7676
PASS="$(sed -e 's/^.*://' <<< $CROWBAR_KEY)"
77-
parse_node_data < <(crowbarctl restricted show $1 -s "http://$ADMIN_IP" -U $USER -P $PASS --no-verify-ssl --plain)
77+
parse_node_data < <(crowbarctl restricted show $1 -s "http://$ADMIN_IP_WRAPPED" -U $USER -P $PASS --no-verify-ssl --plain)
7878
}
7979

8080
post_state() { try_to "$MAXTRIES" 15 __post_state "$@"; }
@@ -141,7 +141,11 @@ wait_for_pxe() {
141141
# 22 is the curl exit code for HTTP status codes of 400 and above
142142

143143
# convert ADMIN_ADDRESS from decimal to hex
144-
MYHEXIP=`IFS="." ; for i in $ADMIN_ADDRESS; do printf '%02X' $i ; done`
144+
if (( $IP_VERSION == 6 )); then
145+
MYHEXIP=`IFS=":" ; for i in $ADMIN_ADDRESS; do printf '%s' $i ; done`
146+
else
147+
MYHEXIP=`IFS="." ; for i in $ADMIN_ADDRESS; do printf '%02X' $i ; done`
148+
fi
145149
146150
count=0
147151
done=0
@@ -156,10 +160,10 @@ wait_for_pxe() {
156160
157161
until [ 1 = $done ] ; do
158162
if [ -n "$state" ]; then
159-
curl --fail --silent --connect-timeout 5 "http://$ADMIN_IP:8091/discovery/$arch/bios/pxelinux.cfg/$MYHEXIP" | grep -q "^DEFAULT $state$"
163+
curl --fail --silent --connect-timeout 5 "http://$ADMIN_IP_WRAPPED:8091/discovery/$arch/bios/pxelinux.cfg/$MYHEXIP" | grep -q "^DEFAULT $state$"
160164
ret=$?
161165
else
162-
curl --fail --silent --head --connect-timeout 5 "http://$ADMIN_IP:8091/discovery/$arch/bios/pxelinux.cfg/$MYHEXIP" > /dev/null
166+
curl --fail --silent --head --connect-timeout 5 "http://$ADMIN_IP_WRAPPED:8091/discovery/$arch/bios/pxelinux.cfg/$MYHEXIP" > /dev/null
163167
ret=$?
164168
fi
165169

0 commit comments

Comments
 (0)