summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Schwenke <martin@meltin.net>2019-02-06 17:43:50 +1100
committerMartin Schwenke <martin@meltin.net>2019-03-25 16:52:07 +1100
commit7003df8ad2ec9eaa119439f21976e7117b1771e5 (patch)
treea83bb8c23f8212dd66a13301aa7dbd23adbcbe2f
parentfc6fd0765f3c22b21478113378d00434e6315610 (diff)
downloadautocluster-7003df8ad2ec9eaa119439f21976e7117b1771e5.tar.gz
autocluster-7003df8ad2ec9eaa119439f21976e7117b1771e5.tar.xz
autocluster-7003df8ad2ec9eaa119439f21976e7117b1771e5.zip
Add a Vagrantfile and supporting scripts
Generates libvirt nodes according to configuration. Signed-off-by: Martin Schwenke <martin@meltin.net>
-rw-r--r--vagrant/Vagrantfile114
-rwxr-xr-xvagrant/autocluster_check_ips.sh11
-rw-r--r--vagrant/autocluster_ssh_node_setup.sh24
3 files changed, 149 insertions, 0 deletions
diff --git a/vagrant/Vagrantfile b/vagrant/Vagrantfile
new file mode 100644
index 0000000..8bf508b
--- /dev/null
+++ b/vagrant/Vagrantfile
@@ -0,0 +1,114 @@
+# -*- mode: ruby -*-
+# vi: ft=ruby:et:ts=2:sts=2:sw=2
+
+VAGRANTFILE_API_VERSION = "2"
+
+require 'yaml'
+require 'ipaddr'
+require 'resolv'
+require 'securerandom'
+
+f = ENV['AUTOCLUSTER_STATE'] + '/config.yml'
+if File.exists?(f)
+ settings = YAML::load_file f
+
+ puts "Loaded config from #{f}."
+end
+
+def resolvURL(url)
+ u = URI.parse(url)
+ u.host = Resolv.getaddress(u.host)
+ u.to_s
+end
+
+shared_disk_ids = []
+for i in 1..settings['shared_disks']['count']
+ shared_disk_ids[i] = sprintf('AUTO-%02d-', i) + SecureRandom.uuid[0..7]
+end
+
+#
+# The vagrant machine definitions
+#
+
+Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
+
+ if ENV['http_proxy'] or ENV['https_proxy']
+ if Vagrant.has_plugin?("vagrant-proxyconf")
+ if ENV['http_proxy']
+ config.proxy.http = resolvURL(ENV['http_proxy'])
+ end
+ if ENV['http_proxys']
+ config.proxy.https = resolvURL(ENV['http_proxys'])
+ end
+ config.proxy.no_proxy = "localhost,127.0.0.1"
+ end
+ end
+
+ if Vagrant.has_plugin?("vagrant-libvirt")
+ config.vm.provider :libvirt do |libvirt|
+ libvirt.storage_pool_name = "autocluster"
+ end
+ end
+
+ settings['nodes'].each do |hostname, node|
+ config.vm.define hostname do |v|
+ v.vm.box = settings['vagrant_box']
+ v.vm.hostname = hostname
+
+ node['ips'].each do |ip|
+ v.vm.network "private_network",
+ ip: ip,
+ nm_controlled: "no"
+ end
+
+ if settings['virthost']
+ virthost = settings['virthost']
+ v.vm.provision "shell",
+ run: "always",
+ inline: "route add default gw " + virthost + "|| :"
+ end
+
+ # No shared folders - they might require extra software on the
+ # nodes and installation can time out :-(
+ v.vm.synced_folder ".", "/vagrant", disabled: true
+
+ v.vm.provision "file",
+ source: "~/.ssh/id_autocluster",
+ destination: "~/.ssh/id_autocluster"
+ v.vm.provision "file",
+ source: "~/.ssh/id_autocluster.pub",
+ destination: "~/.ssh/id_autocluster.pub"
+ v.vm.provision :shell,
+ privileged: true,
+ path: "autocluster_ssh_node_setup.sh"
+
+ v.vm.provider :libvirt do |libvirt|
+
+ libvirt.default_prefix = 'autocluster'
+ libvirt.cpus = settings['cpus']
+ #FIXME: causes an error ### libvirt.memory = settings['memory']
+
+ if node['has_shared_storage']
+ for i in 1..settings['shared_disks']['count']
+ libvirt.storage :file,
+ :serial => shared_disk_ids[i],
+ :path => sprintf('autocluster_%s_shared%02d.img',
+ settings['cluster'], i),
+ :size => settings['shared_disks'].size,
+ :allow_existing => true,
+ :shareable => true,
+ :type => 'raw'
+ end
+ end
+ end
+
+ # The libvirt provider sometimes configures a private network
+ # but doesn't bring it up. Check that all desired IPs are
+ # assigned, failing if any are missing.
+ v.vm.provision "shell",
+ run: "always",
+ path: "autocluster_check_ips.sh",
+ args: node['ips']
+ end
+ end
+end
diff --git a/vagrant/autocluster_check_ips.sh b/vagrant/autocluster_check_ips.sh
new file mode 100755
index 0000000..d6b23cf
--- /dev/null
+++ b/vagrant/autocluster_check_ips.sh
@@ -0,0 +1,11 @@
+#!/bin/sh
+
+for ip ; do
+ out=$(ip addr show to "$ip")
+
+ if [ -z "$out" ] ; then
+ echo "ERROR: ${ip} was not found on an interface"
+ ip addr
+ exit 1
+ fi
+done
diff --git a/vagrant/autocluster_ssh_node_setup.sh b/vagrant/autocluster_ssh_node_setup.sh
new file mode 100644
index 0000000..aeea98a
--- /dev/null
+++ b/vagrant/autocluster_ssh_node_setup.sh
@@ -0,0 +1,24 @@
+#!/bin/sh
+
+set -e
+
+user="vagrant"
+key="id_autocluster"
+
+u_ssh="/home/${user}/.ssh"
+r_ssh="/root/.ssh"
+
+mkdir -p "$r_ssh"
+chmod 700 "$r_ssh"
+cp "${u_ssh}/${key}" "${r_ssh}/"
+cp "${u_ssh}/${key}.pub" "${r_ssh}/"
+cat "${u_ssh}/${key}.pub" >> "${r_ssh}/authorized_keys"
+if selinuxenabled >/dev/null 2>&1 ; then
+ #chcon -t ssh_home_t "${r_ssh}/authorized_keys"
+ restorecon -R "$r_ssh"
+fi
+cat "${u_ssh}/${key}.pub" >> "${u_ssh}/authorized_keys"
+if selinuxenabled >/dev/null 2>&1 ; then
+ #chcon -t ssh_home_t "${u_ssh}/authorized_keys"
+ restorecon -R "$u_ssh"
+fi