Skip to content

Commit

Permalink
ipv6: add ipv6 support to control scripts, bind9 and more dhcp6 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewoliver committed Jul 4, 2019
1 parent c03c408 commit 4e70134
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 29 deletions.
14 changes: 9 additions & 5 deletions chef/cookbooks/bind9/recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ def make_zone(zone)

zonefile_entries
end
def address_version(address)
'ip6addr' if IPAddr.new(address).ipv6?
'ip4addr' if IPAddr.new(address).ipv4?
end

# Create our basic zone infrastructure.
zones = Mash.new
Expand Down Expand Up @@ -207,7 +211,7 @@ def make_zone(zone)
alias_name = "#{net_name}-#{alias_name_no_net}" if alias_name_no_net
end
cluster_zone[:hosts][base_name] = Mash.new
cluster_zone[:hosts][base_name][:ip4addr] = network.address
cluster_zone[:hosts][base_name][address_version(network.address)] = network.address
cluster_zone[:hosts][base_name][:alias] = alias_name if alias_name
end

Expand Down Expand Up @@ -238,7 +242,7 @@ def make_zone(zone)
temporary_dhcp.each_pair do |address, value|
_, base_name, alias_name = value
cluster_zone[:hosts][base_name] = Mash.new
cluster_zone[:hosts][base_name][:ip4addr] = address
cluster_zone[:hosts][base_name][address_version(address)] = address
cluster_zone[:hosts][base_name][:alias] = alias_name if alias_name
end

Expand All @@ -257,7 +261,8 @@ def make_zone(zone)
base_name="#{net_name}-#{base_name}"
end
cluster_zone[:hosts][base_name] = Mash.new
cluster_zone[:hosts][base_name][:ip4addr] = network[:allocated_by_name][host][:address]
address = network[:allocated_by_name][host][:address]
cluster_zone[:hosts][base_name][address_version(address)] = address
end
end

Expand Down Expand Up @@ -388,8 +393,7 @@ def make_zone(zone)
end
end

### FIXME Change to "any" once IPv6 support has been implemented
admin_addr6 = "none"
admin_addr6 = "any"
if node[:dns][:enable_designate] && !node[:dns][:master]
node[:dns][:forwarders].push master_ip
end
Expand Down
2 changes: 1 addition & 1 deletion chef/cookbooks/provisioner/recipes/dhcp_update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
if admin_ip_version == "6"
pool_opts["dhcp"] = ipv6_dhcp_opts
subnet_options = [
"option domain-name \"#{domain_name}\"",
"option dhcp6.domain-search \"#{domain_name}\"",
"option dhcp6.name-servers #{dns_servers.join(", ")}"
]
else
Expand Down
12 changes: 7 additions & 5 deletions chef/cookbooks/provisioner/recipes/update_nodes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ def find_node_boot_mac_addresses(node, admin_data_net)
states = node["provisioner"]["dhcp"]["state_machine"]
tftproot = node["provisioner"]["root"]
timezone = node["provisioner"]["timezone"]
admin_ip = Chef::Recipe::Barclamp::Inventory.get_network_by_type(node, "admin").address
admin_net = Chef::Recipe::Barclamp::Inventory.get_network_by_type(node, "admin")
admin_ip = admin_net.address
web_port = node[:provisioner][:web_port]
provisioner_web = "http://#{admin_ip}:#{web_port}"
provisioner_web = "http://#{NetworkHelper.wrap_ip(admin_ip)}:#{web_port}"
dhcp_hosts_dir = node["provisioner"]["dhcp_hosts"]
virtual_intfs = ["tap", "qbr", "qvo", "qvb", "brq", "ovs", "vxl"]

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

####
# First deal with states that don't require PXE booting
Expand Down Expand Up @@ -222,7 +224,7 @@ def find_node_boot_mac_addresses(node, admin_data_net)
####
# Everything below is for states that require PXE booting

