1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

add (dis)associate address

This commit is contained in:
Wesley Beary 2009-07-22 22:25:24 -07:00
parent e31174d189
commit b7d6f3ec65
5 changed files with 95 additions and 0 deletions

View file

@ -27,6 +27,7 @@ require "#{parsers_directory}/terminate_instances"
requests_directory = "#{current_directory}/requests/ec2"
require "#{requests_directory}/allocate_address"
require "#{requests_directory}/associate_address"
require "#{requests_directory}/authorize_security_group_ingress"
require "#{requests_directory}/create_key_pair"
require "#{requests_directory}/create_security_group"
@ -44,6 +45,7 @@ require "#{requests_directory}/describe_key_pairs"
require "#{requests_directory}/describe_security_groups"
require "#{requests_directory}/describe_snapshots"
require "#{requests_directory}/describe_volumes"
require "#{requests_directory}/disassociate_address"
require "#{requests_directory}/release_address"
require "#{requests_directory}/revoke_security_group_ingress"
require "#{requests_directory}/run_instances"

View file

@ -0,0 +1,26 @@
module Fog
module AWS
class EC2
# Associate an elastic IP address with an instance
#
# ==== Parameters
# * instance_id<~String> - Id of instance to associate address with
# * public_ip<~String> - Public ip to assign to instance
#
# ==== Returns
# * response<~Fog::AWS::Response>:
# * body<~Hash>:
# * :request_id<~String> - Id of request
# * :return<~Boolean> - success?
def associate_address(instance_id, public_ip)
request({
'Action' => 'AssociateAddress',
'InstanceId' => instance_id,
'PublicIp' => public_ip
}, Fog::Parsers::AWS::EC2::Basic.new)
end
end
end
end

View file

@ -0,0 +1,24 @@
module Fog
module AWS
class EC2
# Disassociate an elastic IP address from its instance (if any)
#
# ==== Parameters
# * public_ip<~String> - Public ip to assign to instance
#
# ==== Returns
# * response<~Fog::AWS::Response>:
# * body<~Hash>:
# * :request_id<~String> - Id of request
# * :return<~Boolean> - success?
def disassociate_address(public_ip)
request({
'Action' => 'DisassociateAddress',
'PublicIp' => public_ip
}, Fog::Parsers::AWS::EC2::Basic.new)
end
end
end
end

View file

@ -0,0 +1,21 @@
require File.dirname(__FILE__) + '/../../spec_helper'
describe 'EC2.associate_address' do
before(:all) do
@instance_id = ec2.run_instances('ami-5ee70037', 1, 1).body[:instances_set].first[:instance_id]
@public_ip = ec2.allocate_address.body[:public_ip]
end
after(:all) do
ec2.release_address(@public_ip)
ec2.terminate_instances([@instance_id])
end
it "should return proper attributes" do
actual = ec2.associate_address(@instance_id, @public_ip)
actual.body[:request_id].should be_a(String)
[false, true].should include(actual.body[:return])
end
end

View file

@ -0,0 +1,22 @@
require File.dirname(__FILE__) + '/../../spec_helper'
describe 'EC2.disassociate_address' do
before(:all) do
@instance_id = ec2.run_instances('ami-5ee70037', 1, 1).body[:instances_set].first[:instance_id]
@public_ip = ec2.allocate_address.body[:public_ip]
ec2.associate_address(@instance_id, @public_ip)
end
after(:all) do
ec2.release_address(@public_ip)
ec2.terminate_instances([@instance_id])
end
it "should return proper attributes" do
actual = ec2.disassociate_address(@public_ip)
actual.body[:request_id].should be_a(String)
[false, true].should include(actual.body[:return])
end
end