File: copy_image.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 (59 lines) | stat: -rw-r--r-- 2,176 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
module Fog
  module AWS
    class Compute
      class Real
        require 'fog/aws/parsers/compute/copy_image'

        # Copy an image to a different region
        #
        # ==== Parameters
        # * source_image_id<~String>    - The ID of the AMI to copy
        # * source_region<~String>      - The name of the AWS region that contains the AMI to be copied
        # * name<~String>               - The name of the new AMI in the destination region
        # * description<~String>        - The description to set on the new AMI in the destination region
        # * client_token<~String>       - Unique, case-sensitive identifier you provide to ensure idempotency of the request
        #
        # ==== Returns
        # * response<~Excon::Response>:
        #   * body<~Hash>:
        #     * 'requestId'<~String> - id of request
        #     * 'imageId'<~String> - id of image
        #
        # {Amazon API Reference}[http://docs.aws.amazon.com/AWSEC2/latest/CommandLineReference/ApiReference-cmd-CopyImage.html]
        def copy_image(source_image_id, source_region, name = nil, description = nil, client_token = nil)
          request(
            'Action'          => 'CopyImage',
            'SourceImageId'   => source_image_id,
            'SourceRegion'    => source_region,
            'Name'            => name,
            'Description'     => description,
            'ClientToken'     => client_token,
            :parser           => Fog::Parsers::AWS::Compute::CopyImage.new
          )
        end
      end

      class Mock
        #
        # Usage
        #
        # Fog::AWS[:compute].copy_image("ami-1aad5273", 'us-east-1')
        #

        def copy_image(source_image_id, source_region, name = nil, description = nil, client_token = nil)
          response = Excon::Response.new
          response.status = 200
          image_id = Fog::AWS::Mock.image_id
          data = {
            'imageId'  => image_id,
          }
          self.data[:images][image_id] = data
          response.body = {
            'requestId' => Fog::AWS::Mock.request_id
          }.merge!(data)
          response
        end
      end
    end
  end
end