Class: Awscli::EC2::Eip

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

Overview

> SG

Instance Method Summary collapse

Constructor Details

#initialize(connection) ⇒ Eip

Returns a new instance of Eip.



357
358
359
# File 'lib/awscli/ec2.rb', line 357

def initialize(connection)
  @conn = connection
end

Instance Method Details

#associate(options) ⇒ Object



378
379
380
381
382
383
384
385
386
387
388
389
390
# File 'lib/awscli/ec2.rb', line 378

def associate(options)
  abort "Invalid IP Format" unless options[:eip] =~ /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/
  eip = @conn.addresses.get(options[:eip])
  abort "Cannot find eip: #{options[:eip]}" unless eip
  server = @conn.servers.get(options[:instance_id])
  abort "Cannot find server with id: #{options[:instance_id]}" unless server
  begin
    eip.server = server
    puts "Associated EIP: #{options[:eip]} with Instance: #{options[:instance_id]}"
  rescue Fog::Compute::AWS::Error
    abort "Error: #{$!}"
  end
end

#createObject



365
366
367
368
# File 'lib/awscli/ec2.rb', line 365

def create
  eip = @conn.addresses.create
  puts "Created EIP: #{eip.public_ip}"
end

#delete(options) ⇒ Object



370
371
372
373
374
375
376
# File 'lib/awscli/ec2.rb', line 370

def delete(options)
  abort "Invalid IP Format" unless options[:eip] =~ /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/
  eip = @conn.addresses.get(options[:eip])
  abort "Cannot find IP: #{options[:eip]}" unless eip
  eip.destroy
  puts "Deleted EIP: #{eip.public_ip}"
end

#disassociate(options) ⇒ Object



392
393
394
395
396
397
# File 'lib/awscli/ec2.rb', line 392

def disassociate(options)
  abort "Invalid IP Format" unless options[:eip] =~ /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/
  abort "Cannot find EIP: #{options[:eip]}" unless @conn.addresses.get(options[:eip])
  @conn.disassociate_address(options[:eip])
  puts "Disassociated EIP: #{options[:eip]}"
end

#listObject



361
362
363
# File 'lib/awscli/ec2.rb', line 361

def list
  @conn.addresses.table
end