Sha256: 4122a36ef868389fa8e17e413cb750b6988d454019655e4b3a582260bf45fb10

Contents?: true

Size: 1.65 KB

Versions: 16

Compression:

Stored size: 1.65 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'        => Fog::Mock.random_numbers(6).to_i,
            '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

16 entries across 16 versions & 2 rubygems

Version Path
fog-0.8.1 lib/fog/compute/requests/rackspace/create_image.rb
fog-0.8.0 lib/fog/compute/requests/rackspace/create_image.rb
fog-0.7.2 lib/fog/compute/requests/rackspace/create_image.rb
fog-0.7.1 lib/fog/compute/requests/rackspace/create_image.rb
fog-0.7.0 lib/fog/compute/requests/rackspace/create_image.rb
fog-0.6.0 lib/fog/compute/requests/rackspace/create_image.rb
fog-0.5.3 lib/fog/compute/requests/rackspace/create_image.rb
fog-0.5.2 lib/fog/compute/requests/rackspace/create_image.rb
fog-0.5.1 lib/fog/compute/requests/rackspace/create_image.rb
fog-0.5.0 lib/fog/compute/requests/rackspace/create_image.rb
phpfog-fog-0.4.1.3 lib/fog/compute/requests/rackspace/create_image.rb
phpfog-fog-0.4.1.2 lib/fog/compute/requests/rackspace/create_image.rb
phpfog-fog-0.4.1.1 lib/fog/compute/requests/rackspace/create_image.rb
phpfog-fog-0.4.1 lib/fog/compute/requests/rackspace/create_image.rb
fog-0.4.1 lib/fog/compute/requests/rackspace/create_image.rb
fog-0.4.0 lib/fog/rackspace/requests/compute/create_image.rb