New configuration variable NETWORKS - IPBASE, IPNET* no longer used
authorMartin Schwenke <martin@meltin.net>
Tue, 5 Mar 2013 00:36:16 +0000 (11:36 +1100)
committerMartin Schwenke <martin@meltin.net>
Tue, 5 Mar 2013 04:07:36 +0000 (15:07 +1100)
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>
12 files changed:
README
autocluster
base/all/etc/sysconfig/network-scripts/ifcfg-eth0 [deleted file]
base/all/etc/sysconfig/network-scripts/ifcfg-eth1 [deleted file]
base/all/etc/sysconfig/network-scripts/ifcfg-eth2 [deleted file]
base/all/root/scripts/setup_ad_server.sh
config.d/00base.defconf
config.d/10shareddisk.defconf
host_setup/setup_networks.sh [new file with mode: 0755]
templates/basic-postinstall.sh
templates/install.xml
templates/node.xml

diff --git a/README b/README
index 548dbf1929e92be10f5461e3713964b704fb2d89..c924a2f66f8f31c507dd5b4948a58e6b407b5f58 100644 (file)
--- 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:
 
index 8f9fa3093c9006b749d880a860ddc0effe9975cb..ec4cbdf6c57ea6d47200ac5bcebd9a8270df5487 100755 (executable)
@@ -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 (executable)
index 1df959a..0000000
+++ /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 (executable)
index ee8cdf2..0000000
+++ /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 (executable)
index b9b26b0..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-DEVICE=eth2
-ONBOOT=yes
-TYPE=Ethernet
-IPADDR=@@IPBASE@@.@@IPNET2@@.@@IPNUM@@
-NETMASK=255.255.255.0
index 62aa4c644bff1c6e71bfbe44c3832fdd3fd30b64..511c1a4cd2236cc9b8716f8f1683e4f66bd2f615 100755 (executable)
@@ -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@@" \
index 3b72fe0541ea9992c18e790f9dc285a6622c5ef7..c7fe312d6792adb5ad68ca62f2d86294909f8066 100644 (file)
@@ -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
index 7a62004c6199ab05bfc4f2c712a47bf2768e6dd1..7d80465ae6e404688b503ecdc1d9015a5dca9992 100644 (file)
@@ -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 (executable)
index 0000000..68291f1
--- /dev/null
@@ -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
index a2c80948510022a6ed54360bb26b2498e818ff42..8499d703cf7f72e96060c4fcc7e5fb4882f2a4d8 100644 (file)
@@ -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
index 7c288680d8d6a930b2ce41fd944c1332b35ad8f4..87a4dd759f904da39872ca93db31ef81fdfeb480 100644 (file)
       <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">
index d5bc4bcc25a1967a2afe8d0fb52eeefe053d9168..7e7779def8d1827bc6cd9cb5e12597cbbf0ea696 100644 (file)
       <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">