File: neutron_subnet.rb

package info (click to toggle)
puppet-module-neutron 25.0.0-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,708 kB
  • sloc: ruby: 12,680; python: 38; sh: 15; makefile: 10
file content (141 lines) | stat: -rw-r--r-- 3,472 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
Puppet::Type.newtype(:neutron_subnet) do

  ensurable

  newparam(:name, :namevar => true) do
    desc 'Symbolic name for the subnet'
    newvalues(/.*/)
  end

  newproperty(:id) do
    desc 'The unique id of the subnet'
    validate do |v|
      raise(Puppet::Error, 'This is a read only property')
    end
  end

  newproperty(:cidr) do
    desc 'CIDR representing IP range for this subnet, based on IP version'
  end

  newproperty(:ip_version) do
    desc 'The IP version of the CIDR'
    newvalues('4', '6')
  end

  newproperty(:ipv6_ra_mode) do
    desc 'The IPv6 RA (Router Advertisement) mode'
    newvalues('dhcpv6-stateful', 'dhcpv6-stateless', 'slaac')
  end

  newproperty(:ipv6_address_mode) do
    desc 'The IPv6 Address mode'
    newvalues('dhcpv6-stateful', 'dhcpv6-stateless', 'slaac')
  end

  newproperty(:allocation_pools, :array_matching => :all) do
    desc <<-EOT
    Array of Sub-ranges of cidr available for dynamic allocation to ports.
    Syntax:["start=IPADDR,end=IPADDR", ...]
    EOT
    def insync?(is)
      is.to_set == should.to_set
    end
  end

  newproperty(:gateway_ip) do
    desc <<-EOT
    The default gateway provided by DHCP to devices in this subnet.  If set to
    '' then no gateway IP address will be provided via DHCP.
    EOT
  end

  newproperty(:enable_dhcp) do
    desc 'Whether DHCP is enabled for this subnet or not.'
    newvalues(/(t|T)rue/, /(f|F)alse/)
    munge do |v|
      v.to_s.capitalize
    end
  end

  newproperty(:host_routes, :array_matching => :all) do
    desc <<-EOT
    Array of routes that should be used by devices with IPs from this subnet
    (not including local subnet route).
    Syntax:["destination=CIDR,nexhop=IP_ADDR", ...]
    EOT
  end

  newproperty(:dns_nameservers, :array_matching => :all) do
    desc <<-EOT
    'Array of DNS name servers used by hosts in this subnet.'
    EOT
  end

  newproperty(:network_id) do
    desc 'A uuid identifying the network this subnet is associated with.'
  end

  newparam(:network_name) do
    desc 'The name of the network this subnet is associated with.'
  end

  newparam(:project_name) do
    desc 'The name of the project which will own the subnet.'
  end

  newproperty(:project_id) do
    desc 'A uuid identifying the project which will own the subnet.'
  end

  autorequire(:anchor) do
    ['neutron::service::end']
  end

  autorequire(:keystone_tenant) do
    [self[:project_name]] if self[:project_name]
  end

  autorequire(:neutron_network) do
    [self[:network_name]] if self[:network_name]
  end

  validate do
    if self[:ensure] != :present
      return
    end

    if ! self[:cidr]
      raise(Puppet::Error, 'Please provide a valid CIDR')
    end

    if ! (self[:network_id] || self[:network_name])
      raise(Puppet::Error, <<-EOT
A value for one of network_name or network_id must be provided.
EOT
            )
    end

    if self[:network_id] && self[:network_name]
      raise(Puppet::Error, <<-EOT
Please provide a value for only one of network_name and network_id.
EOT
            )
    end

    if self[:project_id] && self[:project_name]
      raise(Puppet::Error, <<-EOT
Please provide a value for only one of project_name and project_id.
EOT
            )
    end

    if (self[:ipv6_ra_mode] || self[:ipv6_address_mode]) && String(self[:ip_version]) != '6'
      raise(Puppet::Error, <<-EOT
ipv6_ra_mode and ipv6_address_mode can only be used with ip_version set to '6'
EOT
           )
    end
  end

end