]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/neutron/lib/puppet/type/neutron_subnet.rb
try again, with puppetforge modules, correctly included now
[dsa-puppet.git] / 3rdparty / modules / neutron / lib / puppet / type / neutron_subnet.rb
1 Puppet::Type.newtype(:neutron_subnet) do
2
3   ensurable
4
5   newparam(:name, :namevar => true) do
6     desc 'Symbolic name for the subnet'
7     newvalues(/.*/)
8   end
9
10   newproperty(:id) do
11     desc 'The unique id of the subnet'
12     validate do |v|
13       raise(Puppet::Error, 'This is a read only property')
14     end
15   end
16
17   newproperty(:cidr) do
18     desc 'CIDR representing IP range for this subnet, based on IP version'
19   end
20
21   newproperty(:ip_version) do
22     desc 'The IP version of the CIDR'
23     newvalues('4', '6')
24   end
25
26   newproperty(:allocation_pools, :array_matching => :all) do
27     desc <<-EOT
28     Array of Sub-ranges of cidr available for dynamic allocation to ports.
29     Syntax:["start=IPADDR,end=IPADDR", ...]
30     EOT
31   end
32
33   newproperty(:gateway_ip) do
34     desc <<-EOT
35     The default gateway provided by DHCP to devices in this subnet.  If set to
36     '' then no gateway IP address will be provided via DHCP.
37     EOT
38   end
39
40   newproperty(:enable_dhcp) do
41     desc 'Whether DHCP is enabled for this subnet or not.'
42     newvalues(/(t|T)rue/, /(f|F)alse/)
43     munge do |v|
44       v.to_s.capitalize
45     end
46   end
47
48   newproperty(:host_routes, :array_matching => :all) do
49     desc <<-EOT
50     Array of routes that should be used by devices with IPs from this subnet
51     (not including local subnet route).
52     Syntax:["destination=CIDR,nexhop=IP_ADDR", ...]
53     EOT
54   end
55
56   newproperty(:dns_nameservers, :array_matching => :all) do
57     desc <<-EOT
58     'Array of DNS name servers used by hosts in this subnet.'
59     EOT
60   end
61
62   newproperty(:network_id) do
63     desc 'A uuid identifying the network this subnet is associated with.'
64   end
65
66   newparam(:network_name) do
67     desc 'The name of the network this subnet is associated with.'
68   end
69
70   newparam(:tenant_name) do
71     desc 'The name of the tenant which will own the subnet.'
72   end
73
74   newproperty(:tenant_id) do
75     desc 'A uuid identifying the tenant which will own the subnet.'
76   end
77
78   autorequire(:service) do
79     ['neutron-server']
80   end
81
82   autorequire(:keystone_tenant) do
83     [self[:tenant_name]] if self[:tenant_name]
84   end
85
86   autorequire(:neutron_network) do
87     [self[:network_name]] if self[:network_name]
88   end
89
90   validate do
91     if self[:ensure] != :present
92       return
93     end
94     if ! self[:cidr]
95       raise(Puppet::Error, 'Please provide a valid CIDR')
96     elsif ! (self[:network_id] || self[:network_name])
97       raise(Puppet::Error, <<-EOT
98 A value for one of network_name or network_id must be provided.
99 EOT
100             )
101     elsif self[:network_id] && self[:network_name]
102       raise(Puppet::Error, <<-EOT
103 Please provide a value for only one of network_name and network_id.
104 EOT
105             )
106     elsif self[:tenant_id] && self[:tenant_name]
107       raise(Puppet::Error, <<-EOT
108 Please provide a value for only one of tenant_name and tenant_id.
109 EOT
110             )
111     end
112   end
113
114 end