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

Merge pull request from madAndroid/AWS-run_instance-attach-network-interfaces

Aws run instance attach network interfaces
This commit is contained in:
Wesley Beary 2014-03-03 09:36:50 -06:00
commit 5638e65e4c
5 changed files with 58 additions and 4 deletions
lib/fog/aws
models/compute
parsers/compute
requests/compute
tests/aws/requests/compute

View file

@ -58,7 +58,7 @@ module Fog
def initialize(attributes={})
self.groups ||= ["default"] unless (attributes[:subnet_id] || attributes[:security_group_ids])
self.groups ||= ["default"] unless (attributes[:subnet_id] || attributes[:security_group_ids] || attributes[:network_interfaces])
self.flavor_id ||= 't1.micro'
# Old 'connection' is renamed as service and should be used instead
@ -146,6 +146,7 @@ module Fog
options = {
'BlockDeviceMapping' => block_device_mapping,
'NetworkInterfaces' => network_interfaces,
'ClientToken' => client_token,
'EbsOptimized' => ebs_optimized,
'IamInstanceProfile.Arn' => @iam_instance_profile_arn,

View file

@ -25,6 +25,7 @@ module Fog
# ami_launch_index=nil,
# availability_zone=nil,
# block_device_mapping=nil,
# network_interfaces=nil,
# client_token=nil,
# dns_name=nil,
# groups=["default"],

View file

@ -7,9 +7,10 @@ module Fog
def reset
@block_device_mapping = {}
@network_interfaces = {}
@context = []
@contexts = ['blockDeviceMapping', 'groupSet', 'placement', 'productCodes']
@instance = { 'blockDeviceMapping' => [], 'instanceState' => {}, 'monitoring' => {}, 'placement' => {}, 'productCodes' => [] }
@contexts = ['networkInterfaces', 'blockDeviceMapping', 'groupSet', 'placement', 'productCodes']
@instance = { 'networkInterfaces' => [], 'blockDeviceMapping' => [], 'instanceState' => {}, 'monitoring' => {}, 'placement' => {}, 'productCodes' => [] }
@response = { 'groupSet' => [], 'instancesSet' => [] }
end
@ -40,8 +41,11 @@ module Fog
@instance['instanceState'][name] = value.to_i
when 'deleteOnTermination'
@block_device_mapping[name] = (value == 'true')
@network_interfaces[name] = (value == 'true')
when 'deviceName', 'status', 'volumeId'
@block_device_mapping[name] = value
when 'networkInterfaceId'
@network_interfaces[name] = value
when 'groupId'
@response['groupSet'] << value
when 'groupName'
@ -56,9 +60,12 @@ module Fog
when 'blockDeviceMapping'
@instance['blockDeviceMapping'] << @block_device_mapping
@block_device_mapping = {}
when 'networkInterfaces'
@instance['networkInterfaces'] << @network_interfaces
@network_interfaces = {}
when nil
@response['instancesSet'] << @instance
@instance = { 'blockDeviceMapping' => [], 'instanceState' => {}, 'monitoring' => {}, 'placement' => {}, 'productCodes' => [] }
@instance = { 'networkInterfaces' => [], 'blockDeviceMapping' => [], 'instanceState' => {}, 'monitoring' => {}, 'placement' => {}, 'productCodes' => [] }
end
when 'launchTime'
@instance[name] = Time.parse(value)

View file

@ -30,6 +30,18 @@ module Fog
# * 'Ebs.DeleteOnTermination'<~String> - specifies whether or not to delete the volume on instance termination
# * 'Ebs.VolumeType'<~String> - Type of EBS volue. Valid options in ['standard', 'io1'] default is 'standard'.
# * 'Ebs.Iops'<~String> - The number of I/O operations per second (IOPS) that the volume supports. Required when VolumeType is 'io1'
# * 'NetworkInterfaces'<~Array>: array of hashes
# * 'NetworkInterfaceId'<~String> - An existing interface to attach to a single instance
# * 'DeviceIndex'<~String> - The device index. Applies both to attaching an existing network interface and creating a network interface
# * 'SubnetId'<~String> - The subnet ID. Applies only when creating a network interface
# * 'Description'<~String> - A description. Applies only when creating a network interface
# * 'PrivateIpAddress'<~String> - The primary private IP address. Applies only when creating a network interface
# * 'SecurityGroupId'<~String> - The ID of the security group. Applies only when creating a network interface.
# * 'DeleteOnTermination'<~String> - Indicates whether to delete the network interface on instance termination.
# * 'PrivateIpAddresses.PrivateIpAddress'<~String> - The private IP address. This parameter can be used multiple times to specify explicit private IP addresses for a network interface, but only one private IP address can be designated as primary.
# * 'PrivateIpAddresses.Primary'<~Bool> - Indicates whether the private IP address is the primary private IP address.
# * 'SecondaryPrivateIpAddressCount'<~Bool> - The number of private IP addresses to assign to the network interface.
# * 'AssociatePublicIpAddress'<~String> - Indicates whether to assign a public IP address to an instance in a VPC. The public IP address is assigned to a specific network interface
# * 'ClientToken'<~String> - unique case-sensitive token for ensuring idempotency
# * 'DisableApiTermination'<~Boolean> - specifies whether or not to allow termination of the instance from the api
# * 'SecurityGroup'<~Array> or <~String> - Name of security group(s) for instances (not supported for VPC)
@ -108,6 +120,13 @@ module Fog
if options['UserData']
options['UserData'] = Base64.encode64(options['UserData'])
end
if network_interfaces = options.delete('NetworkInterfaces')
network_interfaces.each_with_index do |mapping, index|
for key, value in mapping
options.merge!({ format("NetworkInterface.%d.#{key}", index) => value })
end
end
end
idempotent = !(options['ClientToken'].nil? || options['ClientToken'].empty?)
@ -159,11 +178,36 @@ module Fog
}
end
network_interfaces = (options['NetworkInterfaces'] || []).inject([]) do |mapping, device|
device_index = device.fetch("DeviceIndex", 0)
subnet_id = device.fetch("SubnetId", options[:subnet_id] || Fog::AWS::Mock.subnet_id)
private_ip_address = device.fetch("PrivateIpAddress", options[:private_ip_address] || Fog::AWS::Mock.private_ip_address)
delete_on_termination = device.fetch("DeleteOnTermination", true)
description = device.fetch("Description", "mock_network_interface")
security_group_id = device.fetch("SecurityGroupId", self.data[:security_groups]['default']['groupId'])
interface_options = {
"PrivateIpAddress" => private_ip_address,
"GroupSet" => device.fetch("GroupSet", [security_group_id]),
"Description" => description
}
interface_id = device.fetch("NetworkInterfaceId", create_network_interface(subnet_id, interface_options))
mapping << {
"networkInterfaceId" => interface_id,
"subnetId" => subnet_id,
"status" => "attached",
"attachTime" => Time.now,
"deleteOnTermination" => delete_on_termination,
}
end
instance = {
'amiLaunchIndex' => i,
'associatePublicIP' => options['associatePublicIP'] || false,
'architecture' => 'i386',
'blockDeviceMapping' => block_device_mapping,
'networkInterfaces' => network_interfaces,
'clientToken' => options['clientToken'],
'dnsName' => nil,
'ebsOptimized' => options['EbsOptimized'] || false,

View file

@ -6,6 +6,7 @@ Shindo.tests('Fog::Compute[:aws] | instance requests', ['aws']) do
'associatePublicIP' => Fog::Nullable::Boolean,
'attachmentId' => Fog::Nullable::String,
'blockDeviceMapping' => [Fog::Nullable::Hash],
'networkInterfaces' => [Fog::Nullable::Hash],
'clientToken' => Fog::Nullable::String,
'dnsName' => NilClass,
'ebsOptimized' => Fog::Boolean,