File: describe_vpcs.rb

package info (click to toggle)
ruby-fog-aws 3.18.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,140 kB
  • sloc: ruby: 73,328; javascript: 14; makefile: 9; sh: 4
file content (74 lines) | stat: -rw-r--r-- 2,542 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
73
74
module Fog
  module AWS
    class Compute
      class Real
        require 'fog/aws/parsers/compute/describe_vpcs'

        # Describe all or specified vpcs
        #
        # ==== Parameters
        # * filters<~Hash> - List of filters to limit results with
        #
        # === Returns
        # * response<~Excon::Response>:
        # * body<~Hash>:
        # * 'requestId'<~String> - Id of request
        # * 'vpcSet'<~Array>:
        # * 'vpcId'<~String> - The VPC's ID
        # * 'state'<~String> - The current state of the VPC. ['pending', 'available']
        # * 'cidrBlock'<~String> - The CIDR block the VPC covers.
        # * 'dhcpOptionsId'<~String> - The ID of the set of DHCP options.
        # * 'tagSet'<~Array>: Tags assigned to the resource.
        # * 'key'<~String> - Tag's key
        # * 'value'<~String> - Tag's value
        # * 'instanceTenancy'<~String> - The allowed tenancy of instances launched into the VPC.
        #
        # {Amazon API Reference}[http://docs.amazonwebservices.com/AWSEC2/2011-07-15/APIReference/index.html?ApiReference-query-DescribeVpcs.html]
        def describe_vpcs(filters = {})
          unless filters.is_a?(Hash)
            Fog::Logger.warning("describe_vpcs with #{filters.class} param is deprecated, use describe_vpcs('vpc-id' => []) instead [light_black](#{caller.first})[/]")
            filters = {'vpc-id' => [*filters]}
          end
          params = Fog::AWS.indexed_filters(filters)
          request({
            'Action' => 'DescribeVpcs',
            :idempotent => true,
            :parser => Fog::Parsers::AWS::Compute::DescribeVpcs.new
          }.merge!(params))
        end
      end

      class Mock
        def describe_vpcs(filters = {})
          vpcs = self.data[:vpcs]
          vpcs = apply_tag_filters(vpcs, filters, 'vpcId')

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

          if filters['vpc-id']
            vpcs = vpcs.reject {|vpc| vpc['vpcId'] != filters['vpc-id']}
          end

          vpcs.each do |vpc|
            tags = self.data[:tag_sets][vpc['vpcId']]
            vpc.merge!('tagSet' => tags) if tags
          end

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