Sha256: 132e63cb4bc03609a31d63057a87cbf82c82aa846879b9860d09efd44b1d0b3d

Contents?: true

Size: 1.71 KB

Versions: 27

Compression:

Stored size: 1.71 KB

Contents

unless Fog.mocking?

  module Fog
    module Rackspace
      class Servers

        # 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
    end
  end

else

  module Fog
    module Rackspace
      class Servers

        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,
          }

          Fog::Rackspace::Servers.data[:last_modified][:images][data['id']] = now
          Fog::Rackspace::Servers.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

27 entries across 27 versions & 1 rubygems

Version Path
fog-0.0.58 lib/fog/rackspace/requests/servers/create_image.rb
fog-0.0.57 lib/fog/rackspace/requests/servers/create_image.rb
fog-0.0.56 lib/fog/rackspace/requests/servers/create_image.rb
fog-0.0.55 lib/fog/rackspace/requests/servers/create_image.rb
fog-0.0.54 lib/fog/rackspace/requests/servers/create_image.rb
fog-0.0.53 lib/fog/rackspace/requests/servers/create_image.rb
fog-0.0.52 lib/fog/rackspace/requests/servers/create_image.rb
fog-0.0.51 lib/fog/rackspace/requests/servers/create_image.rb
fog-0.0.50 lib/fog/rackspace/requests/servers/create_image.rb
fog-0.0.49 lib/fog/rackspace/requests/servers/create_image.rb
fog-0.0.48 lib/fog/rackspace/requests/servers/create_image.rb
fog-0.0.47 lib/fog/rackspace/requests/servers/create_image.rb
fog-0.0.46 lib/fog/rackspace/requests/servers/create_image.rb
fog-0.0.45 lib/fog/rackspace/requests/servers/create_image.rb
fog-0.0.44 lib/fog/rackspace/requests/servers/create_image.rb
fog-0.0.43 lib/fog/rackspace/requests/servers/create_image.rb
fog-0.0.42 lib/fog/rackspace/requests/servers/create_image.rb
fog-0.0.41 lib/fog/rackspace/requests/servers/create_image.rb
fog-0.0.40 lib/fog/rackspace/requests/servers/create_image.rb
fog-0.0.39 lib/fog/rackspace/requests/servers/create_image.rb