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.
500 501 502 |
# File 'lib/awscli/ec2.rb', line 500 def initialize(connection) @conn = connection end |
Instance Method Details
#attach_volume(options) ⇒ Object
516 517 518 519 520 521 522 523 524 525 |
# File 'lib/awscli/ec2.rb', line 516 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
566 567 568 569 570 |
# File 'lib/awscli/ec2.rb', line 566 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
512 513 514 |
# File 'lib/awscli/ec2.rb', line 512 def create() @conn.volumes.create() end |
#create_snapshot(options) ⇒ Object
560 561 562 563 564 |
# File 'lib/awscli/ec2.rb', line 560 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
546 547 548 549 550 551 552 553 554 555 556 557 558 |
# 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) ⇒ Object
572 573 574 575 576 577 |
# File 'lib/awscli/ec2.rb', line 572 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
539 540 541 542 543 544 |
# File 'lib/awscli/ec2.rb', line 539 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
527 528 529 530 531 532 533 534 535 536 537 |
# File 'lib/awscli/ec2.rb', line 527 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
504 505 506 507 508 509 510 |
# File 'lib/awscli/ec2.rb', line 504 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 |