Class: Fog::Storage::IBM::Mock
- Inherits:
-
Object
- Object
- Fog::Storage::IBM::Mock
- Defined in:
- lib/rackspace-fog/ibm/storage.rb,
lib/rackspace-fog/ibm/requests/storage/get_volume.rb,
lib/rackspace-fog/ibm/requests/storage/list_volumes.rb,
lib/rackspace-fog/ibm/requests/storage/create_volume.rb,
lib/rackspace-fog/ibm/requests/storage/delete_volume.rb,
lib/rackspace-fog/ibm/requests/storage/list_offerings.rb
Class Method Summary collapse
Instance Method Summary collapse
- #create_volume(name, offering_id, format, location_id, size) ⇒ Object
- #data ⇒ Object
- #delete_volume(volume_id) ⇒ Object
-
#format_create_volume_response_for(volume_id) ⇒ Object
The create_volume response doesn’t contain ioPrice either.
-
#format_get_volume_response_for(volume_id) ⇒ Object
get_volume response doesn’t contain instanceId.
-
#format_list_volumes_response ⇒ Object
The list_volumes response doesn’t contain ioPrice.
-
#get_volume(volume_id) ⇒ Object
For whatever reason, get_volume returns different data than an entry in list_volumes.
-
#initialize(options = {}) ⇒ Mock
constructor
A new instance of Mock.
- #list_offerings ⇒ Object
- #list_volumes ⇒ Object
-
#ready_volume(volume_id) ⇒ Object
Sets volume status to Detached if it’s not already set, and or attached.
- #reset_data ⇒ Object
- #volume_attached?(volume_id) ⇒ Boolean
- #volume_exists?(volume_id) ⇒ Boolean
-
#volume_ready?(volume_id) ⇒ Boolean
Checks if an volume is Active.
Constructor Details
#initialize(options = {}) ⇒ Mock
Returns a new instance of Mock.
72 73 74 75 76 |
# File 'lib/rackspace-fog/ibm/storage.rb', line 72 def initialize(={}) @ibm_username = [:ibm_username] @ibm_password = [:ibm_password] @data = self.class.data[@ibm_username] end |
Class Method Details
.data ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/rackspace-fog/ibm/storage.rb', line 51 def self.data @data ||= Hash.new do |hash, key| hash[key] = { :volumes => {}, } end end |
.reset ⇒ Object
59 60 61 |
# File 'lib/rackspace-fog/ibm/storage.rb', line 59 def self.reset @data = nil end |
Instance Method Details
#create_volume(name, offering_id, format, location_id, size) ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/rackspace-fog/ibm/requests/storage/create_volume.rb', line 47 def create_volume(name, offering_id, format, location_id, size) volume = Fog::IBM::Mock.create_volume(name, offering_id, format, location_id, size) self.data[:volumes][volume['id']] = volume response = Excon::Response.new response.status = 200 response.body = format_create_volume_response_for(volume['id']) response end |
#data ⇒ Object
63 64 65 |
# File 'lib/rackspace-fog/ibm/storage.rb', line 63 def data self.class.data[@ibm_username] end |
#delete_volume(volume_id) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/rackspace-fog/ibm/requests/storage/delete_volume.rb', line 27 def delete_volume(volume_id) response = Excon::Response.new if volume_exists? volume_id self.data[:volumes].delete volume_id response.status = 200 response.body = {"success"=>true} else response.status = 404 end response end |
#format_create_volume_response_for(volume_id) ⇒ Object
The create_volume response doesn’t contain ioPrice either
57 58 59 60 61 |
# File 'lib/rackspace-fog/ibm/requests/storage/create_volume.rb', line 57 def format_create_volume_response_for(volume_id) # If we aren't attached/ready, make us ready ready_volume(volume_id) unless volume_attached? volume_id self.data[:volumes][volume_id].reject { |k,v| k == 'ioPrice' } end |
#format_get_volume_response_for(volume_id) ⇒ Object
get_volume response doesn’t contain instanceId
39 40 41 42 43 |
# File 'lib/rackspace-fog/ibm/requests/storage/get_volume.rb', line 39 def format_get_volume_response_for(volume_id) # If we aren't attached/ready, make us ready ready_volume(volume_id) unless volume_attached? volume_id self.data[:volumes][volume_id].reject { |k,v| k == 'instanceId' } end |
#format_list_volumes_response ⇒ Object
The list_volumes response doesn’t contain ioPrice
46 47 48 |
# File 'lib/rackspace-fog/ibm/requests/storage/get_volume.rb', line 46 def format_list_volumes_response self.data[:volumes].values.dup.map { |volume| volume.reject { |k,v| k == 'ioPrice'} } end |
#get_volume(volume_id) ⇒ Object
For whatever reason, get_volume returns different data than an entry in list_volumes
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/rackspace-fog/ibm/requests/storage/get_volume.rb', line 27 def get_volume(volume_id) response = Excon::Response.new if volume_exists? volume_id response.status = 200 response.body = format_get_volume_response_for(volume_id) else response.status = 404 end response end |
#list_offerings ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/rackspace-fog/ibm/requests/storage/list_offerings.rb', line 40 def list_offerings response = Excon::Response.new response.status = 200 response.body = {"volumes"=> [{"name"=>"Small", "price"=> {"pricePerQuantity"=>1, "effectiveDate"=>-1, "rate"=>0.0384, "countryCode"=>"897", "unitOfMeasure"=>"UHR", "currencyCode"=>"USD"}, "location"=>"61", "id"=>"20001208", "formats"=> [{"label"=>"ext3", "id"=>"EXT3"}, {"label"=>"raw", "id"=>"RAW"}], "capacity"=>256}, {"name"=>"Small", "price"=> {"pricePerQuantity"=>1, "effectiveDate"=>-1, "rate"=>0.0384, "countryCode"=>"897", "unitOfMeasure"=>"UHR", "currencyCode"=>"USD"}, "location"=>"141", "id"=>"20001208", "formats"=> [{"label"=>"ext3", "id"=>"EXT3"}, {"label"=>"raw", "id"=>"RAW"}], "capacity"=>256}]}, response end |
#list_volumes ⇒ Object
37 38 39 40 41 42 |
# File 'lib/rackspace-fog/ibm/requests/storage/list_volumes.rb', line 37 def list_volumes response = Excon::Response.new response.status = 200 response.body = { 'volumes' => format_list_volumes_response } response end |
#ready_volume(volume_id) ⇒ Object
Sets volume status to Detached if it’s not already set, and or attached
64 65 66 67 |
# File 'lib/rackspace-fog/ibm/requests/storage/get_volume.rb', line 64 def ready_volume(volume_id) # If not ready, make ready self.data[:volumes][volume_id]['state'] = 4 end |
#reset_data ⇒ Object
67 68 69 70 |
# File 'lib/rackspace-fog/ibm/storage.rb', line 67 def reset_data self.class.data.delete(@ibm_username) @data = self.class.data[@ibm_username] end |
#volume_attached?(volume_id) ⇒ Boolean
59 60 61 |
# File 'lib/rackspace-fog/ibm/requests/storage/get_volume.rb', line 59 def volume_attached?(volume_id) self.data[:volumes][volume_id]['instanceId'] != "0" end |
#volume_exists?(volume_id) ⇒ Boolean
50 51 52 |
# File 'lib/rackspace-fog/ibm/requests/storage/get_volume.rb', line 50 def volume_exists?(volume_id) self.data[:volumes].key? volume_id end |
#volume_ready?(volume_id) ⇒ Boolean
Checks if an volume is Active
55 56 57 |
# File 'lib/rackspace-fog/ibm/requests/storage/get_volume.rb', line 55 def volume_ready?(volume_id) self.data[:volumes][volume_id]['state'] == 4 end |