File: neutron.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 (54 lines) | stat: -rw-r--r-- 1,382 bytes parent folder | download | duplicates (5)
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
Puppet::Type.type(:neutron_l3_ovs_bridge).provide(:neutron) do
  desc <<-EOT
    Neutron provider to manage neutron_l3_ovs_bridge type.

    The provider ensures that the gateway ip of the subnet is
    configured on the ovs bridge.
  EOT

  commands :ip => '/sbin/ip'

  mk_resource_methods

  def gateway_ip
    if @gateway_ip == nil
      subnet = Puppet::Type.type('neutron_subnet').instances.find do |instance|
        instance.provider.name == @resource[:subnet_name]
      end
      if subnet
        provider = subnet.provider
        @gateway_ip = "#{provider.gateway_ip}/#{provider.cidr.split('/')[1]}"
      else
        fail("Unable to find subnet for name #{@resource[:subnet_name]}")
      end
    end
    @gateway_ip
  end

  def bridge_ip_addresses
    addresses = []
    result = ip('addr', 'show', @resource[:name])
    (result.split("\n") || []).compact.each do |line|
      if match = line.match(/\sinet ([^\s]*) .*/)
        addresses << match.captures[0]
      end
    end
    return addresses
  end

  def exists?
    bridge_ip_addresses.include?(gateway_ip)
  end

  def create
    ip('addr', 'add', gateway_ip, 'dev', @resource[:name])
    ip('link', 'set', 'dev', @resource[:name], 'up')
    @property_hash[:ensure] = :present
  end

  def destroy
    ip('addr', 'del', gateway_ip, 'dev', @resource[:name])
    @property_hash[:ensure] = :absent
  end

end