Skip to content

Commit 718a948

Browse files
committed
More IPv6 updates to the dhcp and provisner barclamps
1 parent d099dbc commit 718a948

File tree

4 files changed

+49
-19
lines changed

4 files changed

+49
-19
lines changed

chef/cookbooks/provisioner/recipes/base.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,9 +351,9 @@
351351
address = crowbar_node["crowbar"]["network"]["admin"]["address"]
352352
protocol = crowbar_node["crowbar"]["apache"]["ssl"] ? "https" : "http"
353353
if IPAddr.new(address).ipv6?
354-
server = "#{protocol}://#{address}"
355-
else
356354
server = "#{protocol}://[#{address}]"
355+
else
356+
server = "#{protocol}://#{address}"
357357
end
358358
password = crowbar_node["crowbar"]["users"]["crowbar"]["password"]
359359
verify_ssl = !crowbar_node["crowbar"]["apache"]["insecure"]

chef/cookbooks/provisioner/recipes/setup_base_images.rb

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,18 @@
1414
# limitations under the License
1515
#
1616

17+
require "ipaddr"
18+
1719
dirty = false
1820

1921
# Set up the OS images as well
2022
# Common to all OSes
2123
admin_net = Barclamp::Inventory.get_network_by_type(node, "admin")
22-
admin_ip = admin_net.address
24+
admin_ip = IPAddr.new(admin_net.address)
2325
domain_name = node[:dns].nil? ? node[:domain] : (node[:dns][:domain] || node[:domain])
2426
web_port = node[:provisioner][:web_port]
25-
provisioner_web="http://#{admin_ip}:#{web_port}"
27+
provisioner_web="http://#{admin_ip.to_s}:#{web_port}" if admin_ip.ipv4?
28+
provisioner_web="http://[#{admin_ip.to_s}]:#{web_port}" if admin_ip.ipv6?
2629
append_line = node[:provisioner][:discovery][:append].dup # We'll modify it inline
2730

2831
crowbar_node = node_search_with_cache("roles:crowbar").first
@@ -157,7 +160,7 @@
157160
source "grub.conf.erb"
158161
variables(append_line: "#{append_line} crowbar.state=discovery",
159162
install_name: "Crowbar Discovery Image",
160-
admin_ip: admin_ip,
163+
admin_ip: admin_ip.to_s,
161164
efi_suffix: arch == "x86_64",
162165
initrd: "discovery/#{arch}/initrd0.img",
163166
kernel: "discovery/#{arch}/vmlinuz0")
@@ -182,7 +185,7 @@
182185
mode 0o644
183186
variables(docroot: tftproot,
184187
port: web_port,
185-
admin_ip: admin_ip,
188+
admin_ip: admin_ip.to_s,
186189
admin_subnet: admin_net.subnet,
187190
admin_netmask: admin_net.netmask,
188191
logfile: "/var/log/apache2/provisioner-access_log",
@@ -298,12 +301,13 @@
298301
notifies :reload, resources(service: "xinetd")
299302
end
300303
else
304+
ip_addr = admin_ip.ipv6? ? "[#{admin_ip.to_s}]" : admin_ip.to_s
301305
template "/etc/systemd/system/tftp.service" do
302306
source "tftp.service.erb"
303307
owner "root"
304308
group "root"
305309
mode "0644"
306-
variables(tftproot: tftproot, admin_ip: admin_ip)
310+
variables(tftproot: tftproot, admin_ip: ip_addr)
307311
end
308312

309313
service "tftp.service" do
@@ -388,7 +392,7 @@
388392
mode "0644"
389393
source "set_state.ps1.erb"
390394
variables(crowbar_key: crowbar_key,
391-
admin_ip: admin_ip)
395+
admin_ip: admin_ip.to_s)
392396
end
393397

394398
# Also copy the required files to install chef-client and communicate with Crowbar
@@ -507,11 +511,12 @@
507511
owner "root"
508512
group "root"
509513
source "crowbar_join.suse.sh.erb"
510-
variables(admin_ip: admin_ip,
514+
variables(admin_ip: admin_ip.to_s,
511515
web_port: web_port,
512516
ntp_servers_ips: ntp_servers,
513517
platform: target_platform_distro,
514-
target_platform_version: target_platform_version)
518+
target_platform_version: target_platform_version,
519+
is_ipv6: admin_ip.ipv6?)
515520
end
516521

