Vagrantfile: systematic use of name lv for libvirt provider
[obnox/vagrant/vagrant-gluster-samba-cluster.git] / Vagrantfile
index 21d5e661ae76e990ac0c79c53081d961e5e88f6b..94a876144fa66416d5d21668b1d29c1caebbeda9 100644 (file)
@@ -36,6 +36,11 @@ defaults = {
   :provider => {
     :libvirt => {
       :prefix => 'vagrant',
+      :box => 'fedora/23-cloud-base',
+    },
+    :virtualbox => {
+      :prefix => 'vagrant',
+      :box => 'fedora/23-cloud-base',
     },
   },
 }
@@ -54,7 +59,6 @@ vms = [
         #:container_name => 'node1',
       },
       :libvirt => {
-        :box => 'local-fedora-21.2',
         :prefix => 'gluster',
       }, 
     },
@@ -72,6 +76,7 @@ vms = [
   },
 ]
 
+
 #
 # Load the config, if it exists,
 # possibly override with commandline args,
@@ -150,10 +155,6 @@ end
 #print cluster_internal_ips
 #print "\n"
 
-#PROVISION_SCRIPT = <<SCRIPT
-#yum -y install make samba
-#SCRIPT
-
 
 NET_FIX_ALWAYS_SCRIPT = <<SCRIPT
 set -e
@@ -203,33 +204,6 @@ ifup eth1
 SCRIPT
 
 
-CTDB_CREATE_CONF_SCRIPT = <<SCRIPT
-set -e
-
-BACKUP_SUFFIX=".orig.$(date +%Y%m%d-%H%M%S)"
-
-RECLOCKDIR="$1"
-mkdir -p ${RECLOCKDIR}
-RECLOCKFILE=${RECLOCKDIR}/reclock
-
-PUBLIC_ADDRESSES_FILE=/etc/ctdb/public_addresses
-NODES_FILE=/etc/ctdb/nodes
-
-FILE=/etc/sysconfig/ctdb
-test -f ${FILE} || touch ${FILE}
-cp -f -a ${FILE} ${FILE}${BACKUP_SUFFIX}
-
-echo -n > ${FILE}
-cat <<EOF >> ${FILE}
-CTDB_NODES=${NODES_FILE}
-#CTDB_PUBLIC_ADDRESSES=${PUBLIC_ADDRESSES_FILE}
-CTDB_RECOVERY_LOCK=${RECLOCKFILE}
-CTDB_MANAGES_SAMBA="yes"
-CTDB_SAMBA_SKIP_SHARE_CHECK="yes"
-#CTDB_MANAGES_WINBIND="yes"
-EOF
-SCRIPT
-
 SAMBA_CREATE_CONF_SCRIPT = <<SCRIPT
 set -e
 
@@ -273,6 +247,55 @@ cat <<EOF >> ${FILE}
 EOF
 SCRIPT
 
+
+#
+# disks: hard-coded for all nodes for now:
+# TODO: make (some of) these configurable ...
+#
+disks = [
+      {
+        :size => 1, # in GB
+        #:volname => "gv0",
+      },
+      {
+        :size => 10,
+        #:volname => "gv1",
+      },
+]
+
+driveletters = ('b'..'z').to_a
+
+#brick_mount_prefix = "/export"
+brick_mount_prefix = "/bricks"
+brick_path_suffix = "brick"
+gluster_volume_prefix = "gv"
+gluster_mount_prefix = "/gluster"
+
+disks.each_with_index do |disk,disk_num|
+  disk[:number] = disk_num
+  disk[:volume_name] = "#{gluster_volume_prefix}#{disk[:number]}"
+  disk[:volume_mount_point] = "#{gluster_mount_prefix}/#{disk[:volume_name]}"
+  disk[:dev_names] = {
+    :libvirt => "vd#{driveletters[disk[:number]]}",
+    :virtualbox => "sd#{driveletters[disk[:number]]}",
+  }
+  disk[:dev_name] = "sd#{driveletters[disk[:number]]}"
+  disk[:brick_name] = "brick0"
+  disk[:label] = "#{disk[:volume_name]}-#{disk[:brick_name]}"
+  disk[:brick_mount_point] = "#{brick_mount_prefix}/#{disk[:label]}"
+  disk[:brick_path] = "#{disk[:brick_mount_point]}/#{brick_path_suffix}"
+end
+
+# /dev/{sv}db --> xfs filesys (on /dev/{sv}db1)
+#  --> mount unter /bricks/gv0
+#    --> dir /bricks/gv0/brick --> dir for gluster createvol gv0
+#      --> gluster/fuse mount /gluster/gv0
+
+
+my_config = {
+  :provider => :libvirt,
+}
+
 #
 # The vagrant machine definitions
 #
