try again, with puppetforge modules, correctly included now
[mirror/dsa-puppet.git] / 3rdparty / modules / nova / lib / puppet / provider / nova_cells / nova_manage.rb
1 #
2 # Copyright (C) 2013 eNovance SAS <licensing@enovance.com>
3 #
4 # Author: Emilien Macchi <emilien.macchi@enovance.com>
5 #         François Charlier <francois.charlier@enovance.com>
6 #
7 # Licensed under the Apache License, Version 2.0 (the "License"); you may
8 # not use this file except in compliance with the License. You may obtain
9 # a copy of the License at
10 #
11 #      http://www.apache.org/licenses/LICENSE-2.0
12 #
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16 # License for the specific language governing permissions and limitations
17 # under the License.
18 #
19 #
20 # nova_cells provider
21 #
22
23 Puppet::Type.type(:nova_cells).provide(:nova_manage) do
24
25   desc "Manage nova cells"
26
27   optional_commands :nova_manage => 'nova-manage'
28
29   def self.instances
30     begin
31       cells_list = nova_manage("cell", "list")
32     rescue Exception => e
33       if e.message =~ /No cells defined/
34         return []
35       else
36         raise(e)
37       end
38     end
39     cells_list.split("\n")[1..-1].collect do |net|
40       if net =~ /^(\S+)\s+(\S+)/
41         new(:name => $2 )
42       end
43     end.compact
44   end
45
46
47   def create
48     optional_opts = []
49     {
50       :name                => '--name',
51       :cell_type           => '--cell_type',
52       :rabbit_username     => '--username',
53       :rabbit_password     => '--password',
54       :rabbit_hosts        => '--hostname',
55       :rabbit_port         => '--port',
56       :rabbit_virtual_host => '--virtual_host',
57       :weight_offset       => '--woffset',
58       :weight_scale        => '--wscale'
59
60     }.each do |param, opt|
61       if resource[param]
62         optional_opts.push(opt).push(resource[param])
63       end
64     end
65
66     nova_manage('cell', 'create',
67       optional_opts
68     )
69   end
70
71   def exists?
72     begin
73       cells_list = nova_manage("cell", "list")
74       return cells_list.split("\n")[1..-1].detect do |n|
75         n =~ /^(\S+)\s+(#{resource[:cells].split('/').first})/
76       end
77     rescue
78       return false
79     end
80   end
81
82
83   def destroy
84     nova_manage("cell", "delete", resource[:name])
85   end
86
87 end