diff options
author | Martin Schwenke <martin@meltin.net> | 2014-11-24 21:01:37 +1100 |
---|---|---|
committer | Martin Schwenke <martin@meltin.net> | 2014-11-25 11:24:56 +1100 |
commit | 415d586cca66ded609b8f74a7acaece4bd88f57a (patch) | |
tree | 46d7d4f431b57e8bf3f505c47fc8793fb4124461 | |
parent | 85628a2ba97f28cdb21a3efade73c38304f28416 (diff) | |
download | autocluster-415d586cca66ded609b8f74a7acaece4bd88f57a.tar.gz autocluster-415d586cca66ded609b8f74a7acaece4bd88f57a.tar.xz autocluster-415d586cca66ded609b8f74a7acaece4bd88f57a.zip |
Remove netmask from network_map
This removes the /24 assumption, embeds the prefix into the ip field
and calculates netmask in the only place it is needed.
Signed-off-by: Martin Schwenke <martin@meltin.net>
-rwxr-xr-x | autocluster | 20 | ||||
-rw-r--r-- | config.d/00base.defconf | 15 | ||||
-rwxr-xr-x | host_setup/setup_networks.sh | 13 | ||||
-rw-r--r-- | templates/basic-postinstall.sh | 2 |
4 files changed, 21 insertions, 29 deletions
diff --git a/autocluster b/autocluster index 3e9d88e..0eb26f5 100755 --- a/autocluster +++ b/autocluster @@ -350,15 +350,14 @@ make_network_map () local net="${ip_bits%/*}" local netname="acnet_${net//./_}" - local ip="${net%.*}.${IPNUM}" - local mask="255.255.255.0" + local ip="${net%.*}.${IPNUM}/${ip_bits#*/}" # This can be used to override the variables in the echo # statement below. The hook can use any other variables # available in this function. run_hooks hack_network_map_hooks - echo "${netname} ${dev} ${ip} ${mask} ${mac} ${opts}" + echo "${netname} ${dev} ${ip} ${mac} ${opts}" count=$(($count + 1)) done >"$network_map" } @@ -719,8 +718,8 @@ guess_install_network () # specified then use the IP address associated with it. INSTALL_IP="" INSTALL_GW="" - local netname dev ip mask mac opts - while read netname dev ip mask mac opts; do + local netname dev ip mac opts + while read netname dev ip mac opts; do local o for o in $opts ; do case "$o" in @@ -1008,11 +1007,11 @@ setup_network() diskimage rm_rf "/etc/udev/rules.d/70-persistent-net.rules" echo "Setting up network interfaces: " - local netname dev ip mask mac opts - while read netname dev ip mask mac opts; do + local netname dev ip mac opts + while read netname dev ip mac opts; do echo " $dev" - local o gw + local o gw addr mask gw="" for o in $opts ; do case "$o" in @@ -1021,12 +1020,15 @@ setup_network() esac done + addr=${ip%/*} + mask=$(ipv4_prefix_to_netmask ${ip#*/}) + cat <<EOF | \ diskimage put - "/etc/sysconfig/network-scripts/ifcfg-${dev}" DEVICE=$dev ONBOOT=yes TYPE=Ethernet -IPADDR=$ip +IPADDR=$addr NETMASK=$mask HWADDR=$mac ${gw:+GATEWAY=}${gw} diff --git a/config.d/00base.defconf b/config.d/00base.defconf index e141e51..f366f1e 100644 --- a/config.d/00base.defconf +++ b/config.d/00base.defconf @@ -225,8 +225,6 @@ defconf DNSSEARCH "$DOMAIN" \ # * First network is private and contains the CTDB node addresses. # * Items look like: net/bits,dev[,nat|bridge=host_iface][,gw=gateway_ip] -# * Right now autocluster only supports 24 bit networks. This will -# be improved in the future. defconf NETWORKS "10.0.0.0/24,eth0,gw=10.0.0.1 10.0.1.0/24,eth1 10.0.2.0/24,eth2" \ "<list>" "description of IP networks" @@ -263,15 +261,6 @@ make_public_addresses() networks_post_config_hook () { - local n - for n in $NETWORKS ; do - local ip_mask="${n%%,*}" - local mask="${ip_mask#*/}" - - [ "$mask" = "24" ] || \ - die "Network maskbits other than 24 unsupported in \"$n\"" - done - [ -z "$IPBASE" -a -z "$IPNET0" -a -z "$IPNET1" -a -z "$IPNET2" ] || \ die "Configuration variables IPBASE, IPNET0/1/2 unsupported - please use NETWORKS" @@ -290,8 +279,8 @@ defconf NETWORK_TEMPLATE "|network_template" \ network_template () { - local netname dev ip mask mac opts - while read netname dev ip mask mac opts ; do + local netname dev ip mac opts + while read netname dev ip mac opts ; do cat <<EOF <interface type='network'> <mac address='${mac}'/> diff --git a/host_setup/setup_networks.sh b/host_setup/setup_networks.sh index c2663b4..e175863 100755 --- a/host_setup/setup_networks.sh +++ b/host_setup/setup_networks.sh @@ -20,8 +20,7 @@ gen_xml () { local netname="$1" local ip="$2" - local mask="$3" - local opts="$4" + local opts="$3" local uuid=$(uuidgen) @@ -52,10 +51,12 @@ EOF EOF fi + ip_addr=${ip%/*} + ip_mask=${ip#*/} + cat <<EOF <bridge name='${netname}' stp='on' forwardDelay='0' /> - <ip address='${ip}' netmask='${mask}'> - </ip> + <ip address='${ip_addr}' prefix='${ip_mask}' /> </network> EOF } @@ -76,10 +77,10 @@ if [ $? -ne 0 -o -z "$network_map" ]; then fi -while read netname dev ip mask mac opts ; do +while read netname dev ip mac opts ; do echo "Setting up network \"${netname}\"" t=$(mktemp) - gen_xml "$netname" "$ip" "$mask" "$opts" >"$t" + gen_xml "$netname" "$ip" "$opts" >"$t" if $dry_run ; then cat "$t" else diff --git a/templates/basic-postinstall.sh b/templates/basic-postinstall.sh index d81b3c1..f630b70 100644 --- a/templates/basic-postinstall.sh +++ b/templates/basic-postinstall.sh @@ -21,7 +21,7 @@ dev=$(ip link show | echo "Forcing up network interface \"$dev\"" ip link set $dev up -ip addr add @@INSTALL_IP@@/24 dev $dev +ip addr add @@INSTALL_IP@@ dev $dev if [ -n "@@INSTALL_GW@@" ] ; then ip route add default via @@INSTALL_GW@@ fi |