Class: Fog::Volume::OpenStack::Real
- Inherits:
-
Object
- Object
- Fog::Volume::OpenStack::Real
- Defined in:
- lib/fog/openstack/volume.rb,
lib/fog/openstack/requests/volume/get_quota.rb,
lib/fog/openstack/requests/volume/set_tenant.rb,
lib/fog/openstack/requests/volume/list_volumes.rb,
lib/fog/openstack/requests/volume/update_quota.rb,
lib/fog/openstack/requests/volume/create_volume.rb,
lib/fog/openstack/requests/volume/delete_volume.rb,
lib/fog/openstack/requests/volume/list_snapshots.rb,
lib/fog/openstack/requests/volume/delete_snapshot.rb,
lib/fog/openstack/requests/volume/list_volume_types.rb,
lib/fog/openstack/requests/volume/get_quota_defaults.rb,
lib/fog/openstack/requests/volume/get_volume_details.rb,
lib/fog/openstack/requests/volume/get_snapshot_details.rb,
lib/fog/openstack/requests/volume/create_volume_snapshot.rb,
lib/fog/openstack/requests/volume/get_volume_type_details.rb
Instance Attribute Summary collapse
-
#current_tenant ⇒ Object
readonly
Returns the value of attribute current_tenant.
-
#current_user ⇒ Object
readonly
Returns the value of attribute current_user.
Instance Method Summary collapse
- #create_volume(name, description, size, options = {}) ⇒ Object
- #create_volume_snapshot(volume_id, name, description, force = false) ⇒ Object
- #credentials ⇒ Object
- #delete_snapshot(snapshot_id) ⇒ Object
- #delete_volume(volume_id) ⇒ Object
- #get_quota(tenant_id) ⇒ Object
- #get_quota_defaults(tenant_id) ⇒ Object
- #get_snapshot_details(snapshot_id) ⇒ Object
- #get_volume_details(volume_id) ⇒ Object
- #get_volume_type_details(volume_type_id) ⇒ Object
-
#initialize(options = {}) ⇒ Real
constructor
A new instance of Real.
- #list_snapshots(detailed = true) ⇒ Object
- #list_volume_types(options = {}) ⇒ Object
- #list_volumes(detailed = true, options = {}) ⇒ Object
- #reload ⇒ Object
- #request(params) ⇒ Object
- #set_tenant(tenant) ⇒ Object
- #update_quota(tenant_id, options = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Real
Returns a new instance of Real.
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/fog/openstack/volume.rb', line 108 def initialize(={}) @openstack_auth_token = [:openstack_auth_token] unless @openstack_auth_token missing_credentials = Array.new @openstack_api_key = [:openstack_api_key] @openstack_username = [:openstack_username] missing_credentials << :openstack_api_key unless @openstack_api_key missing_credentials << :openstack_username unless @openstack_username raise ArgumentError, "Missing required arguments: #{missing_credentials.join(', ')}" unless missing_credentials.empty? end @openstack_tenant = [:openstack_tenant] @openstack_auth_uri = URI.parse([:openstack_auth_url]) @openstack_management_url = [:openstack_management_url] @openstack_must_reauthenticate = false @openstack_service_type = [:openstack_service_type] || ['volume'] @openstack_service_name = [:openstack_service_name] @openstack_region = [:openstack_region] @openstack_endpoint_type = [:openstack_endpoint_type] || 'adminURL' @connection_options = [:connection_options] || {} @current_user = [:current_user] @current_tenant = [:current_tenant] authenticate @persistent = [:persistent] || false @connection = Fog::Core::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options) end |
Instance Attribute Details
#current_tenant ⇒ Object (readonly)
Returns the value of attribute current_tenant.
106 107 108 |
# File 'lib/fog/openstack/volume.rb', line 106 def current_tenant @current_tenant end |
#current_user ⇒ Object (readonly)
Returns the value of attribute current_user.
105 106 107 |
# File 'lib/fog/openstack/volume.rb', line 105 def current_user @current_user end |
Instance Method Details
#create_volume(name, description, size, options = {}) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/fog/openstack/requests/volume/create_volume.rb', line 5 def create_volume(name, description, size, ={}) data = { 'volume' => { 'display_name' => name, 'display_description' => description, 'size' => size } } = [:snapshot_id, :imageRef, :volume_type, :source_volid, :availability_zone] .select{|o| [o]}.each do |key| data['volume'][key] = [key] end request( :body => Fog::JSON.encode(data), :expects => [200, 202], :method => 'POST', :path => "volumes" ) end |
#create_volume_snapshot(volume_id, name, description, force = false) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/fog/openstack/requests/volume/create_volume_snapshot.rb', line 5 def create_volume_snapshot(volume_id, name, description, force=false) data = { 'snapshot' => { 'volume_id' => volume_id, 'display_name' => name, 'display_description' => description, 'force' => force } } request( :body => Fog::JSON.encode(data), :expects => [200, 202], :method => 'POST', :path => "snapshots" ) end |
#credentials ⇒ Object
141 142 143 144 145 146 147 148 |
# File 'lib/fog/openstack/volume.rb', line 141 def credentials { :provider => 'openstack', :openstack_auth_url => @openstack_auth_uri.to_s, :openstack_auth_token => @auth_token, :openstack_management_url => @openstack_management_url, :current_user => @current_user, :current_tenant => @current_tenant } end |
#delete_snapshot(snapshot_id) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/fog/openstack/requests/volume/delete_snapshot.rb', line 5 def delete_snapshot(snapshot_id) request( :expects => 202, :method => 'DELETE', :path => "snapshots/#{snapshot_id}" ) end |
#delete_volume(volume_id) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/fog/openstack/requests/volume/delete_volume.rb', line 5 def delete_volume(volume_id) request( :expects => 202, :method => 'DELETE', :path => "volumes/#{volume_id}" ) end |
#get_quota(tenant_id) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/fog/openstack/requests/volume/get_quota.rb', line 5 def get_quota(tenant_id) request( :expects => 200, :method => 'GET', :path => "/os-quota-sets/#{tenant_id}" ) end |
#get_quota_defaults(tenant_id) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/fog/openstack/requests/volume/get_quota_defaults.rb', line 5 def get_quota_defaults(tenant_id) request( :expects => 200, :method => 'GET', :path => "/os-quota-sets/#{tenant_id}/defaults" ) end |
#get_snapshot_details(snapshot_id) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/fog/openstack/requests/volume/get_snapshot_details.rb', line 5 def get_snapshot_details(snapshot_id) request( :expects => 200, :method => 'GET', :path => "snapshots/#{snapshot_id}" ) end |
#get_volume_details(volume_id) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/fog/openstack/requests/volume/get_volume_details.rb', line 5 def get_volume_details(volume_id) request( :expects => 200, :method => 'GET', :path => "volumes/#{volume_id}" ) end |
#get_volume_type_details(volume_type_id) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/fog/openstack/requests/volume/get_volume_type_details.rb', line 5 def get_volume_type_details(volume_type_id) request( :expects => 200, :method => 'GET', :path => "types/#{volume_type_id}" ) end |
#list_snapshots(detailed = true) ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/fog/openstack/requests/volume/list_snapshots.rb', line 5 def list_snapshots(detailed=true) path = detailed ? 'snapshots/detail' : 'snapshots' request( :expects => 200, :method => 'GET', :path => path ) end |
#list_volume_types(options = {}) ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/fog/openstack/requests/volume/list_volume_types.rb', line 5 def list_volume_types(={}) request( :expects => 200, :method => 'GET', :path => 'types', :query => ) end |
#list_volumes(detailed = true, options = {}) ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'lib/fog/openstack/requests/volume/list_volumes.rb', line 5 def list_volumes(detailed=true, ={}) path = detailed ? 'volumes/detail' : 'volumes' request( :expects => 200, :method => 'GET', :path => path, :query => ) end |
#reload ⇒ Object
150 151 152 |
# File 'lib/fog/openstack/volume.rb', line 150 def reload @connection.reset end |
#request(params) ⇒ Object
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/fog/openstack/volume.rb', line 154 def request(params) begin response = @connection.request(params.merge({ :headers => { 'Content-Type' => 'application/json', 'Accept' => 'application/json', 'X-Auth-Token' => @auth_token }.merge!(params[:headers] || {}), :path => "#{@path}/#{params[:path]}"#, })) rescue Excon::Errors::Unauthorized => error if error.response.body != 'Bad username or password' # token expiration @openstack_must_reauthenticate = true authenticate retry else # bad credentials raise error end rescue Excon::Errors::HTTPStatusError => error raise case error when Excon::Errors::NotFound Fog::Compute::OpenStack::NotFound.slurp(error) else error end end unless response.body.empty? response.body = Fog::JSON.decode(response.body) end response end |
#set_tenant(tenant) ⇒ Object
5 6 7 8 9 |
# File 'lib/fog/openstack/requests/volume/set_tenant.rb', line 5 def set_tenant(tenant) @openstack_must_reauthenticate = true @openstack_tenant = tenant.to_s authenticate end |
#update_quota(tenant_id, options = {}) ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'lib/fog/openstack/requests/volume/update_quota.rb', line 5 def update_quota(tenant_id, = {}) ['tenant_id'] = tenant_id request( :body => Fog::JSON.encode({ 'quota_set' => }), :expects => 200, :method => 'PUT', :path => "/os-quota-sets/#{tenant_id}" ) end |