Sha256: c9283b5fd7748b00b259dfa835f38f42523b84f3a9d357a1abe5f07de3690741

Contents?: true

Size: 1.96 KB

Versions: 36

Compression:

Stored size: 1.96 KB

Contents

module Fog
  module AWS
    class Compute
      class Real
        require 'fog/aws/parsers/compute/basic'

        # Adds tags to resources
        #
        # ==== Parameters
        # * resources<~String> - One or more resources to tag
        # * tags<~String> - hash of key value tag pairs to assign
        #
        # ==== Returns
        # * response<~Excon::Response>:
        #   * body<~Hash>:
        #     * 'requestId'<~String> - Id of request
        #     * 'return'<~Boolean> - success?
        #
        # {Amazon API Reference}[http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-CreateTags.html]
        def create_tags(resources, tags)
          resources = [*resources]
          for key, value in tags
            if value.nil?
              tags[key] = ''
            end
          end
          params = {}
          params.merge!(Fog::AWS.indexed_param('ResourceId', resources))
          params.merge!(Fog::AWS.indexed_param('Tag.%d.Key', tags.keys))
          params.merge!(Fog::AWS.indexed_param('Tag.%d.Value', tags.values))
          request({
            'Action'    => 'CreateTags',
            :idempotent => true,
            :parser     => Fog::Parsers::AWS::Compute::Basic.new
          }.merge!(params))
        end
      end

      class Mock
        def create_tags(resources, tags)
          resources = [*resources]
          tagged = tagged_resources(resources)

          tags.each do |key, value|
            self.data[:tags][key] ||= {}
            self.data[:tags][key][value] ||= []
            self.data[:tags][key][value] |= tagged

            tagged.each do |resource|
              self.data[:tag_sets][resource['resourceId']][key] = value
            end
          end

          response = Excon::Response.new
          response.status = 200
          response.body = {
            'requestId' => Fog::AWS::Mock.request_id,
            'return'    => true
          }
          response
        end
      end
    end
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
fog-aws-3.29.0 lib/fog/aws/requests/compute/create_tags.rb
fog-aws-3.28.0 lib/fog/aws/requests/compute/create_tags.rb
fog-aws-3.27.0 lib/fog/aws/requests/compute/create_tags.rb
fog-aws-3.26.0 lib/fog/aws/requests/compute/create_tags.rb
fog-aws-3.25.0 lib/fog/aws/requests/compute/create_tags.rb
fog-aws-3.24.0 lib/fog/aws/requests/compute/create_tags.rb
fog-aws-3.23.0 lib/fog/aws/requests/compute/create_tags.rb
fog-aws-3.22.0 lib/fog/aws/requests/compute/create_tags.rb
fog-aws-3.21.1 lib/fog/aws/requests/compute/create_tags.rb
fog-aws-3.21.0 lib/fog/aws/requests/compute/create_tags.rb
fog-aws-3.20.0 lib/fog/aws/requests/compute/create_tags.rb
fog-aws-3.19.0 lib/fog/aws/requests/compute/create_tags.rb
fog-aws-3.18.0 lib/fog/aws/requests/compute/create_tags.rb
fog-aws-3.17.0 lib/fog/aws/requests/compute/create_tags.rb
fog-aws-3.16.0 lib/fog/aws/requests/compute/create_tags.rb
fog-aws-3.15.0 lib/fog/aws/requests/compute/create_tags.rb
fog-aws-3.14.0 lib/fog/aws/requests/compute/create_tags.rb
fog-aws-3.13.0 lib/fog/aws/requests/compute/create_tags.rb
fog-aws-3.12.0 lib/fog/aws/requests/compute/create_tags.rb
fog-aws-3.11.0 lib/fog/aws/requests/compute/create_tags.rb