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

Merge pull request #2765 from madAndroid/AWS_network_interfaces_model_set_options

AWS network interfaces model set options
This commit is contained in:
Wesley Beary 2014-03-18 09:34:19 -05:00
commit a7998305e9
3 changed files with 24 additions and 6 deletions

View file

@ -49,7 +49,7 @@ module Fog
# >> g = AWS.network_interfaces.new(:subnet_id => "subnet-someId", options)
# >> g.save
#
# options is an optional hash which may contain 'PrivateIpAddress', 'Description', 'groupSet'
# options is an optional hash which may contain 'PrivateIpAddress', 'Description', 'GroupSet'
#
# == Returns:
#
@ -58,7 +58,13 @@ module Fog
def save
requires :subnet_id
data = service.create_network_interface(subnet_id).body['networkInterface']
options = {
'PrivateIpAddress' => private_ip_address,
'Description' => description,
'GroupSet' => group_set,
}
options.delete_if {|key, value| value.nil?}
data = service.create_network_interface(subnet_id, options).body['networkInterface']
new_attributes = data.reject {|key,value| key == 'requestId'}
merge_attributes(new_attributes)
true

View file

@ -12,7 +12,7 @@ module Fog
# * options<~Hash>:
# * PrivateIpAddress<~String> - The private IP address of the network interface
# * Description<~String> - The description of the network interface
# * groupSet<~Array> - The security group IDs for use by the network interface
# * GroupSet<~Array> - The security group IDs for use by the network interface
#
# === Returns
# * response<~Excon::Response>:
@ -70,7 +70,7 @@ module Fog
groups = {}
if options['GroupSet']
options['GroupSet'].each do |group_id|
name = self.data[:security_groups].select { |k,v| v['groupId'] == group_id } .first.first
name = self.data[:security_groups].select { |k,v| v['groupId'] == group_id }.first
if name.nil?
raise Fog::Compute::AWS::Error.new("Unknown security group '#{group_id}' specified")
end

View file

@ -40,11 +40,23 @@ Shindo.tests('Fog::Compute[:aws] | network interface requests', ['aws']) do
@vpc = Fog::Compute[:aws].vpcs.create('cidr_block' => '10.0.10.0/24')
@subnet = Fog::Compute[:aws].subnets.create('vpc_id' => @vpc.id, 'cidr_block' => '10.0.10.16/28')
@security_group = Fog::Compute[:aws].security_groups.create('name' => 'sg_name', 'description' => 'sg_desc', 'vpc_id' => @vpc.id)
@owner_id = Fog::Compute[:aws].describe_security_groups('group-name' => 'default').body['securityGroupInfo'].first['ownerId']
@subnet_id = @subnet.subnet_id
@security_group_id = @security_group.group_id
@security_groups = [
@security_group.name, {
'groupDescription' => @security_group.description,
'groupName' => @security_group.name,
'groupId' => @security_group_id,
'ipPermissionsEgress' => [],
'ipPermissions' => [],
'ownerId' => @owner_id,
'vpcId' => @vpc.id
}
]
DESCRIPTION = "Small and green"
tests("#create_network_interface(#{@subnet_id})").formats(@network_interface_create_format) do
data = Fog::Compute[:aws].create_network_interface(@subnet_id, {"PrivateIpAddress" => "10.0.10.23"}).body
@ -149,7 +161,7 @@ Shindo.tests('Fog::Compute[:aws] | network interface requests', ['aws']) do
tests("#describe_network_interface_attribute(#{@nic2_id}, 'description')").returns(DESCRIPTION) do
Fog::Compute[:aws].describe_network_interface_attribute(@nic2_id, 'description').body["description"]
end
tests("#describe_network_interface_attribute(#{@nic2_id}, 'groupSet'')").returns({ @security_group_id => "sg_name"}) do
tests("#describe_network_interface_attribute(#{@nic2_id}, 'groupSet')").returns({ @security_group_id => @security_groups }) do
Fog::Compute[:aws].describe_network_interface_attribute(@nic2_id, 'groupSet').body["groupSet"]
end