class Awscli::EC2::Ebs
Public Class Methods
new(connection)
click to toggle source
# File lib/awscli/ec2.rb, line 500 def initialize(connection) @conn = connection end
Public Instance Methods
attach_volume(options)
click to toggle source
# File lib/awscli/ec2.rb, line 516 def attach_volume(options) #The volume and instance must be in the same Availability Zone. volume = @conn.volumes.get(options[:volume_id]) volume.merge_attributes(:device => options[:device]) server = @conn.servers.get(options[:instance_id]) abort "Cannot find volume: #{options[:volume_id]}" unless volume abort "Cannot find instance: #{options[:instance_id]}" unless server volume.server = server puts "Attached volume: #{options[:volume_id]} to instance: #{options[:instance_id]}" end
copy_snapshot(options)
click to toggle source
# File lib/awscli/ec2.rb, line 566 def copy_snapshot(options) # abort "Cannot find snapshot: #{options[:snapshot_id]}" unless @conn.snapshots.get(options[:snapshot_id]) @conn.copy_snapshot(options[:snapshot_id], options[:source_region]) puts "Copied snapshot" end
create(options)
click to toggle source
# File lib/awscli/ec2.rb, line 512 def create(options) @conn.volumes.create(options) end
create_snapshot(options)
click to toggle source
# File lib/awscli/ec2.rb, line 560 def create_snapshot(options) abort "Cannot find volume: #{options[:volume_id]}" unless @conn.volumes.get(options[:volume_id]) @conn.snapshots.create(options) puts "Created snapshot" end
delete_detached()
click to toggle source
# File lib/awscli/ec2.rb, line 546 def delete_detached vols = @conn.volumes.all('status' => 'available') unless vols.empty? if agree('Are you sure want to delete all the all volumes that are not in use ? ') puts 'Deleting all volumes which are not in use ...' vols.each do |vol| vol.destroy end end else puts "No volumes found, that are 'not in use'" end end
delete_snapshot(options)
click to toggle source
# File lib/awscli/ec2.rb, line 572 def delete_snapshot(options) snap = @conn.snapshots.get(options[:snapshot_id]) abort "Cannot find snapshot: #{options[:snapshot_id]}" unless snap snap.destroy puts "Deleted snapshot" end
delete_volume(options)
click to toggle source
# File lib/awscli/ec2.rb, line 539 def delete_volume(options) vol = @conn.volumes.get(options[:volume_id]) abort "Cannot find volume #{options[:volume_id]}" unless vol vol.destroy puts "Deleted volume: #{options[:volume_id]}" end
detach_volume(options)
click to toggle source
# File lib/awscli/ec2.rb, line 527 def detach_volume(options) #Check if the volume is mounted and show warning regarding data loss volume = @conn.volumes.get(options[:volume_id]) abort "Cannot find volume: #{options[:volume_id]}" unless volume if options[:force] volume.force_detach else @conn.detach_volume(options[:volume_id]) end puts "Detached volume: #{options[:volume_id]}" end
list(options)
click to toggle source
# File lib/awscli/ec2.rb, line 504 def list(options) unless options[:snapshots] @conn.volumes.table([:availability_zone, :delete_on_termination, :device, :id, :server_id, :size, :snapshot_id, :state, :tags, :type]) else @conn.snapshots.table([:id, :owner_id, :volume_id, :state, :progress, :tags, :description]) end end