class Fog::SharedFileSystem::OpenStack::Mock
rubocop:disable LineLength, Metrics/MethodLength, Metrics/ClassLength, Metrics/AbcSize
Public Class Methods
data()
click to toggle source
# 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
new(options = {})
click to toggle source
# File lib/fog/shared_file_system/openstack.rb, line 201 def initialize(options = {}) @openstack_username = options[:openstack_username] @openstack_tenant = options[:openstack_tenant] @openstack_auth_uri = URI.parse(options[:openstack_auth_url]) @auth_token = Fog::Mock.random_base64(64) @auth_token_expiration = (Time.now.utc + 86400).iso8601 management_url = URI.parse(options[: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'] == options[:openstack_username] } id = Fog::Mock.random_numbers(6).to_s @data[:users][id] = { 'id' => id, 'name' => options[:openstack_username], 'email' => "#{options[:openstack_username]}@mock.com", 'tenantId' => Fog::Mock.random_numbers(6).to_s, 'enabled' => true } end end
reset()
click to toggle source
# File lib/fog/shared_file_system/openstack.rb, line 197 def self.reset @data = nil end
Public Instance Methods
create_snapshot(share_id, options = {})
click to toggle source
# File lib/fog/shared_file_system/openstack/requests/create_snapshot.rb, line 28 def create_snapshot(share_id, options = {}) # stringify keys options = Hash[options.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(options)} response end
credentials()
click to toggle source
# 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()
click to toggle source
# File lib/fog/shared_file_system/openstack.rb, line 227 def data self.class.data[@openstack_username] end
delete_snapshot(id)
click to toggle source
# 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_snapshot(id)
click to toggle source
# 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_snapshots(_options = {})
click to toggle source
# File lib/fog/shared_file_system/openstack/requests/list_snapshots.rb, line 16 def list_snapshots(_options = {}) response = Excon::Response.new response.status = 200 response.body = {'snapshots' => data[:snapshots]} response end
list_snapshots_detail(_options = {})
click to toggle source
# File lib/fog/shared_file_system/openstack/requests/list_snapshots_detail.rb, line 16 def list_snapshots_detail(_options = {}) response = Excon::Response.new response.status = 200 response.body = {'snapshots' => data[:snapshots_detail]} response end
reset_data()
click to toggle source
# File lib/fog/shared_file_system/openstack.rb, line 231 def reset_data self.class.data.delete(@openstack_username) end
update_snapshot(id, options = {})
click to toggle source
# File lib/fog/shared_file_system/openstack/requests/update_snapshot.rb, line 16 def update_snapshot(id, options = {}) # stringify keys options = Hash[options.map { |k, v| [k.to_s, v] }] data[:snapshot_updated] = data[:snapshots_detail].first.merge(options) data[:snapshot_updated]['id'] = id response = Excon::Response.new response.status = 200 response.body = {'snapshot' => data[:snapshot_updated]} response end
Private Instance Methods
update_data(id, options)
click to toggle source
# File lib/fog/shared_file_system/openstack/requests/update_share.rb, line 30 def update_data(id, options) data[:share_updated] = data[:shares_detailed].first.merge(options) data[:share_updated]['id'] = id data[:share_updated]['status'] = "PENDING" data[:share_updated]['links']['self'] = "https://127.0.0.1:8786/v2/shares/#{id}" end