class Fog::Identity::OpenStack::V3::Projects

Public Instance Methods

all(options = {}) click to toggle source
# File lib/fog/openstack/models/identity_v3/projects.rb, line 14
def all(options = {})
  if service.openstack_cache_ttl > 0
    cached_project, expires = @@cache[{:token => service.auth_token, :options => options}]
    return cached_project if cached_project && expires > Time.now
  end

  project_to_cache = load_response(service.list_projects(options), 'projects')
  if service.openstack_cache_ttl > 0
    @@cache[{:token => service.auth_token, :options => options}] = [project_to_cache,
                                                                    Time.now + service.openstack_cache_ttl]
  end
  return project_to_cache
end
auth_projects(options = {}) click to toggle source
# File lib/fog/openstack/models/identity_v3/projects.rb, line 33
def auth_projects(options = {})
  load(service.auth_projects(options).body['projects'])
end
create(attributes) click to toggle source
Calls superclass method
# File lib/fog/openstack/models/identity_v3/projects.rb, line 28
def create(attributes)
  @@cache.clear if @@cache
  super(attributes)
end
find_by_id(id, options=[]) click to toggle source
# File lib/fog/openstack/models/identity_v3/projects.rb, line 37
def find_by_id(id, options=[]) # options can include :subtree_as_ids, :subtree_as_list, :parents_as_ids, :parents_as_list
  if options.is_a? Symbol # Deal with a single option being passed on its own
    options = [options]
  end

  if service.openstack_cache_ttl > 0
    cached_project, expires = @@cache[{:token => service.auth_token, :id => id, :options => options}]
    return cached_project if cached_project && expires > Time.now
  end
  project_hash = service.get_project(id, options).body['project']
  top_project = project_from_hash(project_hash, service)
  if options.include? :subtree_as_list
    top_project.subtree.map! {|proj_hash| project_from_hash(proj_hash['project'], service)}
  end
  if options.include? :parents_as_list
    top_project.parents.map! {|proj_hash| project_from_hash(proj_hash['project'], service)}
  end

  if service.openstack_cache_ttl > 0
    @@cache[{:token => service.auth_token, :id => id, :options => options}] = [
      top_project, Time.now + service.openstack_cache_ttl]
  end
  return top_project
end

Private Instance Methods

project_from_hash(project_hash, service) click to toggle source
# File lib/fog/openstack/models/identity_v3/projects.rb, line 63
def project_from_hash(project_hash, service)
  Fog::Identity::OpenStack::V3::Project.new(project_hash.merge(:service => service))
end