Class: AwsCli::CLI::EC2::Instances

Inherits:
Thor
  • Object
show all
Defined in:
lib/awscli/cli/ec2/instances.rb

Instance Method Summary collapse

Instance Method Details

#console_outputObject



260
261
262
263
# File 'lib/awscli/cli/ec2/instances.rb', line 260

def console_output
  create_ec2_object
  @ec2.get_console_output options[:instance_id]
end

#createObject



160
161
162
163
# File 'lib/awscli/cli/ec2/instances.rb', line 160

def create
  create_ec2_object
  @ec2.create_instance options
end

#create_centosObject



171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/awscli/cli/ec2/instances.rb', line 171

def create_centos
  create_ec2_object
  centos_amis    = {
      'us-east-1'       => 'ami-a96b01c0',  #Virginia
      'us-west-1'       => 'ami-51351b14',  #Northern California
      'us-west-2'       => 'ami-bd58c98d',  #Oregon
      'eu-west-1'       => 'ami-050b1b71',  #Ireland
      'ap-southeast-1'  => 'ami-23682671',  #Singapore
      'ap-southeast-2'  => 'ami-ffcd5ec5',  #Sydney
      'ap-northeast-1'  => 'ami-3fe8603e',  #Tokyo
      'sa-east-1'       => 'ami-e2cd68ff',  #Sao Paulo
  }
  options[:count].times do
    @ec2.create_instance  :image_id             => centos_amis[parent_options[:region]],
                          :block_device_mapping => %w(/dev/sda=:100:true::),
                          :groups               => options[:groups],
                          :flavor_id            => options[:flavor_id],
                          :key_name             => options[:key_name],
                          :tags                 => options[:tags]
  end
end

#create_ubuntuObject



199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/awscli/cli/ec2/instances.rb', line 199

def create_ubuntu
  create_ec2_object
  ubuntu_amis    = {
      'us-east-1'       => 'ami-9b85eef2',  #Virginia
      'us-west-1'       => 'ami-9b2d03de',  #Northern California
      'us-west-2'       => 'ami-77be2f47',  #Oregon
      'eu-west-1'       => 'ami-f5736381',  #Ireland
      'ap-southeast-1'  => 'ami-085b155a',  #Singapore
      'ap-southeast-2'  => 'ami-37c0530d',  #Sydney
      'ap-northeast-1'  => 'ami-57109956',  #Tokyo
      'sa-east-1'       => 'ami-a4fb5eb9',  #Sao Paulo
  }
  options[:count].times do
    @ec2.create_instance  :image_id             => ubuntu_amis[parent_options[:region]],
                          :block_device_mapping => %w(/dev/sda1=:100:true::),
                          :groups               => options[:groups],
                          :flavor_id            => options[:flavor_id],
                          :key_name             => options[:key_name],
                          :tags                 => options[:tags]
  end
end

#diattObject



35
36
37
38
# File 'lib/awscli/cli/ec2/instances.rb', line 35

def diatt
  create_ec2_object
  @ec2.describe_instance_attribute(options[:id], options[:attr])
end

#dinsObject



88
89
90
91
# File 'lib/awscli/cli/ec2/instances.rb', line 88

def dins
  create_ec2_object
  @ec2.describe_instance_status options[:instance_id]
end

#listObject



15
16
17
18
19
20
# File 'lib/awscli/cli/ec2/instances.rb', line 15

def list
  puts "Listing Instances"
  create_ec2_object
  # puts parent_options #access awscli/cli/ec2.rb class options
  @ec2.list_instances
end

#miattObject



54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/awscli/cli/ec2/instances.rb', line 54

def miatt
  create_ec2_object
  opts = Marshal.load(Marshal.dump(options))  #create a copy of options, as original options hash cannot be modified
  opts.reject!{ |k| k == 'id' } #remove id from opts
  abort "Please pass an attribute by setting respective option" unless opts
  abort "You can only pass one attribute at a time" if opts.size != 1
  opts.each do |k,v|
    puts "calling modify_instance_attribute with: #{options[:id]}, #{k}, #{opts[k]}"
    @ec2.modify_instance_attribute(options[:id], k, opts[k])
  end

end

#rebootObject



109
110
111
112
# File 'lib/awscli/cli/ec2/instances.rb', line 109

def reboot
  create_ec2_object
  @ec2.reboot_instance options[:instance_id]
end

#riattObject



71
72
73
# File 'lib/awscli/cli/ec2/instances.rb', line 71

def riatt
  puts "Not yet Implemented"
end

#startObject



226
227
228
229
# File 'lib/awscli/cli/ec2/instances.rb', line 226

def start
  create_ec2_object
  @ec2.start_instance options[:instance_id]
end

#stopObject



236
237
238
239
# File 'lib/awscli/cli/ec2/instances.rb', line 236

def stop
  create_ec2_object
  @ec2.stop_instance options[:instance_id]
end

#terminateObject



246
247
248
249
# File 'lib/awscli/cli/ec2/instances.rb', line 246

def terminate
  create_ec2_object
  @ec2.terminate_instance options[:instance_id]
end

#terminate_allObject



253
254
255
256
# File 'lib/awscli/cli/ec2/instances.rb', line 253

def terminate_all
  create_ec2_object
  @ec2.terminate_instances options[:delete_volumes]
end