Debian Codegraph @

lib/puppet/type/nova_aggregate.rb

raw
1 # -*- coding: utf-8 -*-
2 #
3 # Copyright (C) 2014 Deutsche Telekom AG
4 #
5 # Author: Thomas Bechtold <[email protected]>
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 # [*filter_hosts*]
27 # A boolean-y value to toggle whether only hosts known to be active by
28 # openstack should be aggregated. i.e. "true" or "false"
29 # Optional, defaults to "false"
30 #
31 # [*availability_zone*]
32 # The availability zone. ie "zone1"
33 # Optional
34 #
35 # [*metadata*]
36 # A key => value hash used to set the metadata for the aggregate.
37 # Optional
38 #
39 # [*hosts*]
40 # An array of hosts or a single host. ie "host1,host2"
41 # Optional
42 #
43 require 'puppet'
44
45 Puppet::Type.newtype(:nova_aggregate) do
46
47 @doc = "Manage creation of nova aggregations."
48
49 ensurable
50
51 # Require the nova-api service to be running
52 autorequire(:anchor) do
53 ['nova::service::end']
54 end
55
56 newparam(:name, :namevar => true) do
57 desc 'Name for the new aggregate'
58 validate do |value|
59 if not value.is_a? String
60 raise ArgumentError, "name parameter must be a String"
61 end
62 unless value =~ /[a-z0-9]+/
63 raise ArgumentError, "#{value} is not a valid name"
64 end
65 end
66 end
67
68 newparam(:filter_hosts) do
69 desc 'Toggle to filter given hosts so that only known nova-compute service hosts are added to the aggregate'
70 defaultto :false
71 newvalues(:true, :false)
72 end
73
74 newproperty(:id) do
75 desc 'The unique Id of the aggregate'
76 validate do |v|
77 raise ArgumentError, 'This is a read only property'
78 end
79 end
80
81 newproperty(:availability_zone) do
82 desc 'The availability zone of the aggregate'
83 validate do |value|
84 if not value.is_a? String
85 raise ArgumentError, "availability zone must be a String"
86 end
87 end
88 end
89
90 newproperty(:metadata) do
91 desc 'The metadata of the aggregate'
92
93 validate do |value|
94 if value.is_a?(Hash)
95 return true
96 else
97 raise ArgumentError, "Invalid metadata #{value}. Requires a Hash, not a #{value.class}"
98 end
99 end
100 end
101
102 newproperty(:hosts, :array_matching => :all) do
103 desc 'Single host or array of hosts'
104
105 def should
106 val = super
107 val.flatten
108 end
109
110 def should=(values)
111 super
112 @should = @should.flatten
113 end
114
115 def issync?(is)
116 return false unless is.is_a? Array
117 is.sort == should.sort
118 end
119
120 validate do |value|
121 if value.is_a?(String)
122 if value.include?(',')
123 warning('Using comma separated string for hosts is deprecated. Use an array instead.')
124 end
125 return value.split(",").map{|el| el.strip()}.sort
126 else
127 raise ArgumentError, "Invalid hosts #{value}. Requires a String, not a #{value.class}"
128 end
129 end
130 end
131
132 validate do
133 raise ArgumentError, 'Name type must be set' unless self[:name]
134 end
135 end