Class: Fog::OpenStack::Image::V2::Real

Inherits:
Object
  • Object
show all
Includes:
Core
Defined in:
lib/fog/openstack/image/v2.rb,
lib/fog/openstack/image/v2/requests/get_image.rb,
lib/fog/openstack/image/v2/requests/set_tenant.rb,
lib/fog/openstack/image/v2/requests/list_images.rb,
lib/fog/openstack/image/v2/requests/create_image.rb,
lib/fog/openstack/image/v2/requests/delete_image.rb,
lib/fog/openstack/image/v2/requests/update_image.rb,
lib/fog/openstack/image/v2/requests/upload_image.rb,
lib/fog/openstack/image/v2/requests/download_image.rb,
lib/fog/openstack/image/v2/requests/get_image_by_id.rb,
lib/fog/openstack/image/v2/requests/add_tag_to_image.rb,
lib/fog/openstack/image/v2/requests/deactivate_image.rb,
lib/fog/openstack/image/v2/requests/reactivate_image.rb,
lib/fog/openstack/image/v2/requests/get_image_members.rb,
lib/fog/openstack/image/v2/requests/get_shared_images.rb,
lib/fog/openstack/image/v2/requests/get_member_details.rb,
lib/fog/openstack/image/v2/requests/add_member_to_image.rb,
lib/fog/openstack/image/v2/requests/update_image_member.rb,
lib/fog/openstack/image/v2/requests/remove_tag_from_image.rb,
lib/fog/openstack/image/v2/requests/remove_member_from_image.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



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

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
13
# File 'lib/fog/openstack/image/v2/requests/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) ⇒ Object



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



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/fog/openstack/image/v2/requests/create_image.rb', line 6

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) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/fog/openstack/image/v2/requests/deactivate_image.rb', line 6

def deactivate_image(image_id)
  request(
    :expects => 204,
    :method  => 'POST',
    :path    => "images/#{image_id}/actions/deactivate"
  )
end

#default_endpoint_typeObject



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

def default_endpoint_type
  'admin'
end

#default_path_prefixObject



117
118
119
# File 'lib/fog/openstack/image/v2.rb', line 117

def default_path_prefix
  'v2'
end

#default_service_typeObject



121
122
123
# File 'lib/fog/openstack/image/v2.rb', line 121

def default_service_type
  %w[image imagev2]
end

#delete_image(image_id) ⇒ Object



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

TODO: implement content range handling



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



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



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



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



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



6
7
8
9
10
11
12
13
# File 'lib/fog/openstack/image/v2/requests/list_images.rb', line 6

def list_images(options = {})
  request(
    :expects => [200],
    :method  => 'GET',
    :path    => 'images',
    :query   => options
  )
end

#reactivate_image(image_id) ⇒ Object



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



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

#remove_tag_from_image(image_id, tag) ⇒ Object



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



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



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



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



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