Class: Rudy::CLI::AWS::EC2::Addresses

Inherits:
CommandBase
  • Object
show all
Defined in:
lib/rudy/cli/aws/ec2/addresses.rb

Instance Attribute Summary

Attributes inherited from CommandBase

#config

Instance Method Summary collapse

Methods included from Huxtable

config, #config_dirname, create_domain, #current_group_name, #current_machine_address, #current_machine_bucket, #current_machine_count, #current_machine_group, #current_machine_hostname, #current_machine_image, #current_machine_name, #current_machine_os, #current_machine_size, #current_machine_user, #current_user_keypairname, #current_user_keypairpath, #defined_keypairpath, domain, domain_exists?, global, keypair_path_to_name, #known_machine_group?, ld, #ld, #le, le, li, #li, logger, reset_config, reset_global, #root_keypairname, #root_keypairpath, update_config, update_global, update_logger, #user_keypairname, #user_keypairpath

Instance Method Details

#addressesObject



81
82
83
84
# File 'lib/rudy/cli/aws/ec2/addresses.rb', line 81

def addresses
  addresses = Rudy::AWS::EC2::Addresses.list || []
  print_stobjects addresses
end

#addresses_createObject



8
9
10
11
# File 'lib/rudy/cli/aws/ec2/addresses.rb', line 8

def addresses_create
  address = Rudy::AWS::EC2::Addresses.create
  print_stobject address
end

#addresses_destroyObject



19
20
21
22
23
24
25
26
27
# File 'lib/rudy/cli/aws/ec2/addresses.rb', line 19

def addresses_destroy
  address = Rudy::AWS::EC2::Addresses.get(@argv.ipaddress)
  raise "Could not fetch #{address.ipaddress}" unless address
  
  li "Destroying address: #{@argv.ipaddress}"
  li "NOTE: this IP address will become available to other EC2 customers.".bright
  execute_check(:medium)
  execute_action { Rudy::AWS::EC2::Addresses.destroy(@argv.ipaddress) }
end

#addresses_destroy_valid?Boolean

Returns:

  • (Boolean)

Raises:

  • (Drydock::ArgError)


13
14
15
16
17
18
# File 'lib/rudy/cli/aws/ec2/addresses.rb', line 13

def addresses_destroy_valid?
  raise Drydock::ArgError.new("IP address", @alias) unless @argv.ipaddress
  raise "#{@argv.ipaddress} is not allocated to you" unless Rudy::AWS::EC2::Addresses.exists?(@argv.ipaddress)
  raise "#{@argv.ipaddress} is associated!" if Rudy::AWS::EC2::Addresses.associated?(@argv.ipaddress)
  true
end

#associate_addressesObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/rudy/cli/aws/ec2/addresses.rb', line 34

def associate_addresses
  raise "Instance #{@argv.instid} does not exist!" unless Rudy::AWS::EC2::Instances.exists?(@option.instance)
  
  if @option.newaddress
    print "Creating address... "
    tmp = Rudy::AWS::EC2::Addresses.create
    li "#{tmp.ipaddress}"
    address = tmp.ipaddress
  else
    address = @argv.ipaddress
  end
  
  raise "#{address} is not allocated to you" unless Rudy::AWS::EC2::Addresses.exists?(address)
  raise "#{address} is already associated!" if Rudy::AWS::EC2::Addresses.associated?(address)
      
  instance = Rudy::AWS::EC2::Instances.get(@option.instance)
  
  # If an instance was recently disassoiciated, the dns_public may
  # not be updated yet
  instance_name = instance.dns_public
  instance_name = instance.awsid if !instance_name || instance_name.empty?
  
  li "Associating #{address} to #{instance_name} (#{instance.groups.join(', ')})"
  execute_check(:low)
  execute_action { Rudy::AWS::EC2::Addresses.associate(address, instance.awsid) }
  address = Rudy::AWS::EC2::Addresses.get(address)
  print_stobject address
end

#associate_addresses_valid?Boolean

Returns:

  • (Boolean)

Raises:

  • (Drydock::ArgError)


29
30
31
32
33
# File 'lib/rudy/cli/aws/ec2/addresses.rb', line 29

def associate_addresses_valid?
  raise Drydock::ArgError.new('IP address', @alias) if !@argv.ipaddress && !@option.newaddress
  raise Drydock::OptError.new('instance ID', @alias) if !@option.instance
  true
end

#disassociate_addressesObject



67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/rudy/cli/aws/ec2/addresses.rb', line 67

def disassociate_addresses
  raise "#{@argv.ipaddress} is not allocated to you" unless Rudy::AWS::EC2::Addresses.exists?(@argv.ipaddress)
  raise "#{@argv.ipaddress} is not associated!" unless Rudy::AWS::EC2::Addresses.associated?(@argv.ipaddress)
  
  address = Rudy::AWS::EC2::Addresses.get(@argv.ipaddress)
  instance = Rudy::AWS::EC2::Instances.get(address.instid)
  
  li "Disassociating #{address.ipaddress} from #{instance.awsid} (#{instance.groups.join(', ')})"
  execute_check(:medium)
  execute_action { Rudy::AWS::EC2::Addresses.disassociate(@argv.ipaddress) }
  address = Rudy::AWS::EC2::Addresses.get(@argv.ipaddress)
  print_stobject address
end

#disassociate_addresses_valid?Boolean

Returns:

  • (Boolean)


63
64
65
66
# File 'lib/rudy/cli/aws/ec2/addresses.rb', line 63

def disassociate_addresses_valid?
  raise "You have not supplied an IP addresses" unless @argv.ipaddress
  true
end