Class: Fog::Rackspace::BlockStorage::Real
- Defined in:
- lib/fog/rackspace/block_storage.rb,
lib/fog/rackspace/requests/block_storage/get_volume.rb,
lib/fog/rackspace/requests/block_storage/get_snapshot.rb,
lib/fog/rackspace/requests/block_storage/list_volumes.rb,
lib/fog/rackspace/requests/block_storage/create_volume.rb,
lib/fog/rackspace/requests/block_storage/delete_volume.rb,
lib/fog/rackspace/requests/block_storage/list_snapshots.rb,
lib/fog/rackspace/requests/block_storage/create_snapshot.rb,
lib/fog/rackspace/requests/block_storage/delete_snapshot.rb,
lib/fog/rackspace/requests/block_storage/get_volume_type.rb,
lib/fog/rackspace/requests/block_storage/list_volume_types.rb
Instance Method Summary collapse
- #authenticate ⇒ Object
-
#create_snapshot(volume_id, options = {}) ⇒ Excon::Response
Create a snapshot from a volume.
-
#create_volume(size, options = {}) ⇒ Excon::Response
Create volume.
-
#delete_snapshot(snapshot_id) ⇒ Excon::Response
Delete snapshot.
-
#delete_volume(volume_id) ⇒ Excon::Response
Delete volume.
- #endpoint_uri(service_endpoint_url = nil) ⇒ Object
-
#get_snapshot(snapshot_id) ⇒ Excon::Response
Retrieves snapshot detail.
-
#get_volume(volume_id) ⇒ Excon::Response
Retrieves volume detail.
-
#get_volume_type(volume_type_id) ⇒ Excon::Response
Retrieves volume type detail.
-
#initialize(options = {}) ⇒ Real
constructor
A new instance of Real.
-
#list_snapshots ⇒ Excon::Response
Retrieves list of snapshots.
-
#list_volume_types ⇒ Excon::Response
Retrieves list of volume types.
-
#list_volumes ⇒ Excon::Response
Retrieves list of volumes.
- #region ⇒ Object
- #request(params) ⇒ Object
- #service_name ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Real
Returns a new instance of Real.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/fog/rackspace/block_storage.rb', line 74 def initialize( = {}) @rackspace_api_key = [:rackspace_api_key] @rackspace_username = [:rackspace_username] @rackspace_auth_url = [:rackspace_auth_url] @rackspace_must_reauthenticate = false @connection_options = [:connection_options] || {} setup_custom_endpoint() authenticate deprecation_warnings() @persistent = [:persistent] || false @connection = Fog::Connection.new(endpoint_uri.to_s, @persistent, @connection_options) end |
Instance Method Details
#authenticate ⇒ Object
116 117 118 119 120 121 122 123 124 |
# File 'lib/fog/rackspace/block_storage.rb', line 116 def authenticate = { :rackspace_api_key => @rackspace_api_key, :rackspace_username => @rackspace_username, :rackspace_auth_url => @rackspace_auth_url, :connection_options => @connection_options } super() end |
#create_snapshot(volume_id, options = {}) ⇒ Excon::Response
All writes to the volume should be flushed before creating the snapshot, either by un-mounting any file systems on the volume or by detaching the volume.
Create a snapshot from a volume
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/fog/rackspace/requests/block_storage/create_snapshot.rb', line 29 def create_snapshot(volume_id, = {}) data = { 'snapshot' => { 'volume_id' => volume_id } } data['snapshot']['display_name'] = [:display_name] unless [:display_name].nil? data['snapshot']['display_description'] = [:display_description] unless [:display_description].nil? data['snapshot']['force'] = [:force] unless [:force].nil? request( :body => Fog::JSON.encode(data), :expects => [200], :method => 'POST', :path => "snapshots" ) end |
#create_volume(size, options = {}) ⇒ Excon::Response
Create volume
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/fog/rackspace/requests/block_storage/create_volume.rb', line 33 def create_volume(size, = {}) data = { 'volume' => { 'size' => size } } data['volume']['display_name'] = [:display_name] unless [:display_name].nil? data['volume']['display_description'] = [:display_description] unless [:display_description].nil? data['volume']['volume_type'] = [:volume_type] unless [:volume_type].nil? data['volume']['availability_zone'] = [:availability_zone] unless [:availability_zone].nil? data['volume']['snapshot_id'] = [:snapshot_id] unless [:snapshot_id].nil? request( :body => Fog::JSON.encode(data), :expects => [200], :method => 'POST', :path => "volumes" ) end |
#delete_snapshot(snapshot_id) ⇒ Excon::Response
Delete snapshot
15 16 17 18 19 20 21 |
# File 'lib/fog/rackspace/requests/block_storage/delete_snapshot.rb', line 15 def delete_snapshot(snapshot_id) request( :expects => [202], :method => 'DELETE', :path => "snapshots/#{snapshot_id}" ) end |
#delete_volume(volume_id) ⇒ Excon::Response
You cannot delete a volume until all of its dependent snaphosts have been deleted.
Delete volume
16 17 18 19 20 21 22 |
# File 'lib/fog/rackspace/requests/block_storage/delete_volume.rb', line 16 def delete_volume(volume_id) request( :expects => [202], :method => 'DELETE', :path => "volumes/#{volume_id}" ) end |
#endpoint_uri(service_endpoint_url = nil) ⇒ Object
134 135 136 |
# File 'lib/fog/rackspace/block_storage.rb', line 134 def endpoint_uri(service_endpoint_url=nil) @uri = super(@rackspace_endpoint || service_endpoint_url, :rackspace_block_storage_url) end |
#get_snapshot(snapshot_id) ⇒ Excon::Response
Retrieves snapshot detail
25 26 27 28 29 30 31 |
# File 'lib/fog/rackspace/requests/block_storage/get_snapshot.rb', line 25 def get_snapshot(snapshot_id) request( :expects => [200], :method => 'GET', :path => "snapshots/#{snapshot_id}" ) end |
#get_volume(volume_id) ⇒ Excon::Response
Retrieves volume detail
29 30 31 32 33 34 35 |
# File 'lib/fog/rackspace/requests/block_storage/get_volume.rb', line 29 def get_volume(volume_id) request( :expects => [200], :method => 'GET', :path => "volumes/#{volume_id}" ) end |
#get_volume_type(volume_type_id) ⇒ Excon::Response
Retrieves volume type detail
19 20 21 22 23 24 25 |
# File 'lib/fog/rackspace/requests/block_storage/get_volume_type.rb', line 19 def get_volume_type(volume_type_id) request( :expects => [200], :method => 'GET', :path => "types/#{volume_type_id}" ) end |
#list_snapshots ⇒ Excon::Response
Retrieves list of snapshots
22 23 24 25 26 27 28 |
# File 'lib/fog/rackspace/requests/block_storage/list_snapshots.rb', line 22 def list_snapshots request( :expects => [200], :method => 'GET', :path => 'snapshots' ) end |
#list_volume_types ⇒ Excon::Response
Retrieves list of volume types
18 19 20 21 22 23 24 |
# File 'lib/fog/rackspace/requests/block_storage/list_volume_types.rb', line 18 def list_volume_types request( :expects => [200], :method => 'GET', :path => 'types' ) end |
#list_volumes ⇒ Excon::Response
Retrieves list of volumes
26 27 28 29 30 31 32 |
# File 'lib/fog/rackspace/requests/block_storage/list_volumes.rb', line 26 def list_volumes request( :expects => [200], :method => 'GET', :path => 'volumes' ) end |
#region ⇒ Object
130 131 132 |
# File 'lib/fog/rackspace/block_storage.rb', line 130 def region @rackspace_region end |
#request(params) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/fog/rackspace/block_storage.rb', line 90 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] || {}), :host => endpoint_uri.host, :path => "#{endpoint_uri.path}/#{params[:path]}" })) rescue Excon::Errors::NotFound => error raise NotFound.slurp(error, region) rescue Excon::Errors::BadRequest => error raise BadRequest.slurp error rescue Excon::Errors::InternalServerError => error raise InternalServerError.slurp error rescue Excon::Errors::HTTPStatusError => error raise ServiceError.slurp error end unless response.body.empty? response.body = Fog::JSON.decode(response.body) end response end |
#service_name ⇒ Object
126 127 128 |
# File 'lib/fog/rackspace/block_storage.rb', line 126 def service_name :cloudBlockStorage end |