if admin_data_net.ip_version == "6"
if admin_ip_version == "6"
admin6_uri = "http://[#{admin_ip}]:#{web_port}/discovery"
dchp_options = [
"option dhcp6.vendor-class 0 10 \"HTTPClient\"",
Expand Down Expand Up @@ -275,7 +277,7 @@ def find_node_boot_mac_addresses(node, admin_data_net)
ipaddress admin_ip_address
options dchp_options
prefix admin_prefix
ip_version admin_data_net.ip_version
ip_version admin_ip_version
end
action :add
end
Expand Down Expand Up @@ -379,7 +381,7 @@ def find_node_boot_mac_addresses(node, admin_data_net)
if node[:provisioner][:use_serial_console]
append << "textmode=1"
end
append << "ifcfg=dhcp4 netwait=60"
append << "ifcfg=dhcp#{admin_net.ip_version} netwait=60"
append << "squash=0" # workaround bsc#962397
append << "autoupgrade=1" if mnode[:state] == "os-upgrading"

Expand Down
35 changes: 23 additions & 12 deletions updates/control.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#

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

if [[ ! $IN_SCRIPT ]]; then
export IN_SCRIPT=true
Expand Down Expand Up @@ -58,10 +58,21 @@ function is_suse() {
# kernel variable (pre-install).
#
hostname_re='crowbar\.hostname=([^ ]+)'
[[ $(cat /proc/cmdline) =~ $hostname_re ]] && \
HOSTNAME="${BASH_REMATCH[1]}" || \
HOSTNAME="d${MAC//:/-}.${DOMAIN}"
if [[ $(cat /proc/cmdline) =~ $hostname_re ]]; then
HOSTNAME="${BASH_REMATCH[1]}"
else
if [ -n "$DOMAIN" ]; then
HOSTNAME="d${MAC//:/-}.${DOMAIN}"
else
HOSTNAME="d${MAC//:/-}"
fi
fi
sed -i -e "s/\(127\.0\.0\.1.*\)/127.0.0.1 $HOSTNAME ${HOSTNAME%%.*} localhost.localdomain localhost/" /etc/hosts
ADMIN_IP_WRAPPED="$ADMIN_IP"
if (( $IP_VERSION == 6 )); then
sed -i -e "s/\(\:\:1.*\)/::1 $HOSTNAME ${HOSTNAME%%.*} localhost.localdomain localhost ipv6-localhost ipv6-loopback/" /etc/hosts
ADMIN_IP_WRAPPED="[$ADMIN_IP]"
fi
if is_suse; then
echo "$HOSTNAME" > /etc/HOSTNAME
else
Expand All @@ -88,15 +99,15 @@ is_suse && {
# enable remote logging to our admin node.
if ! grep -q "${ADMIN_IP}" /etc/rsyslog.conf; then
echo "# Sledgehammer added to log to the admin node" >> /etc/rsyslog.conf
echo "*.* @@${ADMIN_IP}" >> /etc/rsyslog.conf
echo "*.* @@${ADMIN_IP_WRAPPED}" >> /etc/rsyslog.conf
service $RSYSLOGSERVICE restart
fi

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

MYINDEX=${MYIP##*.}
DHCP_STATE=$(grep -o -E 'crowbar\.state=[^ ]+' /proc/cmdline)
Expand All @@ -110,8 +121,8 @@ BMC_ADDRESS=""
BMC_NETMASK=""
BMC_ROUTER=""
ALLOCATED=false
export DHCP_STATE MYINDEX ADMIN_ADDRESS BMC_ADDRESS BMC_NETMASK BMC_ROUTER ADMIN_IP
export ALLOCATED HOSTNAME CROWBAR_KEY CROWBAR_STATE
export DHCP_STATE MYINDEX ADMIN_ADDRESS BMC_ADDRESS BMC_NETMASK BMC_ROUTER ADMIN_IP ADMIN_IP_WRAPPED
export ALLOCATED HOSTNAME CROWBAR_KEY CROWBAR_STATE IP_VERSION

# Make sure date is up-to-date
until /usr/sbin/ntpdate $ADMIN_IP || [[ $DHCP_STATE = 'debug' ]]; do
Expand Down Expand Up @@ -139,7 +150,7 @@ then
# Other gem dependency installs.
cat > /etc/gemrc <<EOF
:sources:
- http://$ADMIN_IP:8091/gemsite/
- http://$ADMIN_IP_WRAPPED:8091/gemsite/
gem: --no-ri --no-rdoc --bindir /usr/local/bin
EOF
gem install rest-client
Expand All @@ -158,7 +169,7 @@ fi
for retry in $(seq 1 30); do
curl -f --retry 2 -o /etc/chef/validation.pem \
--connect-timeout 60 -s -L \
"http://$ADMIN_IP:8091/validation.pem"
"http://$ADMIN_IP_WRAPPED:8091/validation.pem"
[ -f /etc/chef/validation.pem ] && break
sleep $retry
done
Expand Down Expand Up @@ -248,7 +259,7 @@ renew_dhcp_after_hwinstalling () {
echo "Forcing DHCP renewal after Admin IP allocation"
ifup $BOOTDEV > /dev/null
echo "New local IP Addresses:"
ip a | awk '/127.0.0./ { next; } /inet / { print }'
ip a | awk '/127.0.0./ { next; } /inet / { print } /inet6 / { print }'
fi
return 0
}
Expand All @@ -263,7 +274,7 @@ walk_node_through () {
post_state "$name" "$1" && \
renew_dhcp_after_hwinstalling $1 && \
run_hooks "$HOSTNAME" "$1" pre && \
chef-client -S http://$ADMIN_IP:4000/ -N "$name" && \
chef-client -S http://$ADMIN_IP_WRAPPED:4000/ -N "$name" && \
run_hooks "$HOSTNAME" "$1" post || \
{ post_state "$name" problem; reboot_system; }
shift
Expand Down
16 changes: 10 additions & 6 deletions updates/control_lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ parse_node_data() {
echo "ADMIN_ADDRESS=${ADMIN_ADDRESS}"
echo "ALLOCATED=${ALLOCATED}"
echo "Local IP addresses:"
ip a | awk '/127.0.0./ { next; } /inet / { print }'
ip a | awk '/127.0.0./ { next; } /inet / { print } /inet6 / { print }'
}

try_to() {
Expand All @@ -64,7 +64,7 @@ __post_state() {
# $1 = hostname, $2 = target state
USER="$(sed -e 's/:[^:]*$//' <<< $CROWBAR_KEY)"
PASS="$(sed -e 's/^.*://' <<< $CROWBAR_KEY)"
crowbarctl restricted transition "$1" "$2" -s "http://$ADMIN_IP" -U $USER -P $PASS --no-verify-ssl
crowbarctl restricted transition "$1" "$2" -s "http://$ADMIN_IP_WRAPPED" -U $USER -P $PASS --no-verify-ssl
local RET=$?
__get_state "$1"
return $RET
Expand All @@ -74,7 +74,7 @@ __get_state() {
# $1 = hostname
USER="$(sed -e 's/:[^:]*$//' <<< $CROWBAR_KEY)"
PASS="$(sed -e 's/^.*://' <<< $CROWBAR_KEY)"
parse_node_data < <(crowbarctl restricted show $1 -s "http://$ADMIN_IP" -U $USER -P $PASS --no-verify-ssl --plain)
parse_node_data < <(crowbarctl restricted show $1 -s "http://$ADMIN_IP_WRAPPED" -U $USER -P $PASS --no-verify-ssl --plain)
}

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

# convert ADMIN_ADDRESS from decimal to hex
MYHEXIP=`IFS="." ; for i in $ADMIN_ADDRESS; do printf '%02X' $i ; done`
if (( $IP_VERSION == 6 )); then
MYHEXIP=`IFS=":" ; for i in $ADMIN_ADDRESS; do printf '%s' $i ; done`
else
MYHEXIP=`IFS="." ; for i in $ADMIN_ADDRESS; do printf '%02X' $i ; done`
fi
count=0
done=0
Expand All @@ -156,10 +160,10 @@ wait_for_pxe() {
until [ 1 = $done ] ; do
if [ -n "$state" ]; then
curl --fail --silent --connect-timeout 5 "http://$ADMIN_IP:8091/discovery/$arch/bios/pxelinux.cfg/$MYHEXIP" | grep -q "^DEFAULT $state$"
curl --fail --silent --connect-timeout 5 "http://$ADMIN_IP_WRAPPED:8091/discovery/$arch/bios/pxelinux.cfg/$MYHEXIP" | grep -q "^DEFAULT $state$"
ret=$?
else
curl --fail --silent --head --connect-timeout 5 "http://$ADMIN_IP:8091/discovery/$arch/bios/pxelinux.cfg/$MYHEXIP" > /dev/null
curl --fail --silent --head --connect-timeout 5 "http://$ADMIN_IP_WRAPPED:8091/discovery/$arch/bios/pxelinux.cfg/$MYHEXIP" > /dev/null
ret=$?
fi
Expand Down

0 comments on commit 4e70134

Please sign in to comment.