Class: Awscli::EC2::Eip
- Inherits:
-
Object
- Object
- Awscli::EC2::Eip
- Defined in:
- lib/awscli/ec2.rb
Overview
> SG
Instance Method Summary collapse
- #associate(options) ⇒ Object
- #create ⇒ Object
- #delete(options) ⇒ Object
- #disassociate(options) ⇒ Object
-
#initialize(connection) ⇒ Eip
constructor
A new instance of Eip.
- #list ⇒ Object
Constructor Details
#initialize(connection) ⇒ Eip
Returns a new instance of Eip.
369 370 371 |
# File 'lib/awscli/ec2.rb', line 369 def initialize(connection) @conn = connection end |
Instance Method Details
#associate(options) ⇒ Object
390 391 392 393 394 395 396 397 398 399 400 401 402 |
# File 'lib/awscli/ec2.rb', line 390 def associate() abort "Invalid IP Format" unless [: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([:eip]) abort "Cannot find eip: #{[:eip]}" unless eip server = @conn.servers.get([:instance_id]) abort "Cannot find server with id: #{[:instance_id]}" unless server begin eip.server = server puts "Associated EIP: #{[:eip]} with Instance: #{[:instance_id]}" rescue Fog::Compute::AWS::Error abort "Error: #{$!}" end end |
#create ⇒ Object
377 378 379 380 |
# File 'lib/awscli/ec2.rb', line 377 def create eip = @conn.addresses.create puts "Created EIP: #{eip.public_ip}" end |
#delete(options) ⇒ Object
382 383 384 385 386 387 388 |
# File 'lib/awscli/ec2.rb', line 382 def delete() abort "Invalid IP Format" unless [: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([:eip]) abort "Cannot find IP: #{[:eip]}" unless eip eip.destroy puts "Deleted EIP: #{eip.public_ip}" end |
#disassociate(options) ⇒ Object
404 405 406 407 408 409 |
# File 'lib/awscli/ec2.rb', line 404 def disassociate() abort "Invalid IP Format" unless [: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: #{[:eip]}" unless @conn.addresses.get([:eip]) @conn.disassociate_address([:eip]) puts "Disassociated EIP: #{[:eip]}" end |
#list ⇒ Object
373 374 375 |
# File 'lib/awscli/ec2.rb', line 373 def list @conn.addresses.table end |