ccc6b9c5e96a8e5fe5a8c7574d0c7ab0c1b62473
[mirror/dsa-puppet.git] / 3rdparty / modules / nova / lib / puppet / type / nova_aggregate.rb
1 # -*- coding: utf-8 -*-
2 #
3 # Copyright (C) 2014 Deutsche Telekom AG
4 #
5 # Author: Thomas Bechtold <t.bechtold@telekom.de>
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 # nova_aggregate type
20 #
21 # == Parameters
22 #  [*name*]
23 #    Name for the new aggregate
24 #    Required
25 #
26 #  [*availability_zone*]
27 #    The availability zone. ie "zone1"
28 #    Optional
29 #
30 #  [*metadata*]
31 #    String with key/value pairs. ie "key=value,key=value"
32 #    Optional
33 #
34 #  [*hosts*]
35 #    A comma seperated list with hosts or a single host. ie "host1,host2"
36 #    Optional
37 #
38
39 require 'puppet'
40
41 Puppet::Type.newtype(:nova_aggregate) do
42
43   @doc = "Manage creation of nova aggregations."
44
45   ensurable
46
47   autorequire(:nova_config) do
48     ['auth_host', 'auth_port', 'auth_protocol', 'admin_tenant_name', 'admin_user', 'admin_password']
49   end
50
51   newparam(:name, :namevar => true) do
52     desc 'Name for the new aggregate'
53     validate do |value|
54       if not value.is_a? String
55         raise ArgumentError, "name parameter must be a String"
56       end
57       unless value =~ /[a-z0-9]+/
58         raise ArgumentError, "#{value} is not a valid name"
59       end
60     end
61   end
62
63   newproperty(:id) do
64     desc 'The unique Id of the aggregate'
65     validate do |v|
66       raise ArgumentError, 'This is a read only property'
67     end
68   end
69
70   newproperty(:availability_zone) do
71     desc 'The availability zone of the aggregate'
72     validate do |value|
73       if not value.is_a? String
74         raise ArgumentError, "availability zone must be a String"
75       end
76     end
77   end
78
79   newproperty(:metadata) do
80     desc 'The metadata of the aggregate'
81     #convert DSL/string form to internal form which is a single hash
82     munge do |value|
83       internal = Hash.new
84       value.split(",").map{|el| el.strip()}.each do |pair|
85         key, value = pair.split("=", 2)
86         internal[key.strip()] = value.strip()
87       end
88       return internal
89     end
90
91     validate do |value|
92       value.split(",").each do |kv|
93         raise ArgumentError, "Key/value pairs must be separated by an =" unless value.include?("=")
94       end
95     end
96   end
97
98   newproperty(:hosts) do
99     desc 'Single host or comma seperated list of hosts'
100     #convert DSL/string form to internal form
101     munge do |value|
102       return value.split(",").map{|el| el.strip()}
103     end
104   end
105
106   validate do
107     raise ArgumentError, 'Name type must be set' unless self[:name]
108   end
109
110 end