Class: Fog::Volume::OpenStack::Real
- Inherits:
-
Object
- Object
- Fog::Volume::OpenStack::Real
show all
- Includes:
- OpenStack::Core
- Defined in:
- lib/fog/openstack/requests/volume/list_transfers.rb,
lib/fog/openstack/volume.rb,
lib/fog/openstack/requests/volume/get_quota.rb,
lib/fog/openstack/requests/volume/list_zones.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/extend_volume.rb,
lib/fog/openstack/requests/volume/list_snapshots.rb,
lib/fog/openstack/requests/volume/accept_transfer.rb,
lib/fog/openstack/requests/volume/create_transfer.rb,
lib/fog/openstack/requests/volume/delete_snapshot.rb,
lib/fog/openstack/requests/volume/delete_transfer.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/get_transfer_details.rb,
lib/fog/openstack/requests/volume/list_volumes_detailed.rb,
lib/fog/openstack/requests/volume/create_volume_snapshot.rb,
lib/fog/openstack/requests/volume/get_volume_type_details.rb,
lib/fog/openstack/requests/volume/list_snapshots_detailed.rb,
lib/fog/openstack/requests/volume/list_transfers_detailed.rb
Overview
no Mock needed, test coverage in RSpec
Instance Attribute Summary
#auth_token, #auth_token_expiration, #current_tenant, #current_user, #current_user_id, #openstack_domain_id, #openstack_domain_name, #openstack_project_domain, #openstack_project_domain_id, #openstack_user_domain, #openstack_user_domain_id
Instance Method Summary
collapse
-
#accept_transfer(transfer_id, auth_key) ⇒ Object
-
#create_transfer(volume_id, options = {}) ⇒ Object
-
#create_volume(name, description, size, options = {}) ⇒ Object
-
#create_volume_snapshot(volume_id, name, description, force = false) ⇒ Object
-
#delete_snapshot(snapshot_id) ⇒ Object
-
#delete_transfer(transfer_id) ⇒ Object
-
#delete_volume(volume_id) ⇒ Object
-
#extend_volume(volume_id, size) ⇒ Object
-
#get_quota(tenant_id) ⇒ Object
-
#get_quota_defaults(tenant_id) ⇒ Object
-
#get_snapshot_details(snapshot_id) ⇒ Object
-
#get_transfer_details(transfer_id) ⇒ Object
-
#get_volume_details(volume_id) ⇒ Object
-
#get_volume_type_details(volume_type_id) ⇒ Object
-
#initialize(options = {}) ⇒ Real
constructor
-
#list_snapshots(options = true, options_deprecated = {}) ⇒ Object
-
#list_snapshots_detailed(options = {}) ⇒ Object
-
#list_transfers(options = {}) ⇒ Object
-
#list_transfers_detailed(options = {}) ⇒ Object
-
#list_volume_types(options = {}) ⇒ Object
-
#list_volumes(options = true, options_deprecated = {}) ⇒ Object
-
#list_volumes_detailed(options = {}) ⇒ Object
-
#list_zones(options = {}) ⇒ Object
-
#request(params) ⇒ Object
-
#set_tenant(tenant) ⇒ Object
-
#update_quota(tenant_id, options = {}) ⇒ Object
#credentials, #initialize_identity, #reload
Constructor Details
#initialize(options = {}) ⇒ Real
Returns a new instance of Real.
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
# File 'lib/fog/openstack/volume.rb', line 129
def initialize(options={})
initialize_identity options
@openstack_service_type = options[:openstack_service_type] || ['volume']
@openstack_service_name = options[:openstack_service_name]
@openstack_endpoint_type = options[:openstack_endpoint_type] || 'adminURL'
@connection_options = options[:connection_options] || {}
authenticate
@persistent = options[:persistent] || false
@connection = Fog::Core::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
end
|
Instance Method Details
#accept_transfer(transfer_id, auth_key) ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/fog/openstack/requests/volume/accept_transfer.rb', line 7
def accept_transfer(transfer_id, auth_key)
data = {
'accept' => {
'auth_key' => auth_key
}
}
request(
:body => Fog::JSON.encode(data),
:expects => [200, 202],
:method => 'POST',
:path => "os-volume-transfer/#{transfer_id}/accept"
)
end
|
#create_transfer(volume_id, options = {}) ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/fog/openstack/requests/volume/create_transfer.rb', line 7
def create_transfer(volume_id, options={})
data = {
'transfer' => {
'volume_id' => volume_id
}
}
if options[:name]
data['transfer']['name'] = options[:name]
end
request(
:body => Fog::JSON.encode(data),
:expects => [200, 202],
:method => 'POST',
:path => 'os-volume-transfer'
)
end
|
#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, options={})
data = {
'volume' => {
'display_name' => name,
'display_description' => description,
'size' => size
}
}
vanilla_options = [:snapshot_id, :imageRef, :volume_type,
:source_volid, :availability_zone, :metadata]
vanilla_options.select{|o| options[o]}.each do |key|
data['volume'][key] = options[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
|
#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_transfer(transfer_id) ⇒ Object
7
8
9
10
11
12
13
|
# File 'lib/fog/openstack/requests/volume/delete_transfer.rb', line 7
def delete_transfer(transfer_id)
request(
:expects => 202,
:method => 'DELETE',
:path => "os-volume-transfer/#{transfer_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
|
#extend_volume(volume_id, size) ⇒ Object
5
6
7
8
9
10
11
12
13
|
# File 'lib/fog/openstack/requests/volume/extend_volume.rb', line 5
def extend_volume(volume_id, size)
body = { 'os-extend' => { 'new_size' => size } }
request(
:expects => 202,
:method => 'POST',
:path => "volumes/#{volume_id}/action",
:body => Fog::JSON.encode(body)
)
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_transfer_details(transfer_id) ⇒ Object
7
8
9
10
11
12
13
|
# File 'lib/fog/openstack/requests/volume/get_transfer_details.rb', line 7
def get_transfer_details(transfer_id)
request(
:expects => 200,
:method => 'GET',
:path => "os-volume-transfer/#{transfer_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(options = true, options_deprecated = {}) ⇒ Object
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/fog/openstack/requests/volume/list_snapshots.rb', line 5
def list_snapshots(options = true, options_deprecated = {})
if options.is_a?(Hash)
path = 'snapshots'
query = options
else
if options
Fog::Logger.deprecation('Calling OpenStack[:volume].list_snapshots(true) is deprecated, use .list_snapshots_detailed instead')
else
Fog::Logger.deprecation('Calling OpenStack[:volume].list_snapshots(false) is deprecated, use .list_snapshots({}) instead')
end
path = options ? 'snapshots/detail' : 'snapshots'
query = options_deprecated
end
request(
:expects => 200,
:method => 'GET',
:path => path,
:query => query
)
end
|
#list_snapshots_detailed(options = {}) ⇒ Object
5
6
7
8
9
10
11
12
|
# File 'lib/fog/openstack/requests/volume/list_snapshots_detailed.rb', line 5
def list_snapshots_detailed(options = {})
request(
:expects => 200,
:method => 'GET',
:path => 'snapshots/detail',
:query => options
)
end
|
#list_transfers(options = {}) ⇒ Object
7
8
9
10
11
12
13
14
|
# File 'lib/fog/openstack/requests/volume/list_transfers.rb', line 7
def list_transfers(options = {})
request(
:expects => 200,
:method => 'GET',
:path => 'os-volume-transfer',
:query => options
)
end
|
#list_transfers_detailed(options = {}) ⇒ Object
7
8
9
10
11
12
13
14
|
# File 'lib/fog/openstack/requests/volume/list_transfers_detailed.rb', line 7
def list_transfers_detailed(options = {})
request(
:expects => 200,
:method => 'GET',
:path => 'os-volume-transfer/detail',
:query => options
)
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(options = {})
request(
:expects => 200,
:method => 'GET',
:path => 'types',
:query => options
)
end
|
#list_volumes(options = true, options_deprecated = {}) ⇒ Object
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/fog/openstack/requests/volume/list_volumes.rb', line 5
def list_volumes(options = true, options_deprecated = {})
if options.is_a?(Hash)
path = 'volumes'
query = options
else
if options
Fog::Logger.deprecation('Calling OpenStack[:volume].list_volumes(true) is deprecated, use .list_volumes_detailed instead')
else
Fog::Logger.deprecation('Calling OpenStack[:volume].list_volumes(false) is deprecated, use .list_volumes({}) instead')
end
path = options ? 'volumes/detail' : 'volumes'
query = options_deprecated
end
request(
:expects => 200,
:method => 'GET',
:path => path,
:query => query
)
end
|
#list_volumes_detailed(options = {}) ⇒ Object
5
6
7
8
9
10
11
12
|
# File 'lib/fog/openstack/requests/volume/list_volumes_detailed.rb', line 5
def list_volumes_detailed(options = {})
request(
:expects => 200,
:method => 'GET',
:path => 'volumes/detail',
:query => options
)
end
|
#list_zones(options = {}) ⇒ Object
5
6
7
8
9
10
11
12
|
# File 'lib/fog/openstack/requests/volume/list_zones.rb', line 5
def list_zones(options = {})
request(
:expects => 200,
:method => 'GET',
:path => 'os-availability-zone.json',
:query => options
)
end
|
#request(params) ⇒ Object
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
# File 'lib/fog/openstack/volume.rb', line 144
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' @openstack_must_reauthenticate = true
authenticate
retry
else 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, options = {})
options['tenant_id'] = tenant_id
request(
:body => Fog::JSON.encode({ 'quota_set' => options }),
:expects => 200,
:method => 'PUT',
:path => "/os-quota-sets/#{tenant_id}"
)
end
|