Permalink
Browse files

#810 - Add ENI support by maf23

  • Loading branch information...
Eric Stonfer
Eric Stonfer committed Apr 2, 2012
1 parent 16dbd66 commit 935c63447be1e5fceefad73b5149ce9fce41bf9e
View
@@ -234,6 +234,10 @@ def self.security_group_id
"sg-#{Fog::Mock.random_hex(8)}"
end
+ def self.network_interface_id
+ "eni-#{Fog::Mock.random_hex(8)}"
+ end
+
def self.key_id(length=21)
#Probably close enough
Fog::Mock.random_selection('ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',length)
View
@@ -17,6 +17,8 @@ class AWS < Fog::Service
collection :images
model :key_pair
collection :key_pairs
+ model :network_interface
+ collection :network_interfaces
model :security_group
collection :security_groups
model :server
@@ -37,11 +39,13 @@ class AWS < Fog::Service
request_path 'fog/aws/requests/compute'
request :allocate_address
request :associate_address
+ request :attach_network_interface
request :attach_volume
request :authorize_security_group_ingress
request :cancel_spot_instance_requests
request :create_image
request :create_key_pair
+ request :create_network_interface
request :create_placement_group
request :create_security_group
request :create_snapshot
@@ -51,6 +55,7 @@ class AWS < Fog::Service
request :create_volume
request :create_vpc
request :delete_key_pair
+ request :delete_network_interface
request :delete_security_group
request :delete_placement_group
request :delete_snapshot
@@ -67,6 +72,8 @@ class AWS < Fog::Service
request :describe_reserved_instances
request :describe_instance_status
request :describe_key_pairs
+ request :describe_network_interface_attribute
+ request :describe_network_interfaces
request :describe_placement_groups
request :describe_regions
request :describe_reserved_instances_offerings
@@ -80,19 +87,22 @@ class AWS < Fog::Service
request :describe_volumes
request :describe_volume_status
request :describe_vpcs
+ request :detach_network_interface
request :detach_volume
request :disassociate_address
request :get_console_output
request :get_password_data
request :import_key_pair
request :modify_image_attribute
request :modify_instance_attribute
+ request :modify_network_interface_attribute
request :modify_snapshot_attribute
request :purchase_reserved_instances_offering
request :reboot_instances
request :release_address
request :register_image
request :request_spot_instances
+ request :reset_network_interface_attribute
request :revoke_security_group_ingress
request :run_instances
request :terminate_instances
@@ -164,6 +174,7 @@ def self.data
'ownerId' => owner_id
}
},
+ :network_interfaces => {},
:snapshots => {},
:volumes => {},
:tags => {},
@@ -0,0 +1,70 @@
+require 'fog/core/model'
+
+module Fog
+ module Compute
+ class AWS
+
+ class NetworkInterface < Fog::Model
+
+ identity :network_interface_id, :aliases => 'networkInterfaceId'
+ attribute :state
+ attribute :request_id, :aliases => 'requestId'
+ attribute :network_interface_id, :aliases => 'networkInterfaceId'
+ attribute :subnet_id, :aliases => 'subnetId'
+ attribute :vpc_id, :aliases => 'vpcId'
+ attribute :availability_zone, :aliases => 'availabilityZone'
+ attribute :description, :aliases => 'description'
+ attribute :owner_id, :aliases => 'ownerId'
+ attribute :requester_id, :aliases => 'requesterId'
+ attribute :requester_managed, :aliases => 'requesterManaged'
+ attribute :status, :aliases => 'status'
+ attribute :mac_address, :aliases => 'macAddress'
+ attribute :private_ip_address, :aliases => 'privateIpAddress'
+ attribute :private_dns_name, :aliases => 'privateDnsName'
+ attribute :source_dest_check, :aliases => 'sourceDestCheck'
+ attribute :group_set, :aliases => 'groupSet'
+ attribute :attachment, :aliases => 'attachment'
+ attribute :association, :aliases => 'association'
+ attribute :tag_set, :aliases => 'tagSet'
+
+
+ # Removes an existing network interface
+ #
+ # network_interface.destroy
+ #
+ # ==== Returns
+ #
+ # True or false depending on the result
+ #
+
+ def destroy
+ requires :network_interface_id
+
+ connection.delete_network_interface(network_interface_id)
+ true
+ end
+
+ # Create a network_interface
+ #
+ # >> g = AWS.network_interfaces.new(:subnet_id => "subnet-someId", options)
+ # >> g.save
+ #
+ # options is an optional hash which may contain 'PrivateIpAddress', 'Description', 'groupSet'
+ #
+ # == Returns:
+ #
+ # requestId and a networkInterface object
+ #
+
+ def save
+ requires :subnet_id
+ data = connection.create_network_interface(subnet_id).body['networkInterface']
+ new_attributes = data.reject {|key,value| key == 'requestId'}
+ merge_attributes(new_attributes)
+ true
+ end
+
+ end
+ end
+ end
+end
@@ -0,0 +1,136 @@
+require 'fog/core/collection'
+require 'fog/aws/models/compute/network_interface'
+
+module Fog
+ module Compute
+ class AWS
+
+ class NetworkInterfaces < Fog::Collection
+
+ attribute :filters
+
+ model Fog::Compute::AWS::NetworkInterface
+
+ # Creates a new network interface
+ #
+ # AWS.network_interfaces.new
+ #
+ # ==== Returns
+ #
+ # Returns the details of the new network interface
+ #
+ #>> AWS.network_interfaces.new
+ # <Fog::AWS::Compute::NetworkInterface
+ # network_interface_id=nil
+ # state=nil
+ # request_id=nil
+ # network_interface_id=nil
+ # subnet_id=nil
+ # vpc_id=nil
+ # availability_zone=nil
+ # description=nil
+ # owner_id=nil
+ # requester_id=nil
+ # requester_managed=nil
+ # status=nil
+ # mac_address=nil
+ # private_ip_address=nil
+ # private_dns_name=nil
+ # source_dest_check=nil
+ # group_set=nil
+ # attachment=nil
+ # association=nil
+ # tag_set=nil
+ # >
+ #
+
+ def initialize(attributes)
+ self.filters ||= {}
+ super
+ end
+
+ # Returns an array of all network interfaces that have been created
+ #
+ # AWS.network_interfaces.all
+ #
+ # ==== Returns
+ #
+ # Returns an array of all network interfaces
+ #
+ #>> AWS.network_interfaves.all
+ # <Fog::AWS::Compute::NetworkInterfaces
+ # filters={}
+ # [
+ # <Fog::Compute::AWS::NetworkInterface
+ # network_interface_id="eni-da5dc7ca",
+ # state=nil,
+ # request_id=nil,
+ # subnet_id="a9db1bcd-d215-a56f-b0ab-2398d7f37217",
+ # vpc_id="mock-vpc-id",
+ # availability_zone="mock-zone",
+ # description=nil,
+ # owner_id="",
+ # requester_id=nil,
+ # requester_managed="false",
+ # status="available",
+ # mac_address="00:11:22:33:44:55",
+ # private_ip_address="10.0.0.2",
+ # private_dns_name=nil,
+ # source_dest_check=true,
+ # group_set={},
+ # attachment={},
+ # association={},
+ # tag_set={}
+ # >
+ # ]
+ # >
+ #
+
+ def all(filters = filters)
+ self.filters = filters
+ data = connection.describe_network_interfaces(filters).body
+ load(data['networkInterfaceSet'])
+ end
+
+ # Used to retrieve a network interface
+ # network interface id is required to get any information
+ #
+ # You can run the following command to get the details:
+ # AWS.network_interfaces.get("eni-11223344")
+ #
+ # ==== Returns
+ #
+ #>> AWS.NetworkInterface.get("eni-11223344")
+ # <Fog::AWS::Compute::NetworkInterface
+ # network_interface_id="eni-da5dc7ca",
+ # state=nil,
+ # request_id=nil,
+ # subnet_id="a9db1bcd-d215-a56f-b0ab-2398d7f37217",
+ # vpc_id="mock-vpc-id",
+ # availability_zone="mock-zone",
+ # description=nil,
+ # owner_id="",
+ # requester_id=nil,
+ # requester_managed="false",
+ # status="available",
+ # mac_address="00:11:22:33:44:55",
+ # private_ip_address="10.0.0.2",
+ # private_dns_name=nil,
+ # source_dest_check=true,
+ # group_set={},
+ # attachment={},
+ # association={},
+ # tag_set={}
+ # >
+ #
+
+ def get(nic_id)
+ if nic_id
+ self.class.new(:connection => connection).all('network-interface-id' => nic_id).first
+ end
+ end
+ end
+
+ end
+ end
+end
@@ -0,0 +1,18 @@
+module Fog
+ module Parsers
+ module Compute
+ module AWS
+
+ class AttachNetworkInterface < Fog::Parsers::Base
+
+ def end_element(name)
+ case name
+ when 'requestId', 'attachmentId'
+ @response[name] = value
+ end
+ end
+ end
+ end
+ end
+ end
+end
@@ -0,0 +1,28 @@
+module Fog
+ module Parsers
+ module Compute
+ module AWS
+ require 'fog/aws/parsers/compute/network_interface_parser'
+
+ class CreateNetworkInterface < NetworkInterfaceParser
+ def reset
+ super
+ @response = { 'networkInterface' => {} }
+ end
+
+ def end_element(name)
+ case name
+ when 'requestId'
+ @response[name] = value
+ when 'networkInterface'
+ @response['networkInterface'] = @nic
+ reset_nic
+ else
+ super
+ end
+ end
+ end
+ end
+ end
+ end
+end
@@ -0,0 +1,24 @@
+module Fog
+ module Parsers
+ module Compute
+ module AWS
+
+ class DeleteNetworkInterface < Fog::Parsers::Base
+
+ def end_element(name)
+ case name
+ when 'requestId'
+ @response[name] = value
+ when 'return'
+ if value == 'true'
+ @response[name] = true
+ else
+ @response[name] = false
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+end
Oops, something went wrong.

0 comments on commit 935c634

Please sign in to comment.