summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Schwenke <martin@meltin.net>2013-03-05 11:36:16 +1100
committerMartin Schwenke <martin@meltin.net>2013-03-05 15:07:36 +1100
commit0a6d897bdaf009f6e441dd8cb282624c3e05a975 (patch)
treeafa9e2a6cf8b1b397d1000c8372cdf5fd24eadcb
parenta5f51d7274c8ce32905b05a4ff99f810f768e1c0 (diff)
downloadautocluster-0a6d897bdaf009f6e441dd8cb282624c3e05a975.tar.gz
autocluster-0a6d897bdaf009f6e441dd8cb282624c3e05a975.tar.xz
autocluster-0a6d897bdaf009f6e441dd8cb282624c3e05a975.zip
New configuration variable NETWORKS - IPBASE, IPNET* no longer used
Much more flexible network configuration. Replace canned host_setup/etc/libvirt/qemu/networks/*.xml with setup_networks.sh script. Signed-off-by: Martin Schwenke <martin@meltin.net>
-rw-r--r--README19
-rwxr-xr-xautocluster65
-rwxr-xr-xbase/all/etc/sysconfig/network-scripts/ifcfg-eth05
-rwxr-xr-xbase/all/etc/sysconfig/network-scripts/ifcfg-eth15
-rwxr-xr-xbase/all/etc/sysconfig/network-scripts/ifcfg-eth25
-rwxr-xr-xbase/all/root/scripts/setup_ad_server.sh2
-rw-r--r--config.d/00base.defconf93
-rw-r--r--config.d/10shareddisk.defconf2
-rwxr-xr-xhost_setup/setup_networks.sh75
-rw-r--r--templates/basic-postinstall.sh2
-rw-r--r--templates/install.xml11
-rw-r--r--templates/node.xml16
12 files changed, 187 insertions, 113 deletions
diff --git a/README b/README
index 548dbf1..c924a2f 100644
--- a/README
+++ b/README
@@ -171,21 +171,14 @@ clusters generated by autocluster.
You will need to add the autocluster directory to your PATH.
- You will need to configure the right kvm networking setup. The
- files in host_setup/etc/libvirt/qemu/networks/ should help. This
- command will install the right networks for kvm:
+ You will need to configure the right libvirt networking setup. To
+ do this, run:
- rsync -av --delete host_setup/etc/libvirt/qemu/networks/ /etc/libvirt/qemu/networks/
+ host_setup/setup_networks.sh [ <myconfig> ]
- Note that you'll need to edit the installed files to reflect any
- changes to IPBASE, IPNET0, IPNET1, IPNET2 away from the defaults.
- This is also true for named.conf.local and squid.conf (see below).
-
- After this you might need to reload libvirt:
-
- /etc/init.d/libvirt reload
-
- or similar.
+ If you're using a network setup different to the default then pass
+ your autocluster configuration filename, which should set the
+ NETWORKS variable.
You might also need to set:
diff --git a/autocluster b/autocluster
index 8f9fa30..ec4cbdf 100755
--- a/autocluster
+++ b/autocluster
@@ -240,8 +240,6 @@ create_node_COMMON ()
die "Error: unknown SYSTEM_DISK_FORMAT=\"${SYSTEM_DISK_FORMAT}\"."
esac
- set_macaddrs $CLUSTER $ip_offset
-
# Pull the UUID for this node out of the map.
UUID=$(awk "\$1 == $ip_offset {print \$2}" $uuid_map)
@@ -365,7 +363,7 @@ common_nodelist_hacking ()
local sname=""
local hosts_line
- local ip_addr="$IPBASE.$IPNET0.$(($FIRSTIP + $ip_offset))"
+ local ip_addr="${NETWORK_PRIVATE_PREFIX}.$(($FIRSTIP + $ip_offset))"
if [ "$ctdb_node" = 1 ] ; then
num_ctdb_nodes=$(($num_ctdb_nodes + 1))
@@ -404,7 +402,7 @@ common_nodelist_hacking ()
ctdb_nodes_line ()
{
[ "$ctdb_node" = 1 ] || return 0
- echo "$IPBASE.$IPNET0.$(($FIRSTIP + $ip_offset))"
+ echo "${NETWORK_PRIVATE_PREFIX}.$(($FIRSTIP + $ip_offset))"
num_nodes=$(($num_nodes + 1))
}
nodes_file="tmp/nodes.$CLUSTER"
@@ -627,28 +625,6 @@ boot_base() {
######################################################################
-# various functions...
-
-# Set some MAC address variables based on a hash of the cluster name
-# plus the node number and each adapter number.
-set_macaddrs () {
- local cname="$1"
- local ip_offset="$2"
-
- local md5=$(echo $cname | md5sum)
- local nh=$(printf "%02x" $ip_offset)
- local mac_prefix="02:${md5:0:2}:${md5:2:2}:00:${nh}:"
-
- MAC1="${mac_prefix}01"
- MAC2="${mac_prefix}02"
- MAC3="${mac_prefix}03"
- MAC4="${mac_prefix}04"
- MAC5="${mac_prefix}05"
- MAC6="${mac_prefix}06"
-}
-
-######################################################################
-
# Updating a disk image...
diskimage ()
@@ -761,6 +737,23 @@ setup_network()
echo '@@@YUM_TEMPLATE@@@' | diskimage substitute_vars - "/etc/yum.repos.d/autocluster.repo"
diskimage rm_rf "/etc/udev/rules.d/70-persistent-net.rules"
+
+ echo "Setting up network interfaces: "
+ local n
+ for n in $NETWORKS ; do
+ local dev="${n#*,}" # Strip address, comma
+ dev="${dev%,*}" # Strip comma, interface
+ echo " $dev"
+ cat <<EOF | \
+ diskimage substitute_vars \
+ - "/etc/sysconfig/network-scripts/ifcfg-${dev}"
+DEVICE=$dev
+ONBOOT=yes
+TYPE=Ethernet
+IPADDR=${n%.*}.@@IPNUM@@
+NETMASK=255.255.255.0
+EOF
+ done
}
register_hook setup_base_hooks setup_network
@@ -1085,26 +1078,6 @@ list_releases () {
echo "\"$releases\""
}
-has_public_addresses_DEFAULT ()
-{
- false
-}
-
-make_public_addresses() {
- local firstip="${1:-$[${FIRSTIP} + ${PUBLIC_IP_OFFSET}]}"
- local num_addrs="${2:-${NUMNODES}}"
-
- if [ $(( $firstip + $num_addrs - 1 )) -gt 254 ]; then
- die "make_public_addresses: last octet > 254 - change PUBLIC_IP_OFFSET"
- fi
-
- local e
- for e in $IPNET1 $IPNET2 ; do
- echo -ne "${IPBASE}.${e}.${firstip},${num_addrs},eth${e} "
- done
- echo
-}
-
######################################################################
post_config_hooks=
diff --git a/base/all/etc/sysconfig/network-scripts/ifcfg-eth0 b/base/all/etc/sysconfig/network-scripts/ifcfg-eth0
deleted file mode 100755
index 1df959a..0000000
--- a/base/all/etc/sysconfig/network-scripts/ifcfg-eth0
+++ /dev/null
@@ -1,5 +0,0 @@
-DEVICE=eth0
-ONBOOT=yes
-TYPE=Ethernet
-IPADDR=@@IPBASE@@.@@IPNET0@@.@@IPNUM@@
-NETMASK=255.255.255.0
diff --git a/base/all/etc/sysconfig/network-scripts/ifcfg-eth1 b/base/all/etc/sysconfig/network-scripts/ifcfg-eth1
deleted file mode 100755
index ee8cdf2..0000000
--- a/base/all/etc/sysconfig/network-scripts/ifcfg-eth1
+++ /dev/null
@@ -1,5 +0,0 @@
-DEVICE=eth1
-ONBOOT=yes
-TYPE=Ethernet
-IPADDR=@@IPBASE@@.@@IPNET1@@.@@IPNUM@@
-NETMASK=255.255.255.0
diff --git a/base/all/etc/sysconfig/network-scripts/ifcfg-eth2 b/base/all/etc/sysconfig/network-scripts/ifcfg-eth2
deleted file mode 100755
index b9b26b0..0000000
--- a/base/all/etc/sysconfig/network-scripts/ifcfg-eth2
+++ /dev/null
@@ -1,5 +0,0 @@
-DEVICE=eth2
-ONBOOT=yes
-TYPE=Ethernet
-IPADDR=@@IPBASE@@.@@IPNET2@@.@@IPNUM@@
-NETMASK=255.255.255.0
diff --git a/base/all/root/scripts/setup_ad_server.sh b/base/all/root/scripts/setup_ad_server.sh
index 62aa4c6..511c1a4 100755
--- a/base/all/root/scripts/setup_ad_server.sh
+++ b/base/all/root/scripts/setup_ad_server.sh
@@ -23,7 +23,7 @@ rm -f /etc/samba/smb.conf
# Create AD instance
echo "Provisioning Samba4 AD domain: @@DOMAIN@@"
-hostip="@@IPBASE@@.@@IPNET0@@.@@IPNUM@@"
+hostip="@@NETWORK_PRIVATE_PREFIX@@.@@IPNUM@@"
samba-tool domain provision \
--realm="@@DOMAIN@@" \
--domain="@@WORKGROUP@@" \
diff --git a/config.d/00base.defconf b/config.d/00base.defconf
index 3b72fe0..c7fe312 100644
--- a/config.d/00base.defconf
+++ b/config.d/00base.defconf
@@ -224,25 +224,96 @@ defconf NAMESERVER "10.0.0.1" \
defconf DNSSEARCH "$DOMAIN" \
"<dom>" "extra domains for DNS search list"
-# set the first two octets of the IPs we will use
-# the 3rd and 4th octets are controlled by the node setup scripts
-defconf IPBASE "10.0" \
- "<n>.<n>" "first 2 octets of IP for each node"
+# Networks:
+# * First network is private and contains the CTDB node addresses.
+# * Items look like: net/bits,dev[, nat|bridge=host_iface]
-defconf IPNET0 "0" \
- "<n>" "3rd octet of IP for each node for network 0"
+# * Right now autocluster only supported 24 bit networks. This will
+# be improved in the future.
+defconf NETWORKS "10.0.0.0/24,eth0 10.0.1.0/24,eth1 10.0.2.0/24,eth2" \
+ "<list>" "description of IP networks"
-defconf IPNET1 "1" \
- "<n>" "3rd octet of IP for each node for network 1"
+has_public_addresses_DEFAULT ()
+{
+ false
+}
+
+make_public_addresses()
+{
+ local firstip="${1:-$[${FIRSTIP} + ${PUBLIC_IP_OFFSET}]}"
+ local num_addrs="${2:-${NUMNODES}}"
+
+ if [ $(( $firstip + $num_addrs - 1 )) -gt 254 ]; then
+ die "make_public_addresses: last octet > 254 - change PUBLIC_IP_OFFSET"
+ fi
+
+ local n
+ for n in $NETWORKS_PUBLIC ; do
+ local dev="${n#*,}" # Strip address, comma
+ dev="${dev%,*}" # Strip comma, interface
+ echo -ne "${n%.*}.${firstip},${num_addrs},${dev} "
+ done
+ echo
+}
+
+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
-defconf IPNET2 "2" \
- "<n>" "3rd octet of IP for each node for network 2"
+ [ -z "$IPBASE" -a -z "$IPNET0" -a -z "$IPNET1" -a -z "$IPNET2" ] || \
+ die "Configuration variables IPBASE, IPNET0/1/2 unsupported - please use NETWORKS"
+
+ # Convenience variables
+ set -- $NETWORKS
+ NETWORK_PRIVATE="$1"
+ NETWORK_PRIVATE_PREFIX="${NETWORK_PRIVATE%.*}"
+ NETWORKS_PUBLIC="$2"
+}
+
+register_hook post_config_hooks networks_post_config_hook
+
+defconf NETWORK_TEMPLATE "|network_template" \
+ "<file>" "libvirt template fragment for networks"
+
+network_template ()
+{
+ if [ -n "$CLUSTER" ] ; then
+ local md5=$(echo "$CLUSTER" | md5sum)
+ local nh=$(printf "%02x" $ip_offset)
+ local mac_prefix="02:${md5:0:2}:${md5:2:2}:00:${nh}:"
+ else
+ local mac_prefix="02:42:42:00:00:"
+ fi
+
+ local n
+ local count=1
+ for n in $NETWORKS ; do
+ local ch=$(printf "%02x" $count)
+ net="${n%/*}"
+ name="acnet_${net//./_}"
+ cat <<EOF
+ <interface type='network'>
+ <mac address='${mac_prefix}${ch}'/>
+ <model type='@@NICMODEL@@'/>
+ <source network='${name}'/>
+ </interface>
+EOF
+ count=$(($count + 1))
+ done
+}
# the nodes will get IPs starting at this number
# the TSM server will get $FIRSTIP, then the first node will get
# the next IP etc
-# so if IPBASE is 10.0, IPNET0 is 0 and FIRSTIP is 20 then
+# so if the private network is 10.0.0.0/24,eth0 and FIRSTIP is 20 then
# you will get nodes like this:
# tsmserver 10.0.0.20
# 1st node 10.0.0.21
diff --git a/config.d/10shareddisk.defconf b/config.d/10shareddisk.defconf
index 7a62004..7d80465 100644
--- a/config.d/10shareddisk.defconf
+++ b/config.d/10shareddisk.defconf
@@ -210,7 +210,7 @@ shared_disk_iscsi_setup_base()
# Override this if you use a different scheme for IP addresses.
shared_disk_iscsi_setup_base_get_ip ()
{
- echo "${IPBASE}.${IPNET0}.${IPNUM}"
+ echo "${NETWORK_PRIVATE_PREFIX}.${IPNUM}"
}
shared_disk_iscsi_setup_base_internal ()
diff --git a/host_setup/setup_networks.sh b/host_setup/setup_networks.sh
new file mode 100755
index 0000000..68291f1
--- /dev/null
+++ b/host_setup/setup_networks.sh
@@ -0,0 +1,75 @@
+#!/bin/bash
+
+base_dir=$(cd -P $(dirname $0) ; cd .. ; echo $PWD)
+autocluster="$base_dir/autocluster"
+
+# Run autocluster to determine desired network configuration. The
+# KVM/SYSTEM_DISK_FORMAT thing is gross... but I'm not solving that
+# problem right now!
+networks=$(KVM=/bin/true SYSTEM_DISK_FORMAT=raw \
+ "$autocluster" "${1:+-c}" "$1" -e 'echo $NETWORKS')
+
+die ()
+{
+ echo "ERROR: $*" >&2
+ exit 1
+}
+
+gen_xml ()
+{
+ local n="$1"
+ local name="$2"
+
+ local prefix="${n%.*}"
+ local mode="nat"
+ case "$n" in
+ *,*,*) mode="${n##*,}"
+ esac
+
+ local uuid=$(uuidgen)
+
+ cat <<EOF
+<network>
+ <name>${name}</name>
+ <uuid>${uuid}</uuid>
+EOF
+
+ case "$mode" in
+ nat)
+ cat <<EOF
+ <forward mode='nat'/>
+EOF
+ ;;
+ bridge\=*)
+ iface="${mode#bridge=}"
+ cat <<EOF
+ <forward dev='${iface}' mode='route'>
+ <interface dev='${iface}'/>
+ </forward>
+EOF
+ ;;
+ *)
+ die "Unknown forwarding mode \"${mode}\" in \"$n\""
+ esac
+cat <<EOF
+ <bridge name='${name}' stp='on' forwardDelay='0' />
+ <ip address='${prefix}.1' netmask='255.255.255.0'>
+ </ip>
+</network>
+EOF
+}
+
+count=1
+for n in $networks ; do
+ echo "Processing: $n"
+ # This must match the code in network_template()
+ net="${n%/*}"
+ name="acnet_${net//./_}"
+ t=$(mktemp)
+ gen_xml "$n" "$name" >"$t"
+ echo "Setting up network \"${name}\""
+ virsh net-define "$t" && \
+ virsh net-start "$name" && \
+ virsh net-autostart "$name"
+ rm -f "$t"
+done
diff --git a/templates/basic-postinstall.sh b/templates/basic-postinstall.sh
index a2c8094..8499d70 100644
--- a/templates/basic-postinstall.sh
+++ b/templates/basic-postinstall.sh
@@ -7,7 +7,7 @@
echo "Using web proxy: \$http_proxy"
# force up the network, as kickstart may not have started it
-/sbin/ifconfig eth0 @@IPBASE@@.@@IPNET0@@.@@FIRSTIP@@ netmask 255.255.255.0 up
+/sbin/ifconfig eth0 @@NETWORK_PRIVATE_PREFIX@@.@@FIRSTIP@@ netmask 255.255.255.0 up
/sbin/route add default gw @@GATEWAY@@
/sbin/ifconfig -a
/sbin/route -n
diff --git a/templates/install.xml b/templates/install.xml
index 7c28868..87a4dd7 100644
--- a/templates/install.xml
+++ b/templates/install.xml
@@ -35,16 +35,7 @@
<target dev='fda'/>
<readonly/>
</disk>
- <interface type='network'>
- <mac address='00:00:00:00:00:01'/>
- <model type='@@NICMODEL@@'/>
- <source network='net1'/>
- </interface>
- <interface type='network'>
- <mac address='00:00:00:00:00:02'/>
- <model type='@@NICMODEL@@'/>
- <source network='net2'/>
- </interface>
+@@@NETWORK_TEMPLATE@@@
<input type='mouse' bus='ps2'/>
<graphics type='vnc' port='-1' listen='127.0.0.1'/>
<serial type="file">
diff --git a/templates/node.xml b/templates/node.xml
index d5bc4bc..7e7779d 100644
--- a/templates/node.xml
+++ b/templates/node.xml
@@ -24,21 +24,7 @@
<driver name='qemu' type='@@SYSTEM_DISK_FORMAT@@' cache='@@SYSTEM_DISK_CACHE@@'/>
</disk>
@@@SHAREDDISK_TEMPLATE@@@
- <interface type='network'>
- <mac address='@@MAC1@@'/>
- <model type='@@NICMODEL@@'/>
- <source network='net1'/>
- </interface>
- <interface type='network'>
- <mac address='@@MAC2@@'/>
- <model type='@@NICMODEL@@'/>
- <source network='net2'/>
- </interface>
- <interface type='network'>
- <mac address='@@MAC3@@'/>
- <model type='@@NICMODEL@@'/>
- <source network='net3'/>
- </interface>
+@@@NETWORK_TEMPLATE@@@
<input type='mouse' bus='ps2'/>
<graphics type='vnc' port='-1' listen='127.0.0.1'/>
<serial type="file">