class Snapscatter::CLI

Public Instance Methods

create() click to toggle source
# File lib/snapscatter/cli.rb, line 55
def create
  source_ec2 = create_ec2
  targets = Snapscatter.targets source_ec2
  targets.each do |volume|
    snapshot = nil
    description = nil

    Snapscatter.in_lock volume.tags['Consistent'] do
      volume_name = volume.tags['Name']
      date_as_string = Date.today.strftime("%Y-%m-%d")
      description = "#{volume_name} #{date_as_string}"

      snapshot = volume.create_snapshot description
      snapshot.add_tag 'VolumeName', value: volume_name
      snapshot.add_tag 'PurgeAllow', value: "true"

      sleep 1 until [:completed, :error].include?(snapshot.status)
    end

    if snapshot.status == :completed
      output = ["created", snapshot.id, description]
      if options.has_key? 'alternate'
        alternate_ec2 = create_ec2(region: options[:alternate])
        Snapscatter.copy alternate_ec2, source_ec2.client.config.region, snapshot, description
        output << "#{options[:alternate]}"
      end
      say output.join(" ")
    else
      say "#{volume.id} (#{volume_name}): snapshot failed"
    end
  end
end
list() click to toggle source
# File lib/snapscatter/cli.rb, line 25
def list
  snapshots = Snapscatter.list create_ec2(region: options[:region])
  snapshots.each do |snapshot|
    output = [ snapshot.id ]
    if options[:full]
      output << snapshot.volume_id
      output << snapshot.start_time.strftime("%Y-%m-%d")
    end
    say output.join(" ")
  end
end
purge() click to toggle source
# File lib/snapscatter/cli.rb, line 42
def purge
  purged = Snapscatter.purge create_ec2, options[:days], options[:noaction]
  purged.each { |snapshot| say "#{snapshot.id}" }

  if options.has_key? 'alternate'
    purged = Snapscatter.purge create_ec2(region: options[:alternate]), options[:days], options[:noaction]
    purged.each { |snapshot| say "#{snapshot.id}" }
  end
end
targets() click to toggle source
# File lib/snapscatter/cli.rb, line 16
def targets
  targets = Snapscatter.targets create_ec2
  targets.each { |target| say target.id }
end
version() click to toggle source
# File lib/snapscatter/cli.rb, line 10
def version
  say "Snapscatter #{Snapscatter::VERSION}"
end

Private Instance Methods

create_ec2(ec2_options={}) click to toggle source
# File lib/snapscatter/cli.rb, line 89
def create_ec2 ec2_options={}
  ec2_options.merge! options[:keys] if options.has_key? :keys
  ec2 = AWS::EC2.new(ec2_options)
end