Class: Fog::SharedFileSystem::OpenStack::Mock
- Inherits:
-
Object
- Object
- Fog::SharedFileSystem::OpenStack::Mock
- Defined in:
- lib/fog/shared_file_system/openstack.rb,
lib/fog/shared_file_system/openstack/requests/get_share.rb,
lib/fog/shared_file_system/openstack/requests/list_shares.rb,
lib/fog/shared_file_system/openstack/requests/create_share.rb,
lib/fog/shared_file_system/openstack/requests/delete_share.rb,
lib/fog/shared_file_system/openstack/requests/get_snapshot.rb,
lib/fog/shared_file_system/openstack/requests/update_share.rb,
lib/fog/shared_file_system/openstack/requests/list_snapshots.rb,
lib/fog/shared_file_system/openstack/requests/create_snapshot.rb,
lib/fog/shared_file_system/openstack/requests/delete_snapshot.rb,
lib/fog/shared_file_system/openstack/requests/update_snapshot.rb,
lib/fog/shared_file_system/openstack/requests/get_share_network.rb,
lib/fog/shared_file_system/openstack/requests/list_shares_detail.rb,
lib/fog/shared_file_system/openstack/requests/list_share_networks.rb,
lib/fog/shared_file_system/openstack/requests/create_share_network.rb,
lib/fog/shared_file_system/openstack/requests/delete_share_network.rb,
lib/fog/shared_file_system/openstack/requests/update_share_network.rb,
lib/fog/shared_file_system/openstack/requests/list_snapshots_detail.rb,
lib/fog/shared_file_system/openstack/requests/list_share_networks_detail.rb
Overview
rubocop:disable LineLength, Metrics/MethodLength, Metrics/ClassLength, Metrics/AbcSize
Class Method Summary collapse
Instance Method Summary collapse
- #create_share(protocol, size, options = {}) ⇒ Object
- #create_share_network(options = {}) ⇒ Object
- #create_snapshot(share_id, options = {}) ⇒ Object
- #credentials ⇒ Object
- #data ⇒ Object
- #delete_share(id) ⇒ Object
- #delete_share_network(id) ⇒ Object
- #delete_snapshot(id) ⇒ Object
- #get_share(id) ⇒ Object
- #get_share_network(id) ⇒ Object
- #get_snapshot(id) ⇒ Object
-
#initialize(options = {}) ⇒ Mock
constructor
A new instance of Mock.
- #list_share_networks(_options = {}) ⇒ Object
- #list_share_networks_detail(_options = {}) ⇒ Object
- #list_shares(_options = {}) ⇒ Object
- #list_shares_detail(_options = {}) ⇒ Object
- #list_snapshots(_options = {}) ⇒ Object
- #list_snapshots_detail(_options = {}) ⇒ Object
- #reset_data ⇒ Object
- #update_share(id, options = {}) ⇒ Object
- #update_share_network(id, options = {}) ⇒ Object
- #update_snapshot(id, options = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Mock
Returns a new instance of Mock.
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
# File 'lib/fog/shared_file_system/openstack.rb', line 201 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 = 8786 management_url.path = '/v2' @openstack_management_url = management_url.to_s @data ||= {:users => {}} unless @data[:users].detect { |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
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 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 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/fog/shared_file_system/openstack.rb', line 53 def self.data @data ||= Hash.new do |hash, key| hash[key] = { :shares => [ { "id" => "d94a8548-2079-4be0-b21c-0a887acd31ca", "links" => [ { "href" => "http://172.18.198.54:8786/v1/16e1ab15c35a457e9c2b2aa189f544e1/shares/d94a8548-2079-4be0-b21c-0a887acd31ca", "rel" => "self" }, { "href" => "http://172.18.198.54:8786/16e1ab15c35a457e9c2b2aa189f544e1/shares/d94a8548-2079-4be0-b21c-0a887acd31ca", "rel" => "bookmark" } ], "name" => "My_share" }, { "id" => "406ea93b-32e9-4907-a117-148b3945749f", "links" => [ { "href" => "http://172.18.198.54:8786/v1/16e1ab15c35a457e9c2b2aa189f544e1/shares/406ea93b-32e9-4907-a117-148b3945749f", "rel" => "self" }, { "href" => "http://172.18.198.54:8786/16e1ab15c35a457e9c2b2aa189f544e1/shares/406ea93b-32e9-4907-a117-148b3945749f", "rel" => "bookmark" } ], "name" => "Share1" } ], :shares_detail => [ { "links" => [ { "href" => "http://172.18.198.54:8786/v2/16e1ab15c35a457e9c2b2aa189f544e1/shares/f45cc5b2-d1bb-4a3e-ba5b-5c4125613adc", "rel" => "self" }, { "href" => "http://172.18.198.54:8786/16e1ab15c35a457e9c2b2aa189f544e1/shares/f45cc5b2-d1bb-4a3e-ba5b-5c4125613adc", "rel" => "bookmark" } ], "availability_zone" => "nova", "share_network_id" => "f9b2e754-ac01-4466-86e1-5c569424754e", "export_locations" => [], "share_server_id" => "87d8943a-f5da-47a4-b2f2-ddfa6794aa82", "snapshot_id" => '', "id" => "f45cc5b2-d1bb-4a3e-ba5b-5c4125613adc", "size" => 1, "share_type" => "25747776-08e5-494f-ab40-a64b9d20d8f7", "share_type_name" => "default", "export_location" => '', "consistency_group_id" => "9397c191-8427-4661-a2e8-b23820dc01d4", "project_id" => "16e1ab15c35a457e9c2b2aa189f544e1", "metadata" => {}, "status" => "available", "access_rules_status" => "active", "description" => "There is a share description.", "host" => "manila2@generic1#GENERIC1", "task_state" => '', "is_public" => 'true', "snapshot_support" => 'true', "name" => "my_share4", "has_replicas" => 'false', "replication_type" => '', "created_at" => "2015-09-16T18:19:50.000000", "share_proto" => "NFS", "volume_type" => "default", "source_cgsnapshot_member_id" => '' } ], :share_networks => [ { "id" => "32763294-e3d4-456a-998d-60047677c2fb", "name" => "net_my1" }, { "id" => "713df749-aac0-4a54-af52-10f6c991e80c", "name" => "net_my" } ], :share_networks_detail => [ { "name" => "net_my1", "segmentation_id" => '', "created_at" => "2015-09-04T14:57:13.000000", "neutron_subnet_id" => "53482b62-2c84-4a53-b6ab-30d9d9800d06", "updated_at" => '', "id" => "32763294-e3d4-456a-998d-60047677c2fb", "neutron_net_id" => "998b42ee-2cee-4d36-8b95-67b5ca1f2109", "ip_version" => '', "nova_net_id" => '', "cidr" => '', "project_id" => "16e1ab15c35a457e9c2b2aa189f544e1", "network_type" => '', "description" => "descr" } ], :snapshots => [ { "id" => "086a1aa6-c425-4ecd-9612-391a3b1b9375", "links" => [ { "href" => "http://172.18.198.54:8786/v1/16e1ab15c35a457e9c2b2aa189f544e1/snapshots/086a1aa6-c425-4ecd-9612-391a3b1b9375", "rel" => "self" }, { "href" => "http://172.18.198.54:8786/16e1ab15c35a457e9c2b2aa189f544e1/snapshots/086a1aa6-c425-4ecd-9612-391a3b1b9375", "rel" => "bookmark" } ], "name" => "snapshot_My_share" } ], :snapshots_detail => [ { "status" => "available", "share_id" => "d94a8548-2079-4be0-b21c-0a887acd31ca", "name" => "snapshot_My_share", "links" => [ { "href" => "http://172.18.198.54:8786/v1/16e1ab15c35a457e9c2b2aa189f544e1/snapshots/086a1aa6-c425-4ecd-9612-391a3b1b9375", "rel" => "self" }, { "href" => "http://172.18.198.54:8786/16e1ab15c35a457e9c2b2aa189f544e1/snapshots/086a1aa6-c425-4ecd-9612-391a3b1b9375", "rel" => "bookmark" } ], "created_at" => "2015-09-07T11:55:09.000000", "description" => "Here is a snapshot of share My_share", "share_proto" => "NFS", "share_size" => 1, "id" => "086a1aa6-c425-4ecd-9612-391a3b1b9375", "size" => 1 } ] } end end |
.reset ⇒ Object
197 198 199 |
# File 'lib/fog/shared_file_system/openstack.rb', line 197 def self.reset @data = nil end |
Instance Method Details
#create_share(protocol, size, options = {}) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/fog/shared_file_system/openstack/requests/create_share.rb', line 30 def create_share(protocol, size, = {}) # stringify keys = Hash[.map { |k, v| [k.to_s, v] }] response = Excon::Response.new response.status = 200 share = data[:shares_detail].first.dup share['share_proto'] = protocol share['size'] = size share['status'] = 'creating' response.body = {'share' => share.merge()} response end |
#create_share_network(options = {}) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/fog/shared_file_system/openstack/requests/create_share_network.rb', line 26 def create_share_network( = {}) # stringify keys = Hash[.map { |k, v| [k.to_s, v] }] response = Excon::Response.new response.status = 200 share_net = data[:share_networks_detail].first.dup response.body = {'share_networks' => share_net.merge()} response end |
#create_snapshot(share_id, options = {}) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/fog/shared_file_system/openstack/requests/create_snapshot.rb', line 28 def create_snapshot(share_id, = {}) # stringify keys = Hash[.map { |k, v| [k.to_s, v] }] response = Excon::Response.new response.status = 202 snapshot = data[:snapshots_detail].first.dup snapshot['share_id'] = share_id snapshot['status'] = 'creating' response.body = {'snapshot' => snapshot.merge()} response end |
#credentials ⇒ Object
235 236 237 238 239 240 241 |
# File 'lib/fog/shared_file_system/openstack.rb', line 235 def credentials {:provider => 'openstack', :openstack_auth_url => @openstack_auth_uri.to_s, :openstack_auth_token => @auth_token, :openstack_region => @openstack_region, :openstack_management_url => @openstack_management_url} end |
#data ⇒ Object
227 228 229 |
# File 'lib/fog/shared_file_system/openstack.rb', line 227 def data self.class.data[@openstack_username] end |
#delete_share(id) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/fog/shared_file_system/openstack/requests/delete_share.rb', line 15 def delete_share(id) response = Excon::Response.new response.status = 202 share = data[:share_updated] || data[:shares_detail].first.dup share['id'] = id share['links']['self'] = "https://127.0.0.1:8786/v2/shares/#{id}" response.body = {'share' => share} response end |
#delete_share_network(id) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/fog/shared_file_system/openstack/requests/delete_share_network.rb', line 15 def delete_share_network(id) response = Excon::Response.new response.status = 202 share_net = data[:share_net_updated] || data[:share_networks_detail].first.dup share_net['id'] = id response.body = {'share_network' => share_net} response end |
#delete_snapshot(id) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/fog/shared_file_system/openstack/requests/delete_snapshot.rb', line 15 def delete_snapshot(id) response = Excon::Response.new response.status = 202 snapshot = data[:snapshot_updated] || data[:snapshots_detail].first.dup snapshot['id'] = id snapshot['status'] = 'deleting' snapshot['links']['self'] = "https://127.0.0.1:8786/v2/snapshots/#{id}" response.body = {'snapshot' => snapshot} response end |
#get_share(id) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/fog/shared_file_system/openstack/requests/get_share.rb', line 15 def get_share(id) response = Excon::Response.new response.status = 200 share = data[:share_updated] || data[:shares_detail].first share['id'] = id response.body = share response end |
#get_share_network(id) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/fog/shared_file_system/openstack/requests/get_share_network.rb', line 15 def get_share_network(id) response = Excon::Response.new response.status = 200 share_net = data[:share_network_updated] || data[:share_networks].first share_net['id'] = id response.body = {'share_network' => share_net} response end |
#get_snapshot(id) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/fog/shared_file_system/openstack/requests/get_snapshot.rb', line 15 def get_snapshot(id) response = Excon::Response.new response.status = 200 snapshot = data[:snapshot_updated] || data[:snapshots_detail].first snapshot['id'] = id response.body = snapshot response end |
#list_share_networks(_options = {}) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/fog/shared_file_system/openstack/requests/list_share_networks.rb', line 16 def list_share_networks( = {}) response = Excon::Response.new response.status = 200 response.body = {'share_networks' => data[:share_networks]} response end |
#list_share_networks_detail(_options = {}) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/fog/shared_file_system/openstack/requests/list_share_networks_detail.rb', line 16 def list_share_networks_detail( = {}) response = Excon::Response.new response.status = 200 response.body = {'share_networks' => data[:share_networks_detail]} response end |
#list_shares(_options = {}) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/fog/shared_file_system/openstack/requests/list_shares.rb', line 16 def list_shares( = {}) response = Excon::Response.new response.status = 200 response.body = {'shares' => data[:shares]} response end |
#list_shares_detail(_options = {}) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/fog/shared_file_system/openstack/requests/list_shares_detail.rb', line 16 def list_shares_detail( = {}) response = Excon::Response.new response.status = 200 response.body = {'shares' => data[:shares_detail]} response end |
#list_snapshots(_options = {}) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/fog/shared_file_system/openstack/requests/list_snapshots.rb', line 16 def list_snapshots( = {}) response = Excon::Response.new response.status = 200 response.body = {'snapshots' => data[:snapshots]} response end |
#list_snapshots_detail(_options = {}) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/fog/shared_file_system/openstack/requests/list_snapshots_detail.rb', line 16 def list_snapshots_detail( = {}) response = Excon::Response.new response.status = 200 response.body = {'snapshots' => data[:snapshots_detail]} response end |
#reset_data ⇒ Object
231 232 233 |
# File 'lib/fog/shared_file_system/openstack.rb', line 231 def reset_data self.class.data.delete(@openstack_username) end |
#update_share(id, options = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/fog/shared_file_system/openstack/requests/update_share.rb', line 16 def update_share(id, = {}) # stringify keys = Hash[.map { |k, v| [k.to_s, v] }] update_data(id, ) response = Excon::Response.new response.status = 200 response.body = {'share' => data[:share_updated]} response end |
#update_share_network(id, options = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/fog/shared_file_system/openstack/requests/update_share_network.rb', line 16 def update_share_network(id, = {}) # stringify keys = Hash[.map { |k, v| [k.to_s, v] }] data[:share_net_updated] = data[:share_networks_detail].first.merge() data[:share_net_updated]['id'] = id response = Excon::Response.new response.status = 200 response.body = {'share_network' => data[:share_net_updated]} response end |
#update_snapshot(id, options = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/fog/shared_file_system/openstack/requests/update_snapshot.rb', line 16 def update_snapshot(id, = {}) # stringify keys = Hash[.map { |k, v| [k.to_s, v] }] data[:snapshot_updated] = data[:snapshots_detail].first.merge() data[:snapshot_updated]['id'] = id response = Excon::Response.new response.status = 200 response.body = {'snapshot' => data[:snapshot_updated]} response end |