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

Inherits:
Object
  • Object
show all
Includes:
OpenStack::Common, OpenStack::Core
Defined in:
lib/fog/openstack/image_v2.rb,
lib/fog/openstack/requests/image_v2/get_image.rb,
lib/fog/openstack/requests/image_v2/set_tenant.rb,
lib/fog/openstack/requests/image_v2/list_images.rb,
lib/fog/openstack/requests/image_v2/create_image.rb,
lib/fog/openstack/requests/image_v2/delete_image.rb,
lib/fog/openstack/requests/image_v2/update_image.rb,
lib/fog/openstack/requests/image_v2/upload_image.rb,
lib/fog/openstack/requests/image_v2/download_image.rb,
lib/fog/openstack/requests/image_v2/get_image_by_id.rb,
lib/fog/openstack/requests/image_v2/add_tag_to_image.rb,
lib/fog/openstack/requests/image_v2/deactivate_image.rb,
lib/fog/openstack/requests/image_v2/reactivate_image.rb,
lib/fog/openstack/requests/image_v2/get_image_members.rb,
lib/fog/openstack/requests/image_v2/get_shared_images.rb,
lib/fog/openstack/requests/image_v2/get_member_details.rb,
lib/fog/openstack/requests/image_v2/add_member_to_image.rb,
lib/fog/openstack/requests/image_v2/update_image_member.rb,
lib/fog/openstack/requests/image_v2/remove_tag_from_image.rb,
lib/fog/openstack/requests/image_v2/remove_member_from_image.rb

Instance Attribute Summary

Attributes included from OpenStack::Common

#unscoped_token

Attributes included from OpenStack::Core

#auth_token, #auth_token_expiration, #current_tenant, #current_user, #current_user_id, #openstack_domain_id, #openstack_domain_name, #openstack_identity_prefix, #openstack_project_domain, #openstack_project_domain_id, #openstack_user_domain, #openstack_user_domain_id

Class Method Summary collapse

Instance Method Summary collapse

Methods included from OpenStack::Common

#request

Methods included from OpenStack::Core

#credentials, #initialize_identity, #reload

Constructor Details

#initialize(options = {}) ⇒ Real

Returns a new instance of Real.



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/fog/openstack/image_v2.rb', line 114

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

Class Method Details

.not_found_classObject



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

def self.not_found_class
  Fog::Image::OpenStack::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/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) ⇒ Object



6
7
8
9
10
11
12
# 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) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
# 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) ⇒ Object



6
7
8
9
10
11
12
# 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) ⇒ Object



6
7
8
9
10
11
12
# 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) ⇒ Object

TODO: implement content range handling



6
7
8
9
10
11
12
13
14
15
# 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) ⇒ Object



6
7
8
9
10
11
12
# 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) ⇒ Object



6
7
8
9
10
11
12
# 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) ⇒ Object



6
7
8
9
10
11
12
# 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) ⇒ Object



6
7
8
9
10
11
12
# 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) ⇒ Object



6
7
8
9
10
11
12
# 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 = {}) ⇒ Object



6
7
8
9
10
11
12
13
# 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) ⇒ Object



6
7
8
9
10
11
12
# 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) ⇒ Object



6
7
8
9
10
11
12
# 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) ⇒ Object



6
7
8
9
10
11
12
# 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) ⇒ Object



6
7
8
9
10
# 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) ⇒ Object



6
7
8
9
10
11
12
13
14
# 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) ⇒ Object



6
7
8
9
10
11
12
13
# 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 = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
# 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