class Awscli::EC2::Eip

Public Class Methods

new(connection) click to toggle source
# File lib/awscli/ec2.rb, line 379
def initialize(connection)
  @conn = connection
end

Public Instance Methods

associate(options) click to toggle source
# File lib/awscli/ec2.rb, line 400
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
create() click to toggle source
# File lib/awscli/ec2.rb, line 387
def create
  eip = @conn.addresses.create
  puts "Created EIP: #{eip.public_ip}"
end
delete(options) click to toggle source
# File lib/awscli/ec2.rb, line 392
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) click to toggle source
# File lib/awscli/ec2.rb, line 414
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
list() click to toggle source
# File lib/awscli/ec2.rb, line 383
def list
  @conn.addresses.table
end