]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/keystone/lib/puppet/type/keystone_user_role.rb
Update to Kilo
[dsa-puppet.git] / 3rdparty / modules / keystone / lib / puppet / type / keystone_user_role.rb
1 # LP#1408531
2 File.expand_path('../..', File.dirname(__FILE__)).tap { |dir| $LOAD_PATH.unshift(dir) unless $LOAD_PATH.include?(dir) }
3 File.expand_path('../../../../openstacklib/lib', File.dirname(__FILE__)).tap { |dir| $LOAD_PATH.unshift(dir) unless $LOAD_PATH.include?(dir) }
4
5 require 'puppet/provider/keystone/util'
6
7 Puppet::Type.newtype(:keystone_user_role) do
8
9   desc <<-EOT
10     This is currently used to model the creation of
11     keystone users roles.
12
13     User roles are an assignment of a role to a user on
14     a certain tenant. The combination of all of these
15     attributes is unique.
16   EOT
17
18   ensurable
19
20   newparam(:name, :namevar => true) do
21   end
22
23   newproperty(:roles,  :array_matching => :all) do
24     def insync?(is)
25       return false unless is.is_a? Array
26       # order of roles does not matter
27       is.sort == self.should.sort
28     end
29   end
30
31   autorequire(:keystone_user) do
32     self[:name].rpartition('@').first
33   end
34
35   autorequire(:keystone_tenant) do
36     proj, dom = Util.split_domain(self[:name].rpartition('@').last)
37     rv = nil
38     if proj # i.e. not ::domain
39       rv = self[:name].rpartition('@').last
40     end
41     rv
42   end
43
44   autorequire(:keystone_role) do
45     self[:roles]
46   end
47
48   autorequire(:keystone_domain) do
49     rv = []
50     userdom = Util.split_domain(self[:name].rpartition('@').first)[1]
51     if userdom
52       rv << userdom
53     end
54     projectdom = Util.split_domain(self[:name].rpartition('@').last)[1]
55     if projectdom
56       rv << projectdom
57     end
58     rv
59   end
60
61   # we should not do anything until the keystone service is started
62   autorequire(:service) do
63     ['keystone']
64   end
65 end