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.
379 380 381 |
# File 'lib/awscli/ec2.rb', line 379 def initialize(connection) @conn = connection end |
Instance Method Details
#associate(options) ⇒ Object
400 401 402 403 404 405 406 407 408 409 410 411 412 |
# File 'lib/awscli/ec2.rb', line 400 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
387 388 389 390 |
# File 'lib/awscli/ec2.rb', line 387 def create eip = @conn.addresses.create puts "Created EIP: #{eip.public_ip}" end |
#delete(options) ⇒ Object
392 393 394 395 396 397 398 |
# File 'lib/awscli/ec2.rb', line 392 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
414 415 416 417 418 419 |
# File 'lib/awscli/ec2.rb', line 414 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
383 384 385 |
# File 'lib/awscli/ec2.rb', line 383 def list @conn.addresses.table end |