Debian Codegraph @

lib/puppet/type/nova_flavor.rb

raw
1 # nova_flavor type
2 #
3 # == Parameters
4 # [*name*]
5 # Name for the flavor
6 # Required
7 #
8 # [*id*]
9 # Unique ID (integer or UUID) for the flavor.
10 # Optional
11 #
12 # [*ram*]
13 # Amount of RAM to use (in megabytes).
14 # Optional
15 #
16 # [*disk*]
17 # Amount of disk space (in gigabytes) to use for the root (/) partition.
18 # Optional
19 #
20 # [*vcpus*]
21 # Number of virtual CPUs to use.
22 # Optional
23 #
24 # [*ephemeral*]
25 # Amount of disk space (in gigabytes) to use for the ephemeral partition.
26 # Optional
27 #
28 # [*swap*]
29 # Amount of swap space (in megabytes) to use.
30 # Optional
31 #
32 # [*rxtx_factor*]
33 # The slice of bandwidth that the instances with this flavor can use
34 # (through the Virtual Interface (vif) creation in the hypervisor)
35 # Optional
36 #
37 # [*is_public*]
38 # A boolean to indicate visibility
39 # Optional
40 #
41 # [*properties*]
42 # A key => value hash used to set the properties for the flavor. This is
43 # the only parameter that can be updated after the creation of the flavor.
44 # Optional
45 #
46 # [*project*]
47 # Set flavor access to project (ID).
48 # If you set this option, take care to set is_public to false.
49 # Optional
50 #
51 # [*project_name*]
52 # Set flavor access to project (name).
53 # If you set this option, take care to set is_public to false.
54 # Optional
55 #
56 require 'puppet'
57
58 Puppet::Type.newtype(:nova_flavor) do
59
60 @doc = "Manage creation of nova flavors."
61
62 ensurable
63
64 # Require the nova-api service to be running
65 autorequire(:anchor) do
66 ['nova::service::end']
67 end
68
69 autorequire(:keystone_tenant) do
70 [self[:project_name]] if (self[:project_name] and self[:project_name] != '')
71 end
72
73 newparam(:name, :namevar => true) do
74 desc 'Name for the flavor'
75 validate do |value|
76 if not value.is_a? String
77 raise ArgumentError, "name parameter must be a String"
78 end
79 unless value =~ /^[a-zA-Z0-9\-\._]+$/
80 raise ArgumentError, "#{value} is not a valid name"
81 end
82 end
83 end
84
85 newproperty(:id) do
86 desc 'Unique ID (integer or UUID) for the flavor.'
87 end
88
89 newproperty(:ram) do
90 desc 'Amount of RAM to use (in megabytes).'
91 newvalues(/\d+/)
92 end
93
94 newproperty(:disk) do
95 desc 'Amount of disk space (in gigabytes) to use for the root (/) partition.'
96 newvalues(/\d+/)
97 end
98
99 newproperty(:vcpus) do
100 desc 'Number of virtual CPUs to use.'
101 newvalues(/\d+/)
102 end
103
104 newproperty(:ephemeral) do
105 desc 'Amount of disk space (in gigabytes) to use for the ephemeral partition.'
106 newvalues(/\d+/)
107 end
108
109 newproperty(:swap) do
110 desc 'Amount of swap space (in megabytes) to use.'
111 newvalues(/\d+/)
112 end
113
114 newproperty(:rxtx_factor) do
115 desc 'The slice of bandwidth that the instances with this flavor can use (through the Virtual Interface (vif) creation in the hypervisor)'
116 newvalues(/\d+(\.\d+)?/)
117 end
118
119 newproperty(:is_public) do
120 desc "Whether the flavor is public or not. Default true"
121 newvalues(/(y|Y)es/, /(n|N)o/, /(t|T)rue/, /(f|F)alse/, true, false)
122 defaultto(:true)
123
124 munge do |value|
125 case value.to_s.downcase
126 when 'true', 'yes'
127 :true
128 else
129 :false
130 end
131 end
132 end
133
134 newproperty(:project) do
135 desc 'Set flavor access to project (ID).'
136 end
137
138 newproperty(:project_name) do
139 desc 'Set flavor access to project (Name).'
140 end
141
142 newproperty(:properties) do
143 desc "The set of flavor properties"
144
145 validate do |value|
146 if value.is_a?(Hash)
147 return true
148 else
149 raise ArgumentError, "Invalid properties #{value}. Requires a Hash, not a #{value.class}"
150 end
151 end
152 end
153
154 validate do
155 unless self[:name]
156 raise(ArgumentError, 'Name must be set')
157 end
158
159 if self[:project] && self[:project_name]
160 raise(Puppet::Error, <<-EOT
161 Please provide a value for only one of project_name and project.
162 EOT
163 )
164 end
165 end
166
167 end