#!/usr/bin/env ruby require 'rubygems' require 'trollop' SUB_COMMANDS = %w[ init append add grow remove ] opts = Trollop::options do banner <<-EOS This script will manage mirrored EBS volumes and lvm volume groups. Usage: pipette [global options] subcommand [options] Where subcommand is one of #{SUB_COMMANDS.inspect} Global Options: EOS opt :access_key, "AWS Access Key", :short => "-a", :default => ENV['ACCESS_KEY'] opt :secret_access_key, "AWS Secret Access Key", :short => "-c", :default => ENV['SECRET_ACCESS_KEY'] stop_on SUB_COMMANDS end cmd = ARGV.shift cmd_opts = case cmd when "init" Trollop::options do banner "Create an initial volume group of EBS mirrored volumes" opt :name , "Name of volume group to create" , :short => "-n", :required => true, :type => :string opt :size , "Size of initial volume in GB" , :short => "-s", :required => true, :type => :int opt :ebs_per_mirror, "Number of EBS volumes to put in each mirrored disk" , :default => 2 , :type => :int opt :num_mirrors , "Number of mirrors to create; will be spanned by the volume group", :default => 2 , :type => :int end when "append" Trollop::options do banner "Add another set of mirrored EBS volumes to the volume group" opt :name , "Name of volume group to append to" , :short => "-n", :required => true, :type => :string opt :size , "Size of initial volume in GB" , :short => "-s", :required => true, :type => :int opt :ebs_per_mirror, "Number of EBS volumes to put in each mirrored disk" , :default => 2 , :type => :int opt :num_mirrors , "Number of mirrors to create; will be spanned by the volume group", :default => 1 , :type => :int end when "add" Trollop::options do banner "Create a new logical volume in the volume group" opt :name , "Name of new logical volume" , :short => "-n", :required => true, :type => :string opt :volume, "Name of volume group to use" , :short => "-v", :required => true, :type => :string opt :size , "Size of new logical volume", :short => "-s", :required => true, :type => :int end when "grow" Trollop::options do banner "Increase the size of a logical volume" opt :name , "Name of logical volume" , :short => "-n", :required => true, :type => :string opt :volume, "Name of volume group to use" , :short => "-v", :required => true, :type => :string opt :size , "Size to increase logical volume to or '+n' to increase size by nGB", :short => "-s", :required => true, :type => :string end when "remove" Trollop::options do banner "Remove a logical volume" opt :name , "Name of logical volume" , :short => "-n", :required => true, :type => :string opt :volume, "Name of volume group to use", :short => "-v", :required => true, :type => :string end else Trollop::die "unknown subcommand #{cmd.inspect}" end begin require 'pipette' rescue LoadError => ex # Not in load path require File.join(File.dirname(__FILE__), '..', 'lib', 'pipette') end Pipette.new(opts).send(cmd, cmd_opts) # vim: ft=ruby