517522
repos = Provisioner::Repositories.get_repos(target_platform_distro,
@@ -525,7 +530,7 @@
525530
owner "root"
526531
group "root"
527532
source "crowbar_register.erb"
528-
variables(admin_ip: admin_ip,
533+
variables(admin_ip: admin_ip.to_s,
529534
admin_broadcast: admin_net.broadcast,
530535
crowbar_protocol: crowbar_protocol,
531536
crowbar_verify_ssl: crowbar_verify_ssl,
@@ -538,7 +543,8 @@
538543
repos: repos,
539544
packages: packages,
540545
platform: target_platform_distro,
541-
target_platform_version: target_platform_version)
546+
target_platform_version: target_platform_version,
547+
is_ipv6: admin_ip.ipv6?)
542548
end
543549

544550
missing_files = !File.exist?("#{os_dir}/install/boot/#{arch}/common")

chef/cookbooks/provisioner/templates/default/crowbar_join.suse.sh.erb

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,11 @@ wait_for_hostname() {
114114
wait_for_admin_server() {
115115
# wait for admin server to become pingable
116116
tries_left=120
117-
while ! ping -q -c1 $IP > /dev/null; do
117+
local ping="ping"
118+
if (( $IPV6 > 0 )); then
119+
ping="ping6"
120+
fi
121+
while ! $ping -q -c1 $IP > /dev/null; do
118122
tries_left=$(($tries_left-1))
119123
if [ $tries_left -eq 0 ]; then
120124
return 1
@@ -163,9 +167,9 @@ do_setup() {
163167
# Make sure that the client knows how to talk to the server.
164168
local cfg=/etc/chef/client.rb
165169
if ! [ -f $cfg ] || \
166-
! grep -q "^\s*chef_server_url\s*[\"\']http://$IP:4000[\"\']" $cfg; then
170+
! grep -q "^\s*chef_server_url\s*[\"\']http://$IP_WRAPPED:4000[\"\']" $cfg; then
167171
test -f $cfg && mv $cfg $cfg.bak
168-
echo "chef_server_url \"http://$IP:4000\"" >$cfg
172+
echo "chef_server_url \"http://$IP_WRAPPED:4000\"" >$cfg
169173
echo "zypper_check_gpg true" >> $cfg
170174
fi
171175

@@ -398,7 +402,17 @@ EXVAL=0
398402
export HOME=/root
399403

400404
IP="<%= @admin_ip %>"
401-
HTTP_SERVER="<%= @admin_ip %>:<%= @web_port %>"
405+
<% if @is_ipv6 -%>
406+
IPV6=1
407+
<% else -%>
408+
IPV6=0
409+
<% end -%>
410+
if (( $IPV6 > 0 )); then
411+
IP_WRAPPED="[$IP]"
412+
else
413+
IP_WRAPPED="$IP"
414+
fi
415+
HTTP_SERVER="$IP_WRAPPED:<%= @web_port %>"
402416
NTP_SERVERS="<%= @ntp_servers_ips.join(" ") %>"
403417
VALID_NTP_SERVERS=""
404418

chef/cookbooks/provisioner/templates/suse/crowbar_register.erb

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,17 @@ add_user() {
122122
ADMIN_IP="<%= @admin_ip %>"
123123
ADMIN_BROADCAST="<%= @admin_broadcast %>"
124124
WEB_PORT="<%= @web_port %>"
125-
HTTP_SERVER="http://${ADMIN_IP}:${WEB_PORT}"
125+
<% if @is_ipv6 -%>
126+
IPV6=1
127+
<% else -%>
128+
IPV6=0
129+
<% end -%>
130+
if (( $IPV6 > 0 )); then
131+
ADMIN_IP_WRAPPED="[ADMIN_IP]"
132+
else
133+
ADMIN_IP_WRAPPED="ADMIN_IP"
134+
fi
135+
HTTP_SERVER="http://${ADMIN_IP_WRAPPED}:${WEB_PORT}"
126136
CROWBAR_OS="<%= @os %>"
127137
CROWBAR_ARCH="<%= @arch %>"
128138
CROWBAR_KEY="<%= @crowbar_key %>"
@@ -381,7 +391,7 @@ TMP_ATTRIBUTES=$(mktemp --suffix .json)
381391
echo "{ \"target_platform\": \"$CROWBAR_OS\", \"crowbar_wall\": { \"registering\": true } }" > "$TMP_ATTRIBUTES"
382392

383393
crowbarctl node transition $HOSTNAME "discovering"
384-
chef-client -S http://$ADMIN_IP:4000/ -N "$HOSTNAME" --json-attributes "$TMP_ATTRIBUTES"
394+
chef-client -S http://$ADMIN_IP_WRAPPED:4000/ -N "$HOSTNAME" --json-attributes "$TMP_ATTRIBUTES"
385395
crowbarctl node transition $HOSTNAME "discovered"
386396
# TODO need to find way of knowing that chef run is over on server side
387397
sleep 30
@@ -393,7 +403,7 @@ echo '{ "crowbar_wall": { "registering": true } }' > "$TMP_ATTRIBUTES"
393403

394404
rm -f /etc/chef/client.pem
395405
crowbarctl node transition $HOSTNAME "hardware-installing"
396-
chef-client -S http://$ADMIN_IP:4000/ -N "$HOSTNAME" --json-attributes "$TMP_ATTRIBUTES"
406+
chef-client -S http://$ADMIN_IP_WRAPPED:4000/ -N "$HOSTNAME" --json-attributes "$TMP_ATTRIBUTES"
397407
crowbarctl node transition $HOSTNAME "hardware-installed"
398408
#TODO
399409
#wait_for_pxe_state ".*_install"

0 commit comments

Comments
 (0)