Sha256: 9c968e01f5e68bf70b1410781c2199ef2be81b02c94b8d91b54d8117b7cddfea

Contents?: true

Size: 1.6 KB

Versions: 84

Compression:

Stored size: 1.6 KB

Contents

module Fog
  module Rackspace
    module Servers
      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,
          }

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

      end
    end
  end
end

Version data entries

84 entries across 84 versions & 2 rubygems

Version Path
fog-0.0.82 lib/fog/rackspace/requests/servers/create_image.rb
fog-0.0.81 lib/fog/rackspace/requests/servers/create_image.rb
fog-0.0.80 lib/fog/rackspace/requests/servers/create_image.rb
fog-0.0.79 lib/fog/rackspace/requests/servers/create_image.rb
fog-0.0.78 lib/fog/rackspace/requests/servers/create_image.rb
fog-0.0.77 lib/fog/rackspace/requests/servers/create_image.rb
fog-0.0.76 lib/fog/rackspace/requests/servers/create_image.rb
fog-0.0.75 lib/fog/rackspace/requests/servers/create_image.rb
fog-0.0.74 lib/fog/rackspace/requests/servers/create_image.rb
fog-0.0.73 lib/fog/rackspace/requests/servers/create_image.rb
fog-0.0.72 lib/fog/rackspace/requests/servers/create_image.rb
fog-0.0.71 lib/fog/rackspace/requests/servers/create_image.rb
fog-0.0.70 lib/fog/rackspace/requests/servers/create_image.rb
fog-0.0.69 lib/fog/rackspace/requests/servers/create_image.rb
fog-0.0.68 lib/fog/rackspace/requests/servers/create_image.rb
fog-0.0.67 lib/fog/rackspace/requests/servers/create_image.rb
fog-0.0.66 lib/fog/rackspace/requests/servers/create_image.rb
fog-0.0.65 lib/fog/rackspace/requests/servers/create_image.rb
fog-0.0.64 lib/fog/rackspace/requests/servers/create_image.rb
fog-0.0.63 lib/fog/rackspace/requests/servers/create_image.rb