Sha256: 363e973ecb7d57c97e7e0a4dab21fa6bf6ad57fcfff8e2b19c5a3b22e5b0886c

Contents?: true

Size: 1.63 KB

Versions: 28

Compression:

Stored size: 1.63 KB

Contents

module Fog
  module Rackspace
    class Compute
      class Real

        # Create an image from a running server
        #
        # ==== Parameters
        # * server_id<~Integer> - Id of server to create image from
        # * options<~Hash> - Name
        #
        # ==== Returns
        # * response<~Excon::Response>:
        #   * 'image'<~Hash>:
        #     * 'id'<~Integer> - Id of image
        #     * 'name'<~String> - Name of image
        #     * 'serverId'<~Integer> - Id of server
        def create_image(server_id, options = {})
          data = {
            'image' => {
              'serverId' => server_id
            }
          }
          if options['name']
            data['image']['name'] = options['name']
          end
          request(
            :body     => data.to_json,
            :expects  => 202,
            :method   => 'POST',
            :path     => "images"
          )
        end

      end

      class Mock

        def create_image(server_id, options = {})
          response = Excon::Response.new
          response.status = 202

          now = Time.now
          data = {
            'created'   => now,
            'id'        => 123456,
            'name'      => options['name'] || '',
            'serverId'  => server_id,
            'status'    => 'SAVING',
            'updated'   => now.to_s,
          }

          @data[:last_modified][:images][data['id']] = now
          @data[:images][data['id']] = data
          response.body = { 'image' => data.reject {|key, value| !['id', 'name', 'serverId', 'status', 'updated'].include?(key)} }
          response
        end

      end
    end
  end
end

Version data entries

28 entries across 28 versions & 2 rubygems

Version Path
fog-0.3.34 lib/fog/rackspace/requests/compute/create_image.rb
fog-0.3.33 lib/fog/rackspace/requests/compute/create_image.rb
fog-0.3.32 lib/fog/rackspace/requests/compute/create_image.rb
fog-0.3.31 lib/fog/rackspace/requests/compute/create_image.rb
fog-0.3.30 lib/fog/rackspace/requests/compute/create_image.rb
fog-0.3.29 lib/fog/rackspace/requests/compute/create_image.rb
fog-0.3.28 lib/fog/rackspace/requests/compute/create_image.rb
fog-0.3.27 lib/fog/rackspace/requests/compute/create_image.rb
fog-0.3.26 lib/fog/rackspace/requests/compute/create_image.rb
fog-0.3.25 lib/fog/rackspace/requests/compute/create_image.rb
fog-0.3.24 lib/fog/rackspace/requests/compute/create_image.rb
bbcloud-0.8.1 lib/bbcloud/vendor/fog-0.3.23/lib/fog/rackspace/requests/compute/create_image.rb
fog-0.3.23 lib/fog/rackspace/requests/compute/create_image.rb
fog-0.3.22 lib/fog/rackspace/requests/compute/create_image.rb
fog-0.3.21 lib/fog/rackspace/requests/compute/create_image.rb
fog-0.3.20 lib/fog/rackspace/requests/compute/create_image.rb
fog-0.3.19 lib/fog/rackspace/requests/compute/create_image.rb
fog-0.3.18 lib/fog/rackspace/requests/compute/create_image.rb
fog-0.3.17 lib/fog/rackspace/requests/compute/create_image.rb
fog-0.3.16 lib/fog/rackspace/requests/compute/create_image.rb