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.2.30 lib/fog/rackspace/requests/servers/create_image.rb
fog-0.2.28 lib/fog/rackspace/requests/servers/create_image.rb
fog-0.2.27 lib/fog/rackspace/requests/servers/create_image.rb
fog-0.2.26 lib/fog/rackspace/requests/servers/create_image.rb
fog-0.2.25 lib/fog/rackspace/requests/servers/create_image.rb
fog-0.2.24 lib/fog/rackspace/requests/servers/create_image.rb
tecnh-fog-0.2.23.vpc lib/fog/rackspace/requests/servers/create_image.rb
fog-0.2.23 lib/fog/rackspace/requests/servers/create_image.rb
fog-0.2.22 lib/fog/rackspace/requests/servers/create_image.rb
fog-0.2.21 lib/fog/rackspace/requests/servers/create_image.rb
fog-0.2.20 lib/fog/rackspace/requests/servers/create_image.rb
fog-0.2.19 lib/fog/rackspace/requests/servers/create_image.rb
fog-0.2.18 lib/fog/rackspace/requests/servers/create_image.rb
fog-0.2.17 lib/fog/rackspace/requests/servers/create_image.rb
fog-0.2.16 lib/fog/rackspace/requests/servers/create_image.rb
fog-0.2.15 lib/fog/rackspace/requests/servers/create_image.rb
fog-0.2.14 lib/fog/rackspace/requests/servers/create_image.rb
fog-0.2.13 lib/fog/rackspace/requests/servers/create_image.rb
fog-0.2.12 lib/fog/rackspace/requests/servers/create_image.rb
fog-0.2.11 lib/fog/rackspace/requests/servers/create_image.rb