File: describe_network_interface_attribute.rb

package info (click to toggle)
ruby-fog-aws 3.3.0-5
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 7,816 kB
  • sloc: ruby: 68,587; makefile: 6
file content (68 lines) | stat: -rw-r--r-- 3,016 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
module Fog
  module AWS
    class Compute
      class Real
        require 'fog/aws/parsers/compute/describe_network_interface_attribute'
        # Describes a network interface attribute value
        #
        # ==== Parameters
        # * network_interface_id<~String> - The ID of the network interface you want to describe an attribute of
        # * attribute<~String>            - The attribute to describe, must be one of 'description', 'groupSet', 'sourceDestCheck' or 'attachment'
        #
        # === Returns
        # * response<~Excon::Response>:
        # * body<~Hash>:
        # * 'requestId'<~String> - Id of request
        # * 'networkInterfaceId'<~String> - The ID of the network interface
        # * 'description'<~String>        - The description (if requested)
        # * 'groupSet'<~Hash>             - Associated security groups (if requested)
        # *   'key'<~String>              - ID of associated group
        # *   'value'<~String>            - Name of associated group
        # * 'sourceDestCheck'<~Boolean>   - Flag indicating whether traffic to or from the instance is validated (if requested)
        # * 'attachment'<~Hash>:          - Describes the way this nic is attached  (if requested)
        # *   'attachmentID'<~String>
        # *   'instanceID'<~String>
        # *   'instanceOwnerId'<~String>
        # *   'deviceIndex'<~Integer>
        # *   'status'<~String>
        # *   'attachTime'<~String>
        # *   'deleteOnTermination<~Boolean>
        #
        # {Amazon API Reference}[http://docs.amazonwebservices.com/AWSEC2/2012-03-01/APIReference/ApiReference-query-DescribeNetworkInterfaceAttribute.html]
        def describe_network_interface_attribute(network_interface_id, attribute)
          request(
            'Action'             => 'DescribeNetworkInterfaceAttribute',
            'NetworkInterfaceId' => network_interface_id,
            'Attribute'          => attribute,
            :parser              => Fog::Parsers::AWS::Compute::DescribeNetworkInterfaceAttribute.new
          )
        end
      end

      class Mock
        def describe_network_interface_attribute(network_interface_id, attribute)
          response = Excon::Response.new
          network_interface = self.data[:network_interfaces][network_interface_id]


          unless network_interface
            raise Fog::AWS::Compute::NotFound.new("The network interface '#{network_interface_id}' does not exist")
          end

          response.status = 200
          response.body = {
            'requestId'          => Fog::AWS::Mock.request_id,
            'networkInterfaceId' => network_interface_id
          }
          case attribute
          when 'description', 'groupSet', 'sourceDestCheck', 'attachment'
            response.body[attribute] = network_interface[attribute]
          else
            raise Fog::AWS::Compute::Error.new("Illegal attribute '#{attribute}' specified")
          end
          response
        end
      end
    end
  end
end