]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
buildpackages: Be robust about addresses
authorRobin H. Johnson <robin.johnson@dreamhost.com>
Thu, 10 Dec 2015 19:55:49 +0000 (11:55 -0800)
committerRobin H. Johnson <robin.johnson@dreamhost.com>
Thu, 10 Dec 2015 19:55:49 +0000 (11:55 -0800)
OpenStack could tell us the VM has multiple networks, and offers no
guarantee about the order of addresses either (the old code failed if
the v4 IP was first).

For now, take the first listed network, and the first listed IPv4
address therein. Comments contain more detailed examples of possible
output from openstack tool.

Also remove the need for using jq to parse the output.

Signed-off-by: Robin H. Johnson <robin.johnson@dreamhost.com>
tasks/buildpackages/Makefile

index b503d1487e1fdb6654347a727b91bbdb1bf6f918..0ac5e54b9dde92b8bda1b7d5fd8581768eb40a73 100644 (file)
@@ -2,8 +2,20 @@ SHELL=/bin/bash
 D=/tmp/stampsdir
 VPATH=${D}
 
+# We want to extract the first listed IPv4 address!
+# Openstack will provide the addresses field in this format:
+# "net1-name=ip(, ip)+(; net2-name=ip(, ip)+)+"
+# Each IP may be v4 or v6 (including shortened forms and IPv4-mapped-IPv6 forms)
+# 1.2.3.4
+# 2001:db8:6050:ed4d:f816:3eff:fe48:3b36
+# 2001:db8::fe48:3b36
+# 2001:db8::1.2.3.4
+# Example long-form input:
+# private-network=10.10.10.69, 2001:db8:6050:ed4d:f816:3eff:fed1:d9f8;net-name2=2001:db8::fe48:3b36, 2001:db8::1.2.3.4, 1.2.3.4;
+# TODO: allow selection of the network instead of taking the first network
+# TODO: Support IPv6 in future
 define get_ip
-$$(openstack server show -f json $(1) | jq '.[] | select(.Field == "addresses") | .Value' | perl -pe 's/([\da-f]*:){7}[\da-f]*, //; s/.*?=([\d\.]+).*/$$1/')
+$$(openstack server show -f value -c addresses $(1) |perl -pe 's/^[^=]+=([^;]+).*/\1/g; s/[ ,]/\n/g; ' |grep -v -e ':' -e '^$$' |head -n1)
 endef
 
 MY_IP=$(shell hostname -I | cut -f1 -d' ')