@@ -280,6 +303,7 @@ SCRIPT
 Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
 
   config.vm.synced_folder ".", "/vagrant", disabled: true
+  #config.vm.synced_folder './', '/vagrant', type: '9p', disabled: false, accessmode: "squash", owner: "vagrant"
 
   #if Vagrant.has_plugin?("vagrant-cachier")
   #  config.cache.scope = :machine
@@ -298,24 +322,44 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
   # just let one node do the probing
   probing = false
 
-  vms.each do |machine|
+  vms.each_with_index do |machine,machine_num|
     config.vm.define machine[:hostname] do |node|
       node.vm.box = machine[:provider][:libvirt][:box]
       node.vm.hostname = machine[:hostname]
 
-      node.vm.provider :libvirt do |libvirt|
-        libvirt.default_prefix = machine[:provider][:libvirt][:prefix]
-        libvirt.memory = 1024
-        libvirt.storage :file, :size => '64M', :device => 'vdb'
-        libvirt.storage :file, :size => '10G', :device => 'vdc'
+      print "machine #{machine_num}: #{machine[:hostname]}\n"
+
+      node.vm.provider :libvirt do |lv|
+        lv.default_prefix = machine[:provider][:libvirt][:prefix]
+        lv.memory = 1024
+      end
+
+      node.vm.provider :virtualbox do |vb|
+        vb.memory = 1024
+      end
 
-        machine[:networks].each do |net|
-          if not net[:ipv4] == ''
-            node.vm.network :private_network, :ip => net[:ipv4]
-          end
+      disks.each do |disk|
+        node.vm.provider :libvirt do |lv|
+          print " [libvirt] attaching disk ##{disk[:number]}: #{disk[:dev_name]}\n"
+          lv.storage :file, :size => "#{disk[:size]}G", :device => "#{disk[:dev_names][:libvirt]}"
+          #lv.storage :file, :size => "#{disk[:size]}G", :bus => "sata" , :device => "#{disk[:dev_name]}"
+        end
+        node.vm.provider :virtualbox do |vb|
+          disk_size = disk[:size]*1024
+          #disk_file = "disk-#{machine_num}-#{disk[:dev_names][:virtualbox]}.vdi"
+          #print " [virtualbox] disk ##{disk[:number]}: #{disk[:dev_names][:virtualbox]}\n"
+          disk_file = "disk-#{machine_num}-#{disk[:dev_name]}.vdi"
+          print " [virtualbox] attaching disk ##{disk[:number]}: #{disk[:dev_name]}\n"
+          vb.customize [ "createhd", "--filename", disk_file, "--size", disk_size ]
+          vb.customize [ "storageattach", :id, "--storagectl", "SATA Controller", "--port", 3+disk[:number], "--device", 0, "--type", "hdd", "--medium", disk_file ]
         end
       end
 
+      machine[:networks].each do |net|
+        if not net[:ipv4] == ''
+          node.vm.network :private_network, :ip => net[:ipv4]
+        end
+      end
 
       node.vm.provision "selinux", type: "shell" do |s|
         s.path = "provision/shell/sys/selinux-off.sh"
