Class: Roark::Ami
- Inherits:
-
Object
- Object
- Roark::Ami
- Defined in:
- lib/roark/ami.rb
Instance Attribute Summary collapse
-
#ami_id ⇒ Object
Returns the value of attribute ami_id.
-
#aws ⇒ Object
Returns the value of attribute aws.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #add_tags(tags) ⇒ Object
- #authorize_account_ids(account_ids) ⇒ Object
- #available? ⇒ Boolean
- #create_ami ⇒ Object
- #create_instance(args) ⇒ Object
- #destroy ⇒ Object
- #destroy_instance ⇒ Object
- #exists? ⇒ Boolean
-
#initialize(args) ⇒ Ami
constructor
A new instance of Ami.
- #instance_id ⇒ Object
- #pending? ⇒ Boolean
- #state ⇒ Object
- #stop_instance ⇒ Object
- #wait_for_ami ⇒ Object
- #wait_for_instance ⇒ Object
- #wait_for_instance_to_stop ⇒ Object
Constructor Details
Instance Attribute Details
#ami_id ⇒ Object
Returns the value of attribute ami_id.
4 5 6 |
# File 'lib/roark/ami.rb', line 4 def ami_id @ami_id end |
#aws ⇒ Object
Returns the value of attribute aws.
4 5 6 |
# File 'lib/roark/ami.rb', line 4 def aws @aws end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/roark/ami.rb', line 4 def name @name end |
Instance Method Details
#add_tags(tags) ⇒ Object
113 114 115 116 117 118 119 120 |
# File 'lib/roark/ami.rb', line 113 def () begin tag rescue AWS::Errors::Base => e return Response.new :code => 1, :message => e. end Response.new :code => 0, :message => 'Tagging completed successfully.' end |
#authorize_account_ids(account_ids) ⇒ Object
122 123 124 125 126 127 128 129 |
# File 'lib/roark/ami.rb', line 122 def (account_ids) begin account_ids rescue AWS::Errors::Base => e return Response.new :code => 1, :message => e. end Response.new :code => 0, :message => 'Authorizations completed successfully.' end |
#available? ⇒ Boolean
131 132 133 |
# File 'lib/roark/ami.rb', line 131 def available? state == :available end |
#create_ami ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/roark/ami.rb', line 28 def create_ami @logger.info "Creating AMI '#{@name}' from Instance '#{instance_id}'." begin ami = instance.create_ami_from_instance @ami_id = ami.id rescue AWS::Errors::Base => e return Response.new :code => 1, :message => e. end @logger.info "AMI '#{@ami_id}' created." Response.new :code => 0, :message => "AMI '#{@ami_id}' created." end |
#create_instance(args) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/roark/ami.rb', line 15 def create_instance(args) @logger.info "Creating instance in '#{@region}'." begin instance.create :parameters => args[:parameters], :template => args[:template] rescue AWS::Errors::Base => e return Response.new :code => 1, :message => e. end @logger.info "Instance created." Response.new :code => 0, :message => 'Instance created.' end |
#destroy ⇒ Object
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/roark/ami.rb', line 60 def destroy @logger.info "Destroying AMI '#{@ami_id}'." begin ec2_destroy_ami.destroy @ami_id rescue AWS::Errors::Base, AWS::Core::Resource::NotFound => e return Response.new :code => 1, :message => e. end @logger.info "Destroy completed succesfully." Response.new :code => 0, :message => "Destroy completed succesfully." end |
#destroy_instance ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/roark/ami.rb', line 50 def destroy_instance begin instance.destroy rescue AWS::Errors::Base => e return Response.new :code => 1, :message => e. end @logger.info "Instance destroyed." Response.new :code => 0, :message => "Instance destroyed." end |
#exists? ⇒ Boolean
139 140 141 |
# File 'lib/roark/ami.rb', line 139 def exists? ec2_ami_state.exists? @ami_id end |
#instance_id ⇒ Object
147 148 149 |
# File 'lib/roark/ami.rb', line 147 def instance_id instance.instance_id end |
#pending? ⇒ Boolean
135 136 137 |
# File 'lib/roark/ami.rb', line 135 def pending? state == :pending end |
#state ⇒ Object
143 144 145 |
# File 'lib/roark/ami.rb', line 143 def state ec2_ami_state.state @ami_id end |
#stop_instance ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/roark/ami.rb', line 40 def stop_instance @logger.info "Stopping instance." begin instance.stop rescue AWS::Errors::Base => e return Response.new :code => 1, :message => e. end Response.new :code => 0, :message => "Instance stopped." end |
#wait_for_ami ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/roark/ami.rb', line 96 def wait_for_ami while !exists? || pending? @logger.info "Waiting for AMI creation to complete. Current state: '#{state}'." sleep 15 end if available? msg = "AMI completed succesfully." @logger.info msg Response.new :code => 0, :message => msg else msg = "AMI did not complete succesfully." @logger.info msg Response.new :code => 1, :message => msg end end |
#wait_for_instance ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/roark/ami.rb', line 71 def wait_for_instance while instance.in_progress? || !instance.exists? @logger.info "Waiting for instance to come online." sleep 60 end if instance.success? msg = "Instance '#{instance_id}' completed succesfully." @logger.info msg Response.new :code => 0, :message => msg else msg = "Instance did not complete succesfully." @logger.info msg Response.new :code => 1, :message => msg end end |
#wait_for_instance_to_stop ⇒ Object
88 89 90 91 92 93 94 |
# File 'lib/roark/ami.rb', line 88 def wait_for_instance_to_stop while instance.status != :stopped @logger.info "Waiting for instance '#{instance_id}' to stop. Current state: '#{instance.status}'." sleep 15 end Response.new :code => 0, :message => "Instance stopped." end |