class Fog::Image::OpenStack::V2::Real

Public Class Methods

new(options = {}) click to toggle source
# File lib/fog/openstack/image_v2.rb, line 115
def initialize(options = {})
  initialize_identity options

  @openstack_service_type           = options[:openstack_service_type] || ['image']
  @openstack_service_name           = options[:openstack_service_name]
  @openstack_endpoint_type          = options[:openstack_endpoint_type] || 'adminURL'

  @connection_options               = options[:connection_options] || {}

  authenticate

  unless @path.match(SUPPORTED_VERSIONS)
    @path = Fog::OpenStack.get_supported_version_path(SUPPORTED_VERSIONS,
                                                      @openstack_management_uri,
                                                      @auth_token,
                                                      @connection_options)
  end

  @persistent = options[:persistent] || false
  @connection = Fog::Core::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
end
not_found_class() click to toggle source
# File lib/fog/openstack/image_v2.rb, line 110
def self.not_found_class
  Fog::Image::OpenStack::NotFound
end

Public Instance Methods

add_member_to_image(image_id, tenant_id) click to toggle source
# File lib/fog/openstack/requests/image_v2/add_member_to_image.rb, line 6
def add_member_to_image(image_id, tenant_id)
  request(
      :expects => [200],
      :method => 'POST',
      :path => "images/#{image_id}/members",
      :body => Fog::JSON.encode({:member => tenant_id})
  )
end
add_tag_to_image(image_id, tag) click to toggle source
# File lib/fog/openstack/requests/image_v2/add_tag_to_image.rb, line 6
def add_tag_to_image(image_id, tag)
  request(
      :expects => [204],
      :method => 'PUT',
      :path => "images/#{image_id}/tags/#{tag}"
  )
end
create_image(image) click to toggle source
# File lib/fog/openstack/requests/image_v2/create_image.rb, line 7
def create_image(image)
  location = image.delete :location
  headers = {}
  headers["Location"] = location if location

  request(
      :headers => headers,
      :expects => [201],
      :method => 'POST',
      :path => "images",
      :body => Fog::JSON.encode(image)
  )
end
deactivate_image(image_id) click to toggle source
# File lib/fog/openstack/requests/image_v2/deactivate_image.rb, line 6
def deactivate_image(image_id)
  request(
      :expects => 204,
      :method => 'POST',
      :path => "images/#{image_id}/actions/deactivate"
  )
end
delete_image(image_id) click to toggle source
# File lib/fog/openstack/requests/image_v2/delete_image.rb, line 6
def delete_image(image_id)
  request(
      :expects => 204,
      :method => 'DELETE',
      :path => "images/#{image_id}"
  )
end
download_image(image_id, content_range=nil, params) click to toggle source
# File lib/fog/openstack/requests/image_v2/download_image.rb, line 6
def download_image(image_id, content_range=nil, params) # TODO: implement content range handling
  request_hash = {
      :expects => [200, 204],
      :method => 'GET',
      :raw_body => true,
      :path => "images/#{image_id}/file",
  }
  request_hash[:response_block] = params[:response_block] if params[:response_block]
  request(request_hash).body
end
get_image(image_id) click to toggle source
# File lib/fog/openstack/requests/image_v2/get_image.rb, line 6
def get_image(image_id)
  request(
      :expects => [200, 204],
      :method => 'HEAD',
      :path => "images/#{image_id}"
  )
end
get_image_by_id(image_id) click to toggle source
# File lib/fog/openstack/requests/image_v2/get_image_by_id.rb, line 6
def get_image_by_id(image_id)
  request(
      :expects => [200],
      :method => 'GET',
      :path => "images/#{image_id}"
  )
end
get_image_members(image_id) click to toggle source
# File lib/fog/openstack/requests/image_v2/get_image_members.rb, line 6
def get_image_members(image_id)
  request(
      :expects => [200, 204],
      :method => 'GET',
      :path => "images/#{image_id}/members"
  )
end
get_member_details(image_id, member_id) click to toggle source
# File lib/fog/openstack/requests/image_v2/get_member_details.rb, line 6
def get_member_details(image_id, member_id)
  request(
      :expects => [200],
      :method => 'GET',
      :path => "images/#{image_id}/members/#{member_id}"
  ).body
end
get_shared_images(tenant_id) click to toggle source
# File lib/fog/openstack/requests/image_v2/get_shared_images.rb, line 6
def get_shared_images(tenant_id)
  request(
      :expects => [200, 204],
      :method => 'GET',
      :path => "shared-images/#{tenant_id}"
  )
end
list_images(options = {}) click to toggle source
# File lib/fog/openstack/requests/image_v2/list_images.rb, line 6
def list_images(options = {})
  request(
      :expects => [200],
      :method => 'GET',
      :path => 'images',
      :query => options
  )
end
reactivate_image(image_id) click to toggle source
# File lib/fog/openstack/requests/image_v2/reactivate_image.rb, line 6
def reactivate_image(image_id)
  request(
      :expects => 204,
      :method => 'POST',
      :path => "images/#{image_id}/actions/reactivate"
  )
end
remove_member_from_image(image_id, member_id) click to toggle source
# File lib/fog/openstack/requests/image_v2/remove_member_from_image.rb, line 6
def remove_member_from_image(image_id, member_id)
  request(
      :expects => [200, 204],
      :method => 'DELETE',
      :path => "images/#{image_id}/members/#{member_id}"
  )
end
remove_tag_from_image(image_id, tag) click to toggle source
# File lib/fog/openstack/requests/image_v2/remove_tag_from_image.rb, line 6
def remove_tag_from_image(image_id, tag)
  request(
      :expects => [204],
      :method => 'DELETE',
      :path => "images/#{image_id}/tags/#{tag}"
  )
end
set_tenant(tenant) click to toggle source
# File lib/fog/openstack/requests/image_v2/set_tenant.rb, line 6
def set_tenant(tenant)
  @openstack_must_reauthenticate = true
  @openstack_tenant = tenant.to_s
  authenticate
end
update_image(id, json_patch) click to toggle source
# File lib/fog/openstack/requests/image_v2/update_image.rb, line 6
def update_image(id, json_patch)
  request(
      :headers => {'Content-Type' => 'application/openstack-images-v2.1-json-patch'},
      :expects => [200],
      :method => 'PATCH',
      :path => "images/#{id}",
      :body => Fog::JSON.encode(json_patch)
  )
end
update_image_member(image_id, member) click to toggle source
# File lib/fog/openstack/requests/image_v2/update_image_member.rb, line 6
def update_image_member(image_id, member)
  request( # 'status' is the only property we can update
      :body => Fog::JSON.encode(member.select {|key, value| key=='status'}),
      :expects => [200],
      :method => 'PUT',
      :path => "images/#{image_id}/members/#{member['member_id']}"
  )
end
upload_image(image_id, body, params={}) click to toggle source
# File lib/fog/openstack/requests/image_v2/upload_image.rb, line 6
def upload_image(image_id, body, params={})
  request_hash = {
      :headers => {'Content-Type' => 'application/octet-stream'},
      :expects => 204,
      :method => 'PUT',
      :path => "images/#{image_id}/file"
  }
  request_hash[:request_block] = params[:request_block] if params[:request_block]
  request_hash[:body] = body if body
  request(request_hash).body
ensure
  body.close if body.respond_to?(:close)
end