]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/keystone/lib/puppet/provider/keystone_endpoint/openstack.rb
try with modules from master
[dsa-puppet.git] / 3rdparty / modules / keystone / lib / puppet / provider / keystone_endpoint / openstack.rb
1 require 'puppet/provider/keystone'
2
3 Puppet::Type.type(:keystone_endpoint).provide(
4   :openstack,
5   :parent => Puppet::Provider::Keystone
6 ) do
7
8   desc "Provider to manage keystone endpoints."
9
10   @credentials = Puppet::Provider::Openstack::CredentialsV2_0.new
11
12   def initialize(value={})
13     super(value)
14     @property_flush = {}
15   end
16
17   def create
18     properties = []
19     # The region property is just ignored. We should fix this in kilo.
20     region, name = resource[:name].split('/')
21     properties << name
22     properties << '--region'
23     properties << region
24     if resource[:public_url]
25       properties << '--publicurl'
26       properties << resource[:public_url]
27     end
28     if resource[:internal_url]
29       properties << '--internalurl'
30       properties << resource[:internal_url]
31     end
32     if resource[:admin_url]
33       properties << '--adminurl'
34       properties << resource[:admin_url]
35     end
36      self.class.request('endpoint', 'create', properties)
37      @property_hash[:ensure] = :present
38   end
39
40   def destroy
41     self.class.request('endpoint', 'delete', @property_hash[:id])
42     @property_hash.clear
43   end
44
45   def exists?
46     @property_hash[:ensure] == :present
47   end
48
49   def region
50     @property_hash[:region]
51   end
52
53   def public_url=(value)
54     @property_flush[:public_url] = value
55   end
56
57   def public_url
58     @property_hash[:public_url]
59   end
60
61   def internal_url=(value)
62     @property_flush[:internal_url] = value
63   end
64
65   def internal_url
66     @property_hash[:internal_url]
67   end
68
69   def admin_url=(value)
70     @property_flush[:admin_url] = value
71   end
72
73   def admin_url
74     @property_hash[:admin_url]
75   end
76
77   def id
78     @property_hash[:id]
79   end
80
81   def self.instances
82     list = request('endpoint', 'list', '--long')
83     list.collect do |endpoint|
84       new(
85         :name         => "#{endpoint[:region]}/#{endpoint[:service_name]}",
86         :ensure       => :present,
87         :id           => endpoint[:id],
88         :region       => endpoint[:region],
89         :public_url   => endpoint[:publicurl],
90         :internal_url => endpoint[:internalurl],
91         :admin_url    => endpoint[:adminurl]
92       )
93     end
94   end
95
96   def self.prefetch(resources)
97     endpoints = instances
98     resources.keys.each do |name|
99        if provider = endpoints.find{ |endpoint| endpoint.name == name }
100         resources[name].provider = provider
101       end
102     end
103   end
104
105   def flush
106     if ! @property_flush.empty?
107       destroy
108       create
109       @property_flush.clear
110     end
111   end
112 end