File: describe_classic_link_instances.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 (73 lines) | stat: -rw-r--r-- 3,678 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
module Fog
  module AWS
    class Compute
      class Real
        require 'fog/aws/parsers/compute/describe_classic_link_instances'
        # Describes one or more of your linked EC2-Classic instances. This request only returns information about EC2-Classic instances linked to a VPC through ClassicLink; you cannot use this request to return information about other instances.
        #
        # ==== Parameters
        # * options<~Hash>
        #   * instance_ids<~Array>  - An array of instance ids to restruct the results to
        #   * filters<~Hash> - Filters to restrict the results to. Recognises vpc-id, group-id, instance-id in addition
        #                      to tag-key, tag-value and tag:key
        #   * max_results
        #   * next_token
        # === Returns
        # * response<~Excon::Response>:
        # * body<~Hash>:
        # * 'requestId'<~String>           - Id of request
        # * 'instancesSet'<~Array>          - array of ClassicLinkInstance
        #   * 'vpcId'<~String>
        #   * 'instanceId'<~String>
        #   * 'tagSet'<~Hash>
        #   * 'groups'<~Array>
        #     * groupId <~String>
        #     * groupName <~String>
        # (Amazon API Reference)[http://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeClassicLinkInstances.html
        def describe_classic_link_instances(options={})
          params = {}
          params['MaxResults'] = options[:max_results] if options[:max_results]
          params['NextToken'] = options[:next_token] if options[:next_token]
          params.merge!(Fog::AWS.indexed_param('InstanceId', options[:instance_ids])) if options[:instance_ids]
          params.merge!(Fog::AWS.indexed_filters(options[:filters])) if options[:filters]
          request({
            'Action'    => 'DescribeClassicLinkInstances',
            :parser     => Fog::Parsers::AWS::Compute::DescribeClassicLinkInstances.new
          }.merge(params))
        end
      end

      class Mock
        def describe_classic_link_instances(options={})
          response = Excon::Response.new
          instances = self.data[:instances].values.select {|instance| instance['classicLinkVpcId']}
          if options[:filters]
            instances = apply_tag_filters(instances, options[:filters], 'instanceId')
            instances = instances.select {|instance| instance['classicLinkVpcId'] == options[:filters]['vpc-id']} if options[:filters]['vpc-id']
            instances = instances.select {|instance| instance['instanceId'] == options[:filters]['instance-id']} if options[:filters]['instance-id']
            instances = instances.select {|instance| instance['classicLinkSecurityGroups'].include?(options[:filters]['group-id'])} if options[:filters]['group-id']
          end
          instances = instances.select {|instance| options[:instance_ids].include?(instance['instanceId'])} if options[:instance_ids]



          response.status = 200
          instance_data = instances.collect do |instance| 
            groups = self.data[:security_groups].values.select {|data| instance['classicLinkSecurityGroups'].include?(data['groupId'])}
            {
              'instanceId' => instance['instanceId'],
              'vpcId' => instance['classicLinkVpcId'],
              'groups' => groups.collect {|group| {'groupId' => group['groupId'], 'groupName' => group['groupName']}},
              'tagSet' => self.data[:tag_sets][instance['instanceId']] || {}
            }
          end
          response.body = {
            'requestId' => Fog::AWS::Mock.request_id,
            'instancesSet' => instance_data
          }
          response
        end
      end
    end
  end
end