lib/kaname/resource.rb in kaname-0.5.0 vs lib/kaname/resource.rb in kaname-0.5.1
- old
+ new
@@ -2,14 +2,25 @@
module Kaname
class Resource
class << self
def yaml(filename = 'keystone.yml')
- @_yaml = if File.exists?(filename)
- YAML.load_file(filename)
- else
- nil
- end
+ if File.exists?(filename)
+ @_yaml ||= expand_all_tenants(YAML.load_file(filename))
+ end
+ end
+
+ private
+
+ def expand_all_tenants _yaml
+ list_tenants = Kaname::Adapter::ReadOnly.new.list_tenants
+
+ _yaml.each do |username, config|
+ next unless config['all_tenants']
+ tenants = list_tenants.map{|tenant| [tenant.name, config['all_tenants']]}
+ config['tenants'] = Hash[*tenants.flatten].merge(config['tenants'] || {})
+ config.delete('all_tenants')
+ end
end
end
end
end