Class: Fog::Rackspace::BlockStorage::Real
- Inherits:
-
Object
- Object
- 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
- #create_snapshot(volume_id, options = {}) ⇒ Object
- #create_volume(size, options = {}) ⇒ Object
- #delete_snapshot(snapshot_id) ⇒ Object
- #delete_volume(volume_id) ⇒ Object
- #get_snapshot(snapshot_id) ⇒ Object
- #get_volume(volume_id) ⇒ Object
- #get_volume_type(volume_type_id) ⇒ Object
-
#initialize(options = {}) ⇒ Real
constructor
A new instance of Real.
- #list_snapshots ⇒ Object
- #list_volume_types ⇒ Object
- #list_volumes ⇒ Object
- #request(params) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Real
Returns a new instance of Real.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/fog/rackspace/block_storage.rb', line 52 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] || {} endpoint = [:rackspace_endpoint] || DFW_ENDPOINT uri = URI.parse(endpoint) @host = uri.host @persistent = [:persistent] || false @path = uri.path @port = uri.port @scheme = uri.scheme authenticate @connection = Fog::Connection.new(uri.to_s, @persistent, @connection_options) end |
Instance Method Details
#create_snapshot(volume_id, options = {}) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/fog/rackspace/requests/block_storage/create_snapshot.rb', line 5 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 = {}) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/fog/rackspace/requests/block_storage/create_volume.rb', line 5 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? request( :body => Fog::JSON.encode(data), :expects => [200], :method => 'POST', :path => "volumes" ) end |
#delete_snapshot(snapshot_id) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/fog/rackspace/requests/block_storage/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/rackspace/requests/block_storage/delete_volume.rb', line 5 def delete_volume(volume_id) request( :expects => [202], :method => 'DELETE', :path => "volumes/#{volume_id}" ) end |
#get_snapshot(snapshot_id) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/fog/rackspace/requests/block_storage/get_snapshot.rb', line 5 def get_snapshot(snapshot_id) request( :expects => [200], :method => 'GET', :path => "snapshots/#{snapshot_id}" ) end |
#get_volume(volume_id) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/fog/rackspace/requests/block_storage/get_volume.rb', line 5 def get_volume(volume_id) request( :expects => [200], :method => 'GET', :path => "volumes/#{volume_id}" ) end |
#get_volume_type(volume_type_id) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/fog/rackspace/requests/block_storage/get_volume_type.rb', line 5 def get_volume_type(volume_type_id) request( :expects => [200], :method => 'GET', :path => "types/#{volume_type_id}" ) end |
#list_snapshots ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/fog/rackspace/requests/block_storage/list_snapshots.rb', line 5 def list_snapshots request( :expects => [200], :method => 'GET', :path => 'snapshots' ) end |
#list_volume_types ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/fog/rackspace/requests/block_storage/list_volume_types.rb', line 5 def list_volume_types request( :expects => [200], :method => 'GET', :path => 'types' ) end |
#list_volumes ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/fog/rackspace/requests/block_storage/list_volumes.rb', line 5 def list_volumes request( :expects => [200], :method => 'GET', :path => 'volumes' ) end |
#request(params) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/fog/rackspace/block_storage.rb', line 73 def request(params) begin response = @connection.request(params.merge!({ :headers => { 'Content-Type' => 'application/json', 'X-Auth-Token' => @auth_token }.merge!(params[:headers] || {}), :host => @host, :path => "#{@path}/#{params[:path]}" })) rescue Excon::Errors::NotFound => error raise NotFound.slurp error 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 |