Class: Fog::Volume::OpenStack::V1::Mock
- Inherits:
-
Object
- Object
- Fog::Volume::OpenStack::V1::Mock
- Includes:
- Mock
- Defined in:
- lib/fog/openstack/volume_v1.rb,
lib/fog/openstack/requests/volume_v1/real_mock.rb,
lib/fog/openstack/requests/volume_v1/list_volumes.rb,
lib/fog/openstack/requests/volume_v1/create_volume.rb,
lib/fog/openstack/requests/volume_v1/get_volume_details.rb,
lib/fog/openstack/requests/volume_v1/get_snapshot_details.rb,
lib/fog/openstack/requests/volume_v1/list_volumes_detailed.rb,
lib/fog/openstack/requests/volume_v1/create_volume_snapshot.rb
Class Method Summary collapse
Instance Method Summary collapse
- #create_volume(name, description, size, options = {}) ⇒ Object
- #create_volume_snapshot(volume_id, name, description, force = false) ⇒ Object
- #credentials ⇒ Object
- #data ⇒ Object
- #get_snapshot_details(detailed = true) ⇒ Object
- #get_volume_details(detailed = true) ⇒ Object
-
#initialize(options = {}) ⇒ Mock
constructor
A new instance of Mock.
- #list_volumes(options = true, options_deprecated = {}) ⇒ Object
- #list_volumes_detailed(options = {}) ⇒ Object
- #reset_data ⇒ Object
Methods included from Mock
#create_volume_type, #delete_snapshot, #delete_volume, #delete_volume_type, #extend_volume, #get_quota, #get_quota_defaults, #get_quota_usage, #get_volume_type_details, #list_snapshots, #list_snapshots_detailed, #list_volume_types, #list_zones, #set_tenant, #update_quota, #update_volume_type
Constructor Details
#initialize(options = {}) ⇒ Mock
Returns a new instance of Mock.
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/fog/openstack/volume_v1.rb', line 86 def initialize(={}) @openstack_username = [:openstack_username] @openstack_tenant = [:openstack_tenant] @openstack_auth_uri = URI.parse([:openstack_auth_url]) @auth_token = Fog::Mock.random_base64(64) @auth_token_expiration = (Time.now.utc + 86400).iso8601 management_url = URI.parse([:openstack_auth_url]) management_url.port = 8776 management_url.path = '/v1' @openstack_management_url = management_url.to_s @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
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/fog/openstack/volume_v1.rb', line 68 def self.data @data ||= Hash.new do |hash, key| hash[key] = { :users => {}, :tenants => {}, :quota => { 'gigabytes' => 1000, 'volumes' => 10, 'snapshots' => 10 } } end end |
.reset ⇒ Object
82 83 84 |
# File 'lib/fog/openstack/volume_v1.rb', line 82 def self.reset @data = nil end |
Instance Method Details
#create_volume(name, description, size, options = {}) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/fog/openstack/requests/volume_v1/create_volume.rb', line 24 def create_volume(name, description, size, ={}) response = Excon::Response.new response.status = 202 response.body = { 'volume' => { 'id' => Fog::Mock.random_numbers(2), 'display_name' => name, 'display_description' => description, 'metadata' => ['metadata'] || {}, 'size' => size, 'status' => 'creating', 'snapshot_id' => [:snapshot_id] || nil, 'image_id' => [:imageRef] || nil, 'volume_type' => nil, 'availability_zone' => 'nova', 'created_at' => Time.now, 'attachments' => [] } } response end |
#create_volume_snapshot(volume_id, name, description, force = false) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/fog/openstack/requests/volume_v1/create_volume_snapshot.rb', line 24 def create_volume_snapshot(volume_id, name, description, force=false) response = Excon::Response.new response.status = 202 response.body = { "snapshot" => { "status" => "creating", "display_name" => name, "created_at" => Time.now, "display_description" => description, "volume_id" => volume_id, "id" => "5", "size" => 1 } } response end |
#credentials ⇒ Object
120 121 122 123 124 125 |
# File 'lib/fog/openstack/volume_v1.rb', line 120 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
112 113 114 |
# File 'lib/fog/openstack/volume_v1.rb', line 112 def data self.class.data[@openstack_username] end |
#get_snapshot_details(detailed = true) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/fog/openstack/requests/volume_v1/get_snapshot_details.rb', line 12 def get_snapshot_details(detailed=true) response = Excon::Response.new response.status = 200 response.body = { 'snapshot' => { 'id' => '1', 'display_name' => 'Snapshot1', 'display_description' => 'Volume1 snapshot', 'size' => 1, 'volume_id' => '1', 'status' => 'available', 'created_at' => Time.now } } response end |
#get_volume_details(detailed = true) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/fog/openstack/requests/volume_v1/get_volume_details.rb', line 12 def get_volume_details(detailed=true) response = Excon::Response.new response.status = 200 response.body = { 'volume' => { 'id' => '1', 'display_name' => Fog::Mock.random_letters(rand(8) + 5), 'display_description' => Fog::Mock.random_letters(rand(12) + 10), 'size' => 3, 'volume_type' => nil, 'snapshot_id' => '4', 'status' => 'online', 'availability_zone' => 'nova', 'created_at' => Time.now, 'attachments' => [] } } response end |
#list_volumes(options = true, options_deprecated = {}) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/fog/openstack/requests/volume_v1/list_volumes.rb', line 12 def list_volumes( = true, = {}) response = Excon::Response.new response.status = 200 self.data[:volumes] ||= [ {"status" => "available", "display_description" => "test 1 desc", "availability_zone" => "nova", "display_name" => "Volume1", "attachments" => [{}], "volume_type" => nil, "snapshot_id" => nil, "size" => 1, "id" => 1, "created_at" => Time.now, "metadata" => {}}, {"status" => "available", "display_description" => "test 2 desc", "availability_zone" => "nova", "display_name" => "Volume2", "attachments" => [{}], "volume_type" => nil, "snapshot_id" => nil, "size" => 1, "id" => 2, "created_at" => Time.now, "metadata" => {}} ] response.body = {'volumes' => self.data[:volumes]} response end |
#list_volumes_detailed(options = {}) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/fog/openstack/requests/volume_v1/list_volumes_detailed.rb', line 12 def list_volumes_detailed( = {}) response = Excon::Response.new response.status = 200 self.data[:volumes] ||= [ {"status" => "available", "display_description" => "test 1 desc", "availability_zone" => "nova", "display_name" => "Volume1", "attachments" => [{}], "volume_type" => nil, "snapshot_id" => nil, "size" => 1, "id" => 1, "created_at" => Time.now, "metadata" => {}}, {"status" => "available", "display_description" => "test 2 desc", "availability_zone" => "nova", "display_name" => "Volume2", "attachments" => [{}], "volume_type" => nil, "snapshot_id" => nil, "size" => 1, "id" => 2, "created_at" => Time.now, "metadata" => {}} ] response.body = {'volumes' => self.data[:volumes]} response end |
#reset_data ⇒ Object
116 117 118 |
# File 'lib/fog/openstack/volume_v1.rb', line 116 def reset_data self.class.data.delete(@openstack_username) end |