Sha256: 3e66c5676602d6108486a237b3fc3ab173194bb3b15cf97462dd76c6918aa0b1

Contents?: true

Size: 1.62 KB

Versions: 1

Compression:

Stored size: 1.62 KB

Contents

module Fog
  module Compute
    class RackspaceV2
      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 = {
            'createImage' => {
            }
          }
          data['createImage'].merge!(options)
          request(
            :body     => Fog::JSON.encode(data),
            :expects  => [202],
            :method   => 'POST',
            :path     => "servers/#{server_id}/action",
          )
        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,
          }

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

1 entries across 1 versions & 1 rubygems

Version Path
fog-sgonyea-1.8.1 lib/fog/rackspace/requests/compute_v2/create_image.rb