Class: Fog::OpenStack::Image::V1::Real

Inherits:
Object
  • Object
show all
Includes:
Core
Defined in:
lib/fog/openstack/image/v1.rb,
lib/fog/openstack/image/v1/requests/get_image.rb,
lib/fog/openstack/image/v1/requests/set_tenant.rb,
lib/fog/openstack/image/v1/requests/create_image.rb,
lib/fog/openstack/image/v1/requests/delete_image.rb,
lib/fog/openstack/image/v1/requests/update_image.rb,
lib/fog/openstack/image/v1/requests/get_image_by_id.rb,
lib/fog/openstack/image/v1/requests/get_image_members.rb,
lib/fog/openstack/image/v1/requests/get_shared_images.rb,
lib/fog/openstack/image/v1/requests/list_public_images.rb,
lib/fog/openstack/image/v1/requests/add_member_to_image.rb,
lib/fog/openstack/image/v1/requests/update_image_members.rb,
lib/fog/openstack/image/v1/requests/remove_member_from_image.rb,
lib/fog/openstack/image/v1/requests/list_public_images_detailed.rb

Instance Attribute Summary

Attributes included from Core

#auth_token, #auth_token_expiration, #current_tenant, #current_user, #current_user_id, #openstack_cache_ttl, #openstack_domain_id, #openstack_domain_name, #openstack_identity_api_version, #openstack_project_domain, #openstack_project_domain_id, #openstack_project_id, #openstack_user_domain, #openstack_user_domain_id, #unscoped_token

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Core

#credentials, #initialize, #reload

Class Method Details

.not_found_classObject



101
102
103
# File 'lib/fog/openstack/image/v1.rb', line 101

def self.not_found_class
  Fog::OpenStack::Image::NotFound
end

Instance Method Details

#add_member_to_image(image_id, tenant_id) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/fog/openstack/image/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) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/fog/openstack/image/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

#default_endpoint_typeObject



105
106
107
# File 'lib/fog/openstack/image/v1.rb', line 105

def default_endpoint_type
  'admin'
end

#default_path_prefixObject



109
110
111
# File 'lib/fog/openstack/image/v1.rb', line 109

def default_path_prefix
  'v1'
end

#default_service_typeObject



113
114
115
# File 'lib/fog/openstack/image/v1.rb', line 113

def default_service_type
  %w[imagev1]
end

#delete_image(image_id) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/fog/openstack/image/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) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/fog/openstack/image/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) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/fog/openstack/image/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) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/fog/openstack/image/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) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/fog/openstack/image/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 = {}) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/fog/openstack/image/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) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/fog/openstack/image/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) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/fog/openstack/image/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_tenant(tenant) ⇒ Object



6
7
8
9
10
# File 'lib/fog/openstack/image/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) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/fog/openstack/image/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) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/fog/openstack/image/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