Class: Fog::Volume::OpenStack::Mock
- Inherits:
-
Object
- Object
- Fog::Volume::OpenStack::Mock
- Defined in:
- lib/rackspace-fog/openstack/volume.rb,
lib/rackspace-fog/openstack/requests/volume/set_tenant.rb,
lib/rackspace-fog/openstack/requests/volume/list_volumes.rb,
lib/rackspace-fog/openstack/requests/volume/create_volume.rb,
lib/rackspace-fog/openstack/requests/volume/delete_volume.rb,
lib/rackspace-fog/openstack/requests/volume/list_snapshots.rb,
lib/rackspace-fog/openstack/requests/volume/delete_snapshot.rb,
lib/rackspace-fog/openstack/requests/volume/get_volume_details.rb,
lib/rackspace-fog/openstack/requests/volume/get_snapshot_details.rb,
lib/rackspace-fog/openstack/requests/volume/create_volume_snapshot.rb
Class Method Summary collapse
Instance Method Summary collapse
- #create_volume(name, description, size, options = {}) ⇒ Object
- #credentials ⇒ Object
- #data ⇒ Object
- #delete_snapshot(snapshot_id) ⇒ Object
- #delete_volume(volume_id) ⇒ Object
- #get_snapshot_details(detailed = true) ⇒ Object
- #get_volume_details(detailed = true) ⇒ Object
-
#initialize(options = {}) ⇒ Mock
constructor
A new instance of Mock.
- #list_snapshots(detailed = true) ⇒ Object
- #list_volumes(detailed = true) ⇒ Object
- #reset_data ⇒ Object
- #set_tenant(tenant) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Mock
Returns a new instance of Mock.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/rackspace-fog/openstack/volume.rb', line 48 def initialize(={}) @openstack_username = [:openstack_username] @data ||= { :users => {} } unless @data[:users].find {|u| u['name'] == [:openstack_username]} id = Fog::Mock.random_numbers(6).to_s @data[:users][id] = { 'id' => id, 'name' => [:openstack_username], 'email' => "#{[:openstack_username]}@mock.com", 'tenantId' => Fog::Mock.random_numbers(6).to_s, 'enabled' => true } end end |
Class Method Details
.data ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/rackspace-fog/openstack/volume.rb', line 35 def self.data @data ||= Hash.new do |hash, key| hash[key] = { :users => {}, :tenants => {} } end end |
.reset ⇒ Object
44 45 46 |
# File 'lib/rackspace-fog/openstack/volume.rb', line 44 def self.reset @data = nil end |
Instance Method Details
#create_volume(name, description, size, options = {}) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/rackspace-fog/openstack/requests/volume/create_volume.rb', line 31 def create_volume(name, description, size, ={}) response = Excon::Response.new response.status = 202 response.body = { 'volume' => { 'id' => Fog::Mock.random_numbers(2), 'displayName' => name, 'displayDescription' => description, 'size' => size, 'status' => 'creating', 'snapshotId' => '4', 'volumeType' => nil, 'availabilityZone' => 'nova', 'createdAt' => Time.now, 'attchments' => [] } } response end |
#credentials ⇒ Object
72 73 74 75 76 77 |
# File 'lib/rackspace-fog/openstack/volume.rb', line 72 def credentials { :provider => 'openstack', :openstack_auth_url => @openstack_auth_uri.to_s, :openstack_auth_token => @auth_token, :openstack_management_url => @openstack_management_url } end |
#data ⇒ Object
64 65 66 |
# File 'lib/rackspace-fog/openstack/volume.rb', line 64 def data self.class.data[@openstack_username] end |
#delete_snapshot(snapshot_id) ⇒ Object
17 18 19 20 21 |
# File 'lib/rackspace-fog/openstack/requests/volume/delete_snapshot.rb', line 17 def delete_snapshot(snapshot_id) response = Excon::Response.new response.status = 204 response end |
#delete_volume(volume_id) ⇒ Object
17 18 19 20 21 |
# File 'lib/rackspace-fog/openstack/requests/volume/delete_volume.rb', line 17 def delete_volume(volume_id) response = Excon::Response.new response.status = 204 response end |
#get_snapshot_details(detailed = true) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rackspace-fog/openstack/requests/volume/get_snapshot_details.rb', line 19 def get_snapshot_details(detailed=true) response = Excon::Response.new response.status = 200 response.body = { 'snapshot' => { 'id' => '1', 'displayName' => Fog::Mock.random_letters(rand(8) + 5), 'displayDescription' => Fog::Mock.random_letters(rand(12) + 10), 'size' => 3, 'volumeId' => '4', 'status' => 'online', 'createdAt' => Time.now } } response end |
#get_volume_details(detailed = true) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/rackspace-fog/openstack/requests/volume/get_volume_details.rb', line 19 def get_volume_details(detailed=true) response = Excon::Response.new response.status = 200 response.body = { 'volume' => { 'id' => '1', 'displayName' => Fog::Mock.random_letters(rand(8) + 5), 'displayDescription' => Fog::Mock.random_letters(rand(12) + 10), 'size' => 3, 'volumeType' => nil, 'snapshotId' => '4', 'status' => 'online', 'availabilityZone' => 'nova', 'createdAt' => Time.now, 'attchments' => [] } } response end |
#list_snapshots(detailed = true) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/rackspace-fog/openstack/requests/volume/list_snapshots.rb', line 20 def list_snapshots(detailed=true) response = Excon::Response.new response.status = 200 response.body = { 'snapshots' => [get_snapshot_details.body["snapshot"]] } response end |
#list_volumes(detailed = true) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/rackspace-fog/openstack/requests/volume/list_volumes.rb', line 20 def list_volumes(detailed=true) response = Excon::Response.new response.status = 200 self.data[:volumes] ||= [ { "status" => "available", "displayDescription" => "", "availabilityZone" => "nova", "displayName" => "test 1", "attachments" => [{}], "volumeType" => nil, "snapshotId" => nil, "size" => 1, "id" => 6, "createdAt" => "2012-03-30 05:31:00.655058", "metadata" => {} }, { "status" => "available", "displayDescription" => "", "availabilityZone" => "nova", "displayName" => "test 2", "attachments" => [{}], "volumeType" => nil, "snapshotId" => nil, "size" => 1, "id" => 8, "createdAt" => "2012-03-30 16:14:55.582717", "metadata" => {} } ] response.body = { 'volumes' => self.data[:volumes] } response end |
#reset_data ⇒ Object
68 69 70 |
# File 'lib/rackspace-fog/openstack/volume.rb', line 68 def reset_data self.class.data.delete(@openstack_username) end |
#set_tenant(tenant) ⇒ Object
14 15 16 |
# File 'lib/rackspace-fog/openstack/requests/volume/set_tenant.rb', line 14 def set_tenant(tenant) true end |