
This patch implements these parts of the blueprint: 1) Adds some utility code for domain handling. Puppet code may need to specify resource titles as "name::domain" e.g. "admin::admin_domain". The function split_domain is used to split a name in this format into its ['name', 'domain'] components as an array. Usually providers will not need to use this, they will use the name_and_domain method in the keystone.rb provider. This is resource aware and will try many different ways to get a domain to use for the provider: resource[:domain], then the domain part of 'name::domain' name/title value. If keystone.conf is available, it will use [identity] default_domain_id as the default domain id, and look up the domain name using the 'domain list' operation to create a mapping. If all else fails, the domain name will be 'Default' which is the "default" default domain name used by Keystone. 2) Adds the method domain_name_from_id - the providers and other code will need to map from the domain id to the name, and this method provides that mapping. Implements: blueprint api-v3-support Change-Id: Ifb8171b78904257f8112e1485d5255f0d0f5aca8 Depends-On: Icafc4cb8ed000fd9d3ed6ffde2afe1a1250d90af
26 lines
833 B
Ruby
26 lines
833 B
Ruby
module Util
|
|
# Splits the rightmost part of a string using '::' as delimiter
|
|
# Returns an array of both parts or nil if either is empty.
|
|
# An empty rightmost part is ignored and converted as 'string::' => 'string'
|
|
#
|
|
# Examples:
|
|
# "foo" -> ["foo", nil]
|
|
# "foo::" -> ["foo", nil]
|
|
# "foo::bar" -> ["foo", "bar"]
|
|
# "foo::bar::" -> ["foo", "bar"]
|
|
# "::foo" -> [nil, "foo"]
|
|
# "::foo::" -> [nil, "foo"]
|
|
# "foo::bar::baz" -> ["foo::bar", "baz"]
|
|
# "foo::bar::baz::" -> ["foo::bar", "baz"]
|
|
#
|
|
def self.split_domain(str)
|
|
left, right = nil, nil
|
|
unless str.nil?
|
|
left, delimiter, right = str.gsub(/::$/, '').rpartition('::')
|
|
left, right = right, nil if delimiter.empty?
|
|
left = nil if left.empty?
|
|
end
|
|
return [left, right]
|
|
end
|
|
end
|