Class: Fog::DNS::OpenStack::V1::Mock

Inherits:
Object
  • Object
show all
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

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(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 = 9001
  management_url.path = '/v1'
  @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

Class Method Details

.dataObject



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

.resetObject



51
52
53
# File 'lib/fog/dns/openstack/v1.rb', line 51

def self.reset
  @data = nil
end

Instance Method Details

#credentialsObject



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

#dataObject



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(_options = {})
  response = Excon::Response.new
  response.status = 200
  response.body = {'domains' => data[:domains]}
  response
end

#reset_dataObject



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, options = {})
  # stringify keys
  options = Hash[options.map { |k, v| [k.to_s, v] }]
  data[:quota_updated] = data[:quota].merge(options)

  response = Excon::Response.new
  response.status = 200
  response.body = data[:quota_updated]
  response
end