Class: Awscli::EC2::Ebs
- Inherits:
-
Object
- Object
- Awscli::EC2::Ebs
- Defined in:
- lib/awscli/ec2.rb
Overview
> AMI
Instance Method Summary collapse
- #attach_volume(options) ⇒ Object
- #copy_snapshot(options) ⇒ Object
- #create(options) ⇒ Object
- #create_snapshot(options) ⇒ Object
- #delete_detached ⇒ Object
- #delete_snapshot(options) ⇒ Object
- #delete_volume(options) ⇒ Object
- #detach_volume(options) ⇒ Object
-
#initialize(connection) ⇒ Ebs
constructor
A new instance of Ebs.
- #list(options) ⇒ Object
Constructor Details
#initialize(connection) ⇒ Ebs
Returns a new instance of Ebs.
478 479 480 |
# File 'lib/awscli/ec2.rb', line 478 def initialize(connection) @conn = connection end |
Instance Method Details
#attach_volume(options) ⇒ Object
494 495 496 497 498 499 500 501 502 503 |
# File 'lib/awscli/ec2.rb', line 494 def attach_volume() #The volume and instance must be in the same Availability Zone. volume = @conn.volumes.get([:volume_id]) volume.merge_attributes(:device => [:device]) server = @conn.servers.get([:instance_id]) abort "Cannot find volume: #{[:volume_id]}" unless volume abort "Cannot find instance: #{[:instance_id]}" unless server volume.server = server puts "Attached volume: #{[:volume_id]} to instance: #{[:instance_id]}" end |
#copy_snapshot(options) ⇒ Object
544 545 546 547 548 |
# File 'lib/awscli/ec2.rb', line 544 def copy_snapshot() # abort "Cannot find snapshot: #{options[:snapshot_id]}" unless @conn.snapshots.get(options[:snapshot_id]) @conn.copy_snapshot([:snapshot_id], [:source_region]) puts "Copied snapshot" end |
#create(options) ⇒ Object
490 491 492 |
# File 'lib/awscli/ec2.rb', line 490 def create() @conn.volumes.create() end |
#create_snapshot(options) ⇒ Object
538 539 540 541 542 |
# File 'lib/awscli/ec2.rb', line 538 def create_snapshot() abort "Cannot find volume: #{[:volume_id]}" unless @conn.volumes.get([:volume_id]) @conn.snapshots.create() puts "Created snapshot" end |
#delete_detached ⇒ Object
524 525 526 527 528 529 530 531 532 533 534 535 536 |
# File 'lib/awscli/ec2.rb', line 524 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) ⇒ Object
550 551 552 553 554 555 |
# File 'lib/awscli/ec2.rb', line 550 def delete_snapshot() snap = @conn.snapshots.get([:snapshot_id]) abort "Cannot find snapshot: #{[:snapshot_id]}" unless snap snap.destroy puts "Deleted snapshot" end |
#delete_volume(options) ⇒ Object
517 518 519 520 521 522 |
# File 'lib/awscli/ec2.rb', line 517 def delete_volume() vol = @conn.volumes.get([:volume_id]) abort "Cannot find volume #{[:volume_id]}" unless vol vol.destroy puts "Deleted volume: #{[:volume_id]}" end |
#detach_volume(options) ⇒ Object
505 506 507 508 509 510 511 512 513 514 515 |
# File 'lib/awscli/ec2.rb', line 505 def detach_volume() #Check if the volume is mounted and show warning regarding data loss volume = @conn.volumes.get([:volume_id]) abort "Cannot find volume: #{[:volume_id]}" unless volume if [:force] volume.force_detach else @conn.detach_volume([:volume_id]) end puts "Detached volume: #{[:volume_id]}" end |
#list(options) ⇒ Object
482 483 484 485 486 487 488 |
# File 'lib/awscli/ec2.rb', line 482 def list() unless [: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 |