File: describe_subnets.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 (72 lines) | stat: -rw-r--r-- 2,860 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
69
70
71
72
module Fog
  module AWS
    class Compute
      class Real
        require 'fog/aws/parsers/compute/describe_subnets'

        # Describe all or specified subnets
        #
        # ==== Parameters
        # * filters<~Hash> - List of filters to limit results with
        #
        # === Returns
        # * response<~Excon::Response>:
        # * body<~Hash>:
        # * 'requestId'<~String> - Id of request
        # * 'subnetSet'<~Array>:
        #   * 'subnetId'<~String> - The Subnet's ID
        #   * 'state'<~String> - The current state of the Subnet. ['pending', 'available']
        #   * 'vpcId'<~String> - The ID of the VPC the subnet is in
        #   * 'cidrBlock'<~String> - The CIDR block the Subnet covers.
        #   * 'availableIpAddressCount'<~Integer> - The number of unused IP addresses in the subnet (the IP addresses for any
        #     stopped instances are considered unavailable)
        #   * 'availabilityZone'<~String> - The Availability Zone the subnet is in.
        #   * 'tagSet'<~Array>: Tags assigned to the resource.
        #     * 'key'<~String> - Tag's key
        #     * 'value'<~String> - Tag's value
        #   * 'mapPublicIpOnLaunch'<~Boolean> - Indicates whether instances launched in this subnet receive a public IPv4 address.
        #   * 'defaultForAz'<~Boolean> - Indicates whether this is the default subnet for the Availability Zone.
        #
        # {Amazon API Reference}[http://docs.amazonwebservices.com/AWSEC2/2011-07-15/APIReference/index.html?ApiReference-query-DescribeSubnets.html]
        def describe_subnets(filters = {})
          unless filters.is_a?(Hash)
            Fog::Logger.warning("describe_subnets with #{filters.class} param is deprecated, use describe_subnets('subnet-id' => []) instead [light_black](#{caller.first})[/]")
            filters = {'subnet-id' => [*filters]}
          end
          params = Fog::AWS.indexed_filters(filters)
          request({
            'Action'    => 'DescribeSubnets',
            :idempotent => true,
            :parser     => Fog::Parsers::AWS::Compute::DescribeSubnets.new
          }.merge!(params))
        end
      end

      class Mock
        def describe_subnets(filters = {})
          subnets = self.data[:subnets]

          # Transition from pending to available
          subnets.each do |subnet|
            case subnet['state']
              when 'pending'
                subnet['state'] = 'available'
            end
          end

          if filters['subnet-id']
            subnets = subnets.reject {|subnet| subnet['subnetId'] != filters['subnet-id']}
          end

          Excon::Response.new(
            :status => 200,
            :body   => {
              'requestId' => Fog::AWS::Mock.request_id,
              'subnetSet' => subnets
            }
          )
        end
      end
    end
  end
end