@@ -352,16 +396,14 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
       ###  s.args = [ '/gluster/gv0', '/gluster/gv1' ]
       ###end
 
-      # multiple privisioners with same name possible?
-      node.vm.provision "xfs_0", type: "shell" do |s|
-        s.path = "provision/shell/gluster/create-brick.sh"
-        s.args = [ "vdb", "/export" ]
-      end
-
-      node.vm.provision "xfs_1", type: "shell" do |s|
-        s.path = "provision/shell/gluster/create-brick.sh"
-        s.args = [ "vdc", "/export" ]
+      disks.each do |disk|
+        print " create_brick: size #{disk[:size]}G, label #{disk[:label]} under #{disk[:brick_mount_point]}\n"
+        node.vm.provision "create_brick_#{disk[:number]}", type: "shell" do |s|
+          s.path = "provision/shell/gluster/create-brick.v2.sh"
+          s.args = [ "#{disk[:size]}G", disk[:label], disk[:brick_mount_point], brick_path_suffix ]
+        end
       end
+      
 
       node.vm.provision "gluster_start", type: "shell" do |s|
         s.path = "provision/shell/gluster/gluster-start.sh"
@@ -373,38 +415,30 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
           s.path = "provision/shell/gluster/gluster-probe.sh"
           s.args = cluster_internal_ips
         end
-        probing = false
       end
 
       node.vm.provision "gluster_wait_peers", type: "shell" do |s|
         s.path = "provision/shell/gluster/gluster-wait-peers.sh"
-        s.args = [ cluster_internal_ips.length, 300]
+        s.args = [ cluster_internal_ips.length, 300 ]
       end
 
-      node.vm.provision "gluster_createvol_0", type: "shell" do |s|
-        mount_points = cluster_internal_ips.map do |ip|
-          "#{ip}:/export/vdb1/brick"
-        end
-        s.path = "provision/shell/gluster/gluster-create-volume.sh"
-        s.args = [ "gv0", "3" ] + mount_points
-      end
 
-      node.vm.provision "gluster_mount_0", type: "shell" do |s|
-        s.path = "provision/shell/gluster/gluster-mount-volume.sh"
-        s.args = [ "gv0", "/gluster/gv0" ]
-      end
+      disks.each do |disk|
+        brick_mount_points = cluster_internal_ips.map do |ip|
+          "#{ip}:#{disk[:brick_path]}"
+        end
+        
+        print " brick directories: #{brick_mount_points}\n"
 
-      node.vm.provision "gluster_createvol_1", type: "shell" do |s|
-        mount_points = cluster_internal_ips.map do |ip|
-          "#{ip}:/export/vdc1/brick"
+        node.vm.provision "gluster_createvol_#{disk[:number]}", type: "shell" do |s|
+          s.path = "provision/shell/gluster/gluster-create-volume.sh"
+          s.args = [ disk[:volume_name], "3" ] + brick_mount_points
         end
-        s.path = "provision/shell/gluster/gluster-create-volume.sh"
-        s.args = [ "gv1", "3" ] + mount_points
-      end
 
-      node.vm.provision "gluster_mount_1", type: "shell" do |s|
-        s.path = "provision/shell/gluster/gluster-mount-volume.sh"
-        s.args = [ "gv1", "/gluster/gv1" ]
+        node.vm.provision "gluster_mount_#{disk[:number]}", type: "shell" do |s|
+          s.path = "provision/shell/gluster/gluster-mount-volume.sh"
+          s.args = [ disk[:volume_name], disk[:volume_mount_point] ]
+        end
       end
 
       #
@@ -426,7 +460,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
       #end
 
       node.vm.provision "ctdb_create_conf", type: "shell" do |s|
-        s.inline = CTDB_CREATE_CONF_SCRIPT
+        s.path = "provision/shell/ctdb/ctdb-create-conf.sh"
         s.args = [ "/gluster/gv0/ctdb" ]
       end