Class: Fog::Identity::OpenStack::V3::Domains

Inherits:
OpenStack::Collection show all
Defined in:
lib/fog/identity/openstack/v3/models/domains.rb

Instance Attribute Summary

Attributes inherited from OpenStack::Collection

#response

Instance Method Summary collapse

Methods inherited from OpenStack::Collection

#get, #load_response, #summary

Instance Method Details

#all(options = {}) ⇒ Object


11
12
13
14
15
16
17
18
19
20
# File 'lib/fog/identity/openstack/v3/models/domains.rb', line 11

def all(options = {})
  cache = Fog::Identity::OpenStack::V3::Domain.cache
  cached_domain, expires = cache[{:token => service.auth_token, :options => options}]
  return cached_domain if cached_domain && expires > Time.now
  domain_to_cache = load_response(service.list_domains(options), 'domains')

  cache[{:token => service.auth_token, :options => options}] = domain_to_cache, Time.now + 30 # 30-second TTL
  Fog::Identity::OpenStack::V3::Domain.cache = cache
  domain_to_cache
end

#auth_domains(options = {}) ⇒ Object


26
27
28
# File 'lib/fog/identity/openstack/v3/models/domains.rb', line 26

def auth_domains(options = {})
  load(service.auth_domains(options).body['domains'])
end

#create(attributes) ⇒ Object


22
23
24
# File 'lib/fog/identity/openstack/v3/models/domains.rb', line 22

def create(attributes)
  super(attributes)
end

#destroy(id) ⇒ Object


43
44
45
46
# File 'lib/fog/identity/openstack/v3/models/domains.rb', line 43

def destroy(id)
  domain = find_by_id(id)
  domain.destroy
end

#find_by_id(id) ⇒ Object


30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/fog/identity/openstack/v3/models/domains.rb', line 30

def find_by_id(id)
  cache = Fog::Identity::OpenStack::V3::Domain.cache
  cached_domain, expires = cache[{:token => service.auth_token, :id => id}]
  return cached_domain if cached_domain && expires > Time.now
  domain_hash = service.get_domain(id).body['domain']
  domain_to_cache = Fog::Identity::OpenStack::V3::Domain.new(
    domain_hash.merge(:service => service)
  )
  cache[{:token => service.auth_token, :id => id}] = domain_to_cache, Time.now + 30 # 30-second TTL
  Fog::Identity::OpenStack::V3::Domain.cache = cache
  domain_to_cache
end