Class: Fog::DNS::OpenStack::V1::Mock
- Inherits:
-
Object
- Object
- Fog::DNS::OpenStack::V1::Mock
- Defined in:
- lib/fog/dns/openstack/v1.rb,
lib/fog/dns/openstack/v1/requests/get_quota.rb,
lib/fog/dns/openstack/v1/requests/list_domains.rb,
lib/fog/dns/openstack/v1/requests/update_quota.rb
Class Method Summary collapse
Instance Method Summary collapse
- #credentials ⇒ Object
- #data ⇒ Object
- #get_quota(_project_id) ⇒ Object
-
#initialize(options = {}) ⇒ Mock
constructor
A new instance of Mock.
- #list_domains(_options = {}) ⇒ Object
- #reset_data ⇒ Object
- #update_quota(_project_id, options = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Mock
Returns a new instance of Mock.
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 |
# File 'lib/fog/dns/openstack/v1.rb', line 55 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 = 9001 management_url.path = '/v1' @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
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/fog/dns/openstack/v1.rb', line 27 def self.data @data ||= Hash.new do |hash, key| hash[key] = { :domains => [{ "id" => "a86dba58-0043-4cc6-a1bb-69d5e86f3ca3", "name" => "example.org.", "email" => "[email protected]", "ttl" => 7200, "serial" => 1_404_757_531, "description" => "This is an example zone.", "created_at" => "2014-07-07T18:25:31.275934", "updated_at" => '' }], :quota => { "api_export_size" => 1000, "recordset_records" => 20, "domain_records" => 500, "domain_recordsets" => 500, "domains" => 100 } } end end |
.reset ⇒ Object
51 52 53 |
# File 'lib/fog/dns/openstack/v1.rb', line 51 def self.reset @data = nil end |
Instance Method Details
#credentials ⇒ Object
89 90 91 92 93 94 95 |
# File 'lib/fog/dns/openstack/v1.rb', line 89 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
81 82 83 |
# File 'lib/fog/dns/openstack/v1.rb', line 81 def data self.class.data[@openstack_username] end |
#get_quota(_project_id) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/fog/dns/openstack/v1/requests/get_quota.rb', line 16 def get_quota(_project_id) response = Excon::Response.new response.status = 200 response.body = data[:quota_updated] || data[:quota] response end |
#list_domains(_options = {}) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/fog/dns/openstack/v1/requests/list_domains.rb', line 17 def list_domains( = {}) response = Excon::Response.new response.status = 200 response.body = {'domains' => data[:domains]} response end |
#reset_data ⇒ Object
85 86 87 |
# File 'lib/fog/dns/openstack/v1.rb', line 85 def reset_data self.class.data.delete(@openstack_username) end |
#update_quota(_project_id, options = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/fog/dns/openstack/v1/requests/update_quota.rb', line 17 def update_quota(_project_id, = {}) # stringify keys = Hash[.map { |k, v| [k.to_s, v] }] data[:quota_updated] = data[:quota].merge() response = Excon::Response.new response.status = 200 response.body = data[:quota_updated] response end |