Class: Fog::Image::HuaweiCloud::V1::Real
- Inherits:
-
Object
- Object
- Fog::Image::HuaweiCloud::V1::Real
- Includes:
- HuaweiCloud::Core
- Defined in:
- lib/fog/image/huaweicloud/v1.rb,
lib/fog/image/huaweicloud/v1/requests/get_image.rb,
lib/fog/image/huaweicloud/v1/requests/set_tenant.rb,
lib/fog/image/huaweicloud/v1/requests/create_image.rb,
lib/fog/image/huaweicloud/v1/requests/delete_image.rb,
lib/fog/image/huaweicloud/v1/requests/update_image.rb,
lib/fog/image/huaweicloud/v1/requests/get_image_by_id.rb,
lib/fog/image/huaweicloud/v1/requests/get_image_members.rb,
lib/fog/image/huaweicloud/v1/requests/get_shared_images.rb,
lib/fog/image/huaweicloud/v1/requests/list_public_images.rb,
lib/fog/image/huaweicloud/v1/requests/add_member_to_image.rb,
lib/fog/image/huaweicloud/v1/requests/update_image_members.rb,
lib/fog/image/huaweicloud/v1/requests/remove_member_from_image.rb,
lib/fog/image/huaweicloud/v1/requests/list_public_images_detailed.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add_member_to_image(image_id, tenant_id) ⇒ Object
- #create_image(attributes) ⇒ Object
- #delete_image(image_id) ⇒ Object
- #get_image(image_id) ⇒ Object
- #get_image_by_id(image_id) ⇒ Object
- #get_image_members(image_id) ⇒ Object
- #get_shared_images(tenant_id) ⇒ Object
-
#initialize(options = {}) ⇒ Real
constructor
A new instance of Real.
- #list_public_images(options = {}) ⇒ Object
- #list_public_images_detailed(options = {}, query_deprecated = nil) ⇒ Object
- #remove_member_from_image(image_id, member_id) ⇒ Object
- #set_api_path ⇒ Object
- #set_tenant(tenant) ⇒ Object
- #update_image(attributes) ⇒ Object
- #update_image_members(image_id, members) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Real
Returns a new instance of Real.
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/fog/image/huaweicloud/v1.rb', line 105 def initialize( = {}) initialize_identity @huaweicloud_service_type = [:huaweicloud_service_type] || ['image'] @huaweicloud_service_name = [:huaweicloud_service_name] @huaweicloud_endpoint_type = [:huaweicloud_endpoint_type] || 'adminURL' @connection_options = [:connection_options] || {} authenticate set_api_path @persistent = [:persistent] || false @connection = Fog::Core::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options) end |
Class Method Details
.not_found_class ⇒ Object
101 102 103 |
# File 'lib/fog/image/huaweicloud/v1.rb', line 101 def self.not_found_class Fog::Image::HuaweiCloud::NotFound end |
Instance Method Details
#add_member_to_image(image_id, tenant_id) ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/fog/image/huaweicloud/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/image/huaweicloud/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) ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/fog/image/huaweicloud/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/image/huaweicloud/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/image/huaweicloud/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/image/huaweicloud/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/image/huaweicloud/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/image/huaweicloud/v1/requests/list_public_images.rb', line 6 def list_public_images( = {}) request( :expects => [200, 204], :method => 'GET', :path => 'images', :query => ) 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/image/huaweicloud/v1/requests/list_public_images_detailed.rb', line 6 def list_public_images_detailed( = {}, query_deprecated = nil) if .kind_of?(Hash) query = elsif Fog::Logger.deprecation("Calling HuaweiCloud[:glance].list_public_images_detailed(attribute, query) format"\ " is deprecated, call .list_public_images_detailed(attribute => query) instead") query = { => 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/image/huaweicloud/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 ⇒ Object
121 122 123 124 125 126 127 128 |
# File 'lib/fog/image/huaweicloud/v1.rb', line 121 def set_api_path unless @path.match(SUPPORTED_VERSIONS) @path = Fog::HuaweiCloud.get_supported_version_path(SUPPORTED_VERSIONS, @huaweicloud_management_uri, @auth_token, @connection_options) end end |
#set_tenant(tenant) ⇒ Object
6 7 8 9 10 |
# File 'lib/fog/image/huaweicloud/v1/requests/set_tenant.rb', line 6 def set_tenant(tenant) @huaweicloud_must_reauthenticate = true @huaweicloud_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/image/huaweicloud/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/image/huaweicloud/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 |