class Fog::Image::OpenStack::V1::Real

Public Class Methods

new(options = {}) click to toggle source
# File lib/fog/image/openstack/v1.rb, line 105
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
  set_api_path

  @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/image/openstack/v1.rb, line 101
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/image/openstack/v1/requests/add_member_to_image.rb, line 6
def add_member_to_image(image_id, tenant_id)
  request(
    :expects => [200, 204],
    :method  => 'PUT',
    :path    => "images/#{image_id}/members/#{tenant_id}"
  )
end
create_image(attributes) click to toggle source
# File lib/fog/image/openstack/v1/requests/create_image.rb, line 6
def create_image(attributes)
  data = {
    'Content-Type'                  => 'application/octet-stream',
    'x-image-meta-name'             => attributes[:name],
    'x-image-meta-disk-format'      => attributes[:disk_format],
    'x-image-meta-container-format' => attributes[:container_format],
    'x-image-meta-size'             => attributes[:size],
    'x-image-meta-is-public'        => attributes[:is_public],
    'x-image-meta-min-ram'          => attributes[:min_ram],
    'x-image-meta-min-disk'         => attributes[:min_disk],
    'x-image-meta-checksum'         => attributes[:checksum],
    'x-image-meta-owner'            => attributes[:owner],
    'x-glance-api-copy-from'        => attributes[:copy_from]
  }.reject { |_k, v| v.nil? }

  body = ''
  if attributes[:location]
    body = File.open(attributes[:location], "rb")
    # Make sure the image file size is always present
    data['x-image-meta-size'] = File.size(body)
  end

  unless attributes[:properties].nil?
    attributes[:properties].each do |key, value|
      data["x-image-meta-property-#{key}"] = value
    end
  end

  request(
    :headers => data,
    :body    => body,
    :expects => 201,
    :method  => 'POST',
    :path    => "images"
  )
ensure
  body.close if body.respond_to?(:close)
end
delete_image(image_id) click to toggle source
# File lib/fog/image/openstack/v1/requests/delete_image.rb, line 6
def delete_image(image_id)
  request(
    :expects => 200,
    :method  => 'DELETE',
    :path    => "images/#{image_id}"
  )
end
get_image(image_id) click to toggle source
# File lib/fog/image/openstack/v1/requests/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/image/openstack/v1/requests/get_image_by_id.rb, line 6
def get_image_by_id(image_id)
  request(
    :expects => [200],
    :method  => 'HEAD',
    :path    => "images/#{image_id}"
  )
end
get_image_members(image_id) click to toggle source
# File lib/fog/image/openstack/v1/requests/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_shared_images(tenant_id) click to toggle source
# File lib/fog/image/openstack/v1/requests/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_public_images(options = {}) click to toggle source
# File lib/fog/image/openstack/v1/requests/list_public_images.rb, line 6
def list_public_images(options = {})
  request(
    :expects => [200, 204],
    :method  => 'GET',
    :path    => 'images',
    :query   => options
  )
end
list_public_images_detailed(options = {}, query_deprecated = nil) click to toggle source
# File lib/fog/image/openstack/v1/requests/list_public_images_detailed.rb, line 6
def list_public_images_detailed(options = {}, query_deprecated = nil)
  if options.kind_of?(Hash)
    query = options
  elsif options
    Fog::Logger.deprecation("Calling OpenStack[:glance].list_public_images_detailed(attribute, query) format"\
                          " is deprecated, call .list_public_images_detailed(attribute => query) instead")
    query = {options => query_deprecated}
  else
    query = {}
  end

  request(
    :expects => [200, 204],
    :method  => 'GET',
    :path    => 'images/detail',
    :query   => query
  )
end
remove_member_from_image(image_id, member_id) click to toggle source
# File lib/fog/image/openstack/v1/requests/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
set_api_path() click to toggle source
# File lib/fog/image/openstack/v1.rb, line 121
def set_api_path
  unless @path.match(SUPPORTED_VERSIONS)
    @path = Fog::OpenStack.get_supported_version_path(SUPPORTED_VERSIONS,
                                                      @openstack_management_uri,
                                                      @auth_token,
                                                      @connection_options)
  end
end
set_tenant(tenant) click to toggle source
# File lib/fog/image/openstack/v1/requests/set_tenant.rb, line 6
def set_tenant(tenant)
  @openstack_must_reauthenticate = true
  @openstack_tenant = tenant.to_s
  authenticate
end
update_image(attributes) click to toggle source
# File lib/fog/image/openstack/v1/requests/update_image.rb, line 6
def update_image(attributes)
  data = {
    'x-image-meta-name'             => attributes[:name],
    'x-image-meta-disk-format'      => attributes[:disk_format],
    'x-image-meta-container-format' => attributes[:container_format],
    'x-image-meta-size'             => attributes[:size],
    'x-image-meta-is-public'        => attributes[:is_public],
    'x-image-meta-min-ram'          => attributes[:min_ram],
    'x-image-meta-min-disk'         => attributes[:min_disk],
    'x-image-meta-checksum'         => attributes[:checksum],
    'x-image-meta-owner'            => attributes[:owner]
  }.reject { |_k, v| v.nil? }

  unless attributes[:properties].nil?
    attributes[:properties].each do |key, value|
      data["x-image-meta-property-#{key}"] = value
    end
  end

  request(
    :headers => data,
    :expects => 200,
    :method  => 'PUT',
    :path    => "images/#{attributes[:id]}"
  )
end
update_image_members(image_id, members) click to toggle source
# File lib/fog/image/openstack/v1/requests/update_image_members.rb, line 6
def update_image_members(image_id, members)
  # Sample members
  # [
  #   {'member_id' => 'tenant1', 'can_share' => true  },
  #   {'member_id' => 'tenant2', 'can_share' => false }
  # ]
  data = {'memberships' => members}

  request(
    :body    => Fog::JSON.encode(data),
    :expects => [204],
    :method  => 'PUT',
    :path    => "images/#{image_id}/members"
  )
end