Rework cluster_setup() to use node types instead of $CLUSTER_TYPE
[tridge/autocluster.git] / config.d / 00base.defconf
1 # Hey Emacs, this is a -*- shell-script -*- !!!
2
3 ######################################################################
4
5 # Cluster
6
7 defconf CLUSTERFS_TYPE "gpfs" \
8         "<gpfs|?>" "type of cluster filesystem to use"
9
10 defconf CLUSTERFS_DEFAULT_MOUNTPOINT "/clusterfs" \
11         "<directory>" "mountpoint for default cluster filesystem"
12
13 defconf NODES "nas:0-3 rhel_base:4" \
14         "<nodes>" "list of node types to create, with associated IP offsets"
15
16 defconf NUMNODES "" \
17         "<n>" "number of nodes to build, not including TSM server"
18
19 # a directory on the host which will be mounted via NFS onto the nodes
20 # as $NFS_MOUNTPOINT, giving a nice common area independent of the
21 # cluster filesystem.  This is useful for compiles, RPMs, devel
22 # scripts etc you need to add this to your /etc/exports and run
23 # exportfs -av yourself on the virtualisation host
24 defconf NFSSHARE "10.0.0.1:/home" \
25         "<mnt>" "NFS share to mount on each node"
26
27 defconf NFS_MOUNTPOINT "/home" \
28         "<dir>" "mount point for NFS share"
29
30 ######################################################################
31
32 # Directories and files
33
34 # these are the default autocluster config options
35 # please override with your own options in your own config file
36
37 defconf VIRTBASE /virtual \
38         "<path>" "virtual machine directory for this host"
39
40 # the name of the base RHEL install image that the nodes will be based on
41 # a kvm image called $VIRTBASE/$BASENAME.img will be created
42 # that will form the basis file for the images for each of the nodes
43 defconf BASENAME "ac-base" \
44         "<file>" "filename for cluster base image"
45
46 defconf BASE_PER_NODE_TYPE "no" \
47         "<yes|no>" "Use per-node-type base images"
48
49 defconf DISK_FOLLOW_SYMLINKS "no" \
50         "<yes|no>" "If disk images use symlinks then follow them to overwrite"
51
52 ######################################################################
53
54 # Virtualisation
55
56 defconf VIRSH "virsh -c qemu:///system" \
57         "<cmd>" "how to invoke virsh"
58
59 defconf KVM "@uto" \
60         "<file>"  "location of KVM executable"
61
62 defconf KVMLOG "/var/log/kvm" \
63         "<dir>" "directory for serial logs"
64
65 defconf NODE_TEMPLATE "$installdir/templates/node.xml" \
66         "<file>" "libvirt template for nodes"
67
68 defconf INSTALL_TEMPLATE "$installdir/templates/install.xml" \
69         "<file>" "libvirt template for initial install"
70
71 defconf INSTALL_KERNEL_OPTIONS "@uto" \
72         "<options>" "installer kernel command-line options"
73
74 defconf BOOT_TEMPLATE "$installdir/templates/bootbase.xml" \
75         "<file>" "libvirt template for \"bootbase\" command"
76
77 defconf BASE_TEMPLATES "$installdir/base" \
78         "<dir>" "directory containing base templates"
79
80 defconf BASE_FORMAT "qcow2" \
81         "<fmt>" "format to use for the qemu base images"
82
83 defconf SYSTEM_DISK_TYPE "ide" \
84         "scsi|ide|virtio" "type of disks to use in nodes"
85
86 rhel_disk_prefix ()
87 {
88     case "$1" in
89         (scsi|iscsi) echo "sd" ;;
90         (virtio)     echo "vd" ;;
91         ide)
92             case "$RHEL_VERSION" in
93                 (5.*) echo "hd" ;;
94                 ([67].*) echo "sd" ;;
95                 (*) die "Unknown RHEL_VERSION in rhel_disk_prefix" ;;
96             esac
97             ;;
98         (*) die "Unknown disk type \"$1\" in rhel_disk_prefix" ;;
99             
100     esac
101 }
102
103 defconf SYSTEM_DISK_PREFIX "@uto" \
104         "sd|hd|vd" "system disk device prefix"
105
106 defconf SYSTEM_DISK_CACHE "writeback" \
107         "default|none|writeback|writethrough" "system disk cache type"
108
109 defconf SYSTEM_DISK_FORMAT "qcow2" \
110         "qcow2|raw|reflink|mmclone|none" "system disk image format"
111
112 defconf SYSTEM_DISK_ACCESS_METHOD "@uto" \
113         "loopback|guestfish|guestmount" "how to setup up disk images"
114
115 system_disk_access_method_hook ()
116 {
117     if [ "$SYSTEM_DISK_ACCESS_METHOD" = "@uto" ] ; then
118         if [ "$SYSTEM_DISK_FORMAT" = "qcow2" ] ; then
119             if which guestmount >/dev/null 2>&1 ; then
120                 SYSTEM_DISK_ACCESS_METHOD="guestmount"
121             elif which guestfish >/dev/null 2>&1 ; then
122                 SYSTEM_DISK_ACCESS_METHOD="guestfish"
123             elif which qemu-nbd nbd-client >/dev/null 2>&1 ; then
124                 SYSTEM_DISK_ACCESS_METHOD="loopback"
125             else
126                 die "Can't determine SYSTEM_DISK_ACCESS_METHOD.  Need guestfish or qemu-nbd + nbd-client."
127             fi
128         else
129             SYSTEM_DISK_ACCESS_METHOD="loopback"
130         fi
131     fi
132 }
133
134 register_hook post_config_hooks system_disk_access_method_hook
135
136 system_disk_mounts ()
137 {
138     # We could call a function using call_func().  However, we want
139     # the options listed in the documentation for
140     # SYSTEM_DISK_ACCESS_METHOD, so they need to be hardcoded...  so
141     # we might as well hardcode this function (for now).
142     case "$SYSTEM_DISK_ACCESS_METHOD" in
143         loopback)
144             case "$RHEL_VERSION" in
145                 (5.*) echo "/:32256" ;;
146                 ([67].*) echo "/:1048576" ;;
147                 (*) die "Unknown RHEL_VERSION in system_disk_mounts" ;;
148             esac
149             ;;
150         (guestfish|guestmount) : ;;
151         (*) die "Unknown SYSTEM_DISK_ACCESS_METHOD in system_disk_mounts" ;;
152     esac
153 }
154
155 defconf SYSTEM_DISK_MOUNTS "@uto" \
156         "<list>" "list of mountpoints and offsets/devices for mount_disk()"
157
158 ######################################################################
159
160 # Node
161
162 # what timezone to put the nodes in
163 # leave this empty to base the timezone on the zone that
164 # this host is in
165 defconf TIMEZONE "" \
166         "<tz>" "timezone for each node"
167
168 # how much disk space to use on each node
169 # note that it will only use what is actually occupied,
170 # so start this larger than you think you'll need
171 defconf DISKSIZE "20G" \
172         "<n>G" "maximum disk size for each node"
173
174 defconf ROOTSIZE 15000 \
175         "<n>" "size of root partition in MB"
176
177 defconf SWAPSIZE 2000 \
178         "<n>" "size of swap partition in MB"
179
180 rhel_default_mem ()
181 {
182     case "$RHEL_VERSION" in
183         (5.*) echo "262144" ;;
184         ([67].*) echo "512000" ;;
185         (*) die "Unknown RHEL_VERSION in rhel_default_mem" ;;
186     esac
187 }
188
189 defconf MEM "@uto" \
190         "<n>" "memory allocated for each node"
191
192 defconf NICMODEL "e1000" \
193         "<module>" "choice of KVM network adapter"
194
195 defconf ROOTPASSWORD "password" \
196         "<string>" "initial root password for each node"
197
198 defconf NUMCPUS 2 \
199         "<n>" "number of virtual CPUs per node"
200
201 # Some machines need "clocksource=jiffies"
202 defconf EXTRA_KERNEL_OPTIONS "" \
203         "<string>" "extra kernel options for nodes"
204
205 defconf HOSTNAME_HACKING_FUNCTION "" \
206         "<string>" "function to modify node hostnames, see the code for details"
207
208 defconf HOSTS_STATIC_ENTRIES "/dev/null" \
209         "<file>" "a file containing extra static entries to add to /etc/hosts"
210
211 ######################################################################
212
213 # Networking
214
215 defconf DOMAIN "EXAMPLE.COM" \
216         "<dom>" "Windows(TM) domain name for each node"
217
218 defconf WORKGROUP "EXAMPLE" \
219         "<grp>" "Windows(TM) workgroup for node"
220
221 # DNS name server. Usually set this to the
222 # kvm host, then setup DNS on the kvm host to direct 
223 # queries for the windows domain name to the w2003 server
224 defconf NAMESERVER "10.0.0.1" \
225         "<ip>" "DNS server for each node"
226
227 defconf DNSSEARCH "$DOMAIN" \
228         "<dom>" "extra domains for DNS search list"
229
230 # Networks:
231 # * First network is private and contains the CTDB node addresses.
232 # * Items look like: net/bits,dev[,nat|bridge=host_iface][,gw=gateway_ip]
233
234 # * Right now autocluster only supports 24 bit networks.  This will
235 #   be improved in the future.
236 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" \
237         "<list>" "description of IP networks"
238
239 make_public_addresses()
240 {
241         local firstip="${1:-$[${FIRSTIP} + ${PUBLIC_IP_OFFSET}]}"
242         local num_addrs="${2:-${NUMNODES}}"
243
244         if [ $(( $firstip + $num_addrs - 1 )) -gt 254 ]; then
245             die "make_public_addresses: last octet > 254 - change PUBLIC_IP_OFFSET"
246         fi
247
248         local n
249         for n in $NETWORKS_PUBLIC ; do
250             local dev="${n#*,}" # Strip address, comma
251             dev="${dev%,*}" # Strip comma, interface
252             echo -ne "${n%.*}.${firstip},${num_addrs},${dev} "
253         done
254         echo
255 }
256
257 networks_post_config_hook ()
258 {
259     local n
260     for n in $NETWORKS ; do
261         local ip_mask="${n%%,*}"
262         local mask="${ip_mask#*/}"
263
264         [ "$mask" = "24" ] || \
265             die "Network maskbits other than 24 unsupported in \"$n\""
266     done
267
268     [ -z "$IPBASE" -a -z "$IPNET0" -a -z "$IPNET1" -a -z "$IPNET2" ] || \
269         die "Configuration variables IPBASE, IPNET0/1/2 unsupported - please use NETWORKS"
270
271     # Convenience variables
272     set -- $NETWORKS
273     NETWORK_PRIVATE="$1" ; shift
274     local t="${NETWORK_PRIVATE%%,*}"
275     NETWORK_PRIVATE_PREFIX="${t%.*}"
276     NETWORKS_PUBLIC="$*"
277 }
278
279 register_hook post_config_hooks networks_post_config_hook
280
281 defconf NETWORK_TEMPLATE "|network_template" \
282         "<file>" "libvirt template fragment for networks"
283
284 network_template ()
285 {
286     local netname dev ip mask mac opts
287     while read netname dev ip mask mac opts ; do
288         cat <<EOF
289     <interface type='network'>
290       <mac address='${mac}'/>
291       <model type='@@NICMODEL@@'/>
292       <source network='${netname}'/>
293     </interface>
294 EOF
295     done <"$network_map"
296 }
297
298
299 # the nodes will get IPs starting at this number 
300 # the TSM server will get $FIRSTIP, then the first node will get
301 # the next IP etc
302 # so if the private network is 10.0.0.0/24,eth0 and FIRSTIP is 20 then
303 # you will get nodes like this:
304 #     tsmserver   10.0.0.20
305 #     1st node    10.0.0.21
306 #     2nd node    10.0.0.22
307 # etc etc
308 defconf FIRSTIP "20" \
309         "<n>" "final octet for the 1st IP of the cluster"
310
311 # Public addresses managed by CTDB.
312 defconf PUBLIC_IP_OFFSET 100 \
313         "<n>" "offset from FIRSTIP of public IP addresses"
314
315 defconf PUBLIC_ADDRESSES "|make_public_addresses" \
316         "<cmd>" "template for public address entry in nas.conf"
317
318 # a caching web proxy that can get to the install server from the
319 # nodes. If you don't have one on the local network then look in
320 # host_setup/etc/squid for an example setup you can install on the kvm
321 # host. The web proxy must cache large objects, and have room for
322 # several G of cache You can choose to have no web proxy at all, in
323 # which case set it to the empty string, and hope you have a fast
324 # network connection to the install server
325 defconf WEBPROXY "" \
326         "<url>" "URL of a caching web proxy"
327
328 defconf KVMHOST "10.0.0.1" \
329         "<ip>" "KVM host - provides things like NTP, iSCSI targets, ..."
330
331 defconf KDC_NAME "example-ad" \
332         "<name>" "prefix of the name of the KDC"
333
334 ######################################################################
335
336 # RHEL
337
338 rhel_print_iso ()
339 {
340     # Uses: RHEL_VERSION, RHEL_ARCH
341     # Prints: a value for ISO
342
343     local datever
344
345     case "$RHEL_VERSION" in
346         (5.1) datever="20071017.0";;
347         (5.2) datever="20080430.0";;
348         (5.3) datever="20090106.0";;
349         (5.4) datever="20090819.0";;
350         (5.5) datever="20100322.0";;
351         (5.6) datever="20110106.0";;
352         (5.7) datever="20110711.5";;
353         (5.8) datever="20120202.0";;
354         (6.0) datever="20100922.1";;
355         (6.1) datever="20110510.1";;
356         (6.2) datever="20111117.0";;
357         (6.3) datever="20120613.2";;
358         (6.4) datever="20130130.0";;
359         (6.5) datever="20131111.0";;
360         (7.0) datever="20140507.0";;
361         (*) die "Unknown RHEL_VERSION in rhel_print_iso" ;;
362     esac
363
364     case "$RHEL_VERSION" in
365         (5.*) echo "RHEL${RHEL_VERSION}-Server-${datever}-${RHEL_ARCH}-DVD.iso"  ;;
366         (6.*) echo "RHEL${RHEL_VERSION}-${datever}-Server-${RHEL_ARCH}-DVD1.iso" ;;
367         (7.*) echo "RHEL-${RHEL_VERSION}-${datever}-Server-${RHEL_ARCH}-dvd1.iso" ;;
368     esac
369 }
370
371 # yum repo infrastructure
372 _YUM_TEMPLATE="$installdir/templates/RHEL.repo" # Private - used below!
373 rhel_gen_yum_repos ()
374 {
375     echo "# Generated by autocluster."
376
377     for repo ; do
378 # Repo IDs can not contain slashes, so replace slashes with dashes.
379 cat <<EOF
380 [${repo//\//-}]
381 name=${repo}
382 baseurl=@@INSTALL_SERVER@@/${repo}
383 enabled=1
384 gpgcheck=0
385
386 EOF
387     done
388
389 cat <<EOF
390 @@@_YUM_TEMPLATE@@@
391 EOF
392 }
393
394 get_kvm_path ()
395 {
396     local t
397
398     if t=$(which qemu-kvm 2>/dev/null) ; then
399         echo "$t"
400     elif t=$(which kvm 2>/dev/null) ; then
401         echo "$t"
402     elif [ -x "/usr/libexec/qemu-kvm" ] ; then
403         echo "/usr/libexec/qemu-kvm"
404     else
405         die "Could not find KVM executable"
406     fi
407
408 }
409
410 rhel_get_install_kernel_options ()
411 {
412     case "$RHEL_VERSION" in
413         (7.*) echo "ks=hd:LABEL=KICKSTART inst.stage2=hd:LABEL=RHEL-${RHEL_VERSION}\\\\x20Server.${RHEL_ARCH}" ;;
414         (*) echo "ks=floppy" ;;
415     esac
416 }
417
418 rhel_get_install_ks_device_xml ()
419 {
420     if [ ${RHEL_VERSION%%.*} -le 6 ] ; then
421         cat <<EOF
422     <disk type='file' device='floppy'>
423       <source file='@@PWD@@/tmp/floppy.img'/>
424       <target dev='fda'/>
425       <readonly/>
426     </disk>
427 EOF
428     else
429         cat <<EOF
430     <disk type='file' device='disk'>
431       <source file='@@PWD@@/tmp/floppy.img'/>
432       <target dev='@@SYSTEM_DISK_PREFIX@@b' bus='@@SYSTEM_DISK_TYPE@@'/>
433       <driver name='qemu' type='raw'/>
434     </disk>
435 EOF
436     fi
437 }
438
439 rhel_get_multipath_magic ()
440 {
441     if [ ${RHEL_VERSION%%.*} -le 6 ] ; then
442         cat <<EOF
443  udev_dir                /dev
444  getuid_callout          "$SHARED_DISK_MULTIPATH_CALLOUT"
445 EOF
446     fi
447 }
448
449 rhel_post_config_hook ()
450 {
451     if [ "$ISO" = "@uto" ] ; then
452         ISO=$(rhel_print_iso) || exit $?
453     fi
454
455     if [ "$SYSTEM_DISK_MOUNTS" = "@uto" ] ; then
456         SYSTEM_DISK_MOUNTS=$(system_disk_mounts) || exit $?
457     fi
458
459     if [ "$MEM" = "@uto" ] ; then
460         MEM=$(rhel_default_mem) || exit $?
461     fi
462
463     if [ "$SYSTEM_DISK_PREFIX" = "@uto" ] ; then
464         SYSTEM_DISK_PREFIX=$(rhel_disk_prefix $SYSTEM_DISK_TYPE) || exit $?
465     fi
466
467     if [ "$KVM" = "@uto" ] ; then
468         KVM=$(get_kvm_path) || exit $?
469     fi
470
471     if [ "$INSTALL_KERNEL_OPTIONS" = "@uto" ] ; then
472         INSTALL_KERNEL_OPTIONS=$(rhel_get_install_kernel_options) || exit $?
473     fi
474
475     if [ "$INSTALL_KS_DEVICE_TEMPLATE" = "@uto" ] ; then
476         INSTALL_KS_DEVICE_TEMPLATE=$(rhel_get_install_ks_device_xml) || exit $?
477     fi
478
479     if [ "$RHEL_MULTIPATH_MAGIC" = "@uto" ] ; then
480         RHEL_MULTIPATH_MAGIC=$(rhel_get_multipath_magic) || exit $?
481     fi
482 }
483
484 register_hook post_config_hooks rhel_post_config_hook
485
486 defconf RHEL_ARCH "x86_64" \
487         "<arch>" "The RHEL operating system architecture to configure"
488
489 defconf RHEL_VERSION "6.2" \
490         "<version>" "version of Red Hat Enterprise Linux to configure"
491
492 defconf RHEL_MULTIPATH_MAGIC "@uto"
493
494 defconf ISO_DIR "/virtual/ISO" \
495         "<dir>" "directory for ISO images, prepended to $ISO if not absolute"
496
497 defconf ISO "@uto" \
498         "<file>" "ISO image for base image creation"
499
500 # the install server where we will get local packages from
501 defconf INSTALL_SERVER "http://10.0.0.1/mediasets" \
502         "<url>" "URL of install server"
503
504 defconf CONFIG_EXTRA_PACKAGES "" \
505         "<packages>" "list of extra packages to install at configuration time"
506
507 # the yum repositories to use. Choose the one appropriate for the
508 # system you are installing
509 defconf YUM_TEMPLATE "$_YUM_TEMPLATE" \
510         "<file>" "location of template for yum repositories"
511
512 defconf INSTALL_KS_DEVICE_TEMPLATE "@uto"
513
514 ##############################
515
516 defconf CREATE_BASE_TIMEOUT 3600 \
517         "<seconds>" "time to wait for base image install before aborting" 
518
519 ##############################
520
521 register_hook hack_nodes_functions hack_nodes_rhel_base
522
523 hack_nodes_rhel_base ()
524 {
525     local node_count_rhel_base=0
526     hack_filter ()
527     {
528         case "$node_type" in
529             rhel_base)
530                 node_count_rhel_base=$(($node_count_rhel_base + 1))
531                 name="${CLUSTER}base${node_count_rhel_base}"
532                 # rhel_base nodes are not part of CTDB cluster
533                 ctdb_node=0
534             esac
535     }
536     hack_all_nodes_with hack_filter
537 }
538
539 create_node_rhel_base ()
540 {
541     local ip_offset="$1"
542     local name="$2"
543     local ctdb_node="$3"
544
545     echo "Creating RHEL base node $name"
546     create_node_COMMON "$name" "$ip_offset" "$type"
547 }
548
549 ##############################
550
551 # Authentication method
552 defconf AUTH_METHOD "files" \
553     "files|winbind" "authentication method"
554
555 ##############################