File: vs_config.rb

package info (click to toggle)
puppet-module-vswitch 21.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 596 kB
  • sloc: ruby: 2,189; python: 38; sh: 10; makefile: 10
file content (71 lines) | stat: -rw-r--r-- 1,745 bytes parent folder | download | duplicates (2)
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
require 'puppet'

Puppet::Type.newtype(:vs_config) do
  desc 'Switch configurations'

  ensurable

  newparam(:name, :namevar => true) do
    desc 'Configuration parameter whose value need to be set'

    validate do |value|
      if !value.is_a?(String)
        raise ArgumentError, "Invalid name #{value}. Requires a String, not a #{value.class}"
      end
    end
  end

  newparam(:skip_if_version) do
    desc 'Skip setting the value when ovs version matches'
    validate do |value|
      unless value.is_a?(String) and value =~ /^\d+.\d+$/
        raise ArgumentError, "Invalid skip_if_version #{value}. Requires a String with format \d+.\d+, not a #{value.class}"
      end
    end
  end

  newparam(:wait) do
    desc 'Should it wait for ovs-vswitchd to reconfigure itself before it exits'

    newvalues(:true, :false)
    defaultto :true
  end

  newparam(:restart) do
    desc 'Should the openvswitch service be restarted'

    newvalues(:true, :false)
    defaultto :false
  end

  autorequire(:service) do
    ['openvswitch']
  end

  autonotify(:service) do
    ['restart openvswitch'] if self[:restart]
  end

  newproperty(:value) do
    desc 'Configuration value for the parameter'

    validate do |value|
      if !value.is_a?(String) and !value.is_a?(Integer) and !(value == true) and !(value == false)
        raise ArgumentError, "Invalid value #{value}. Requires a String, a Integer or a Boolean, not a #{value.class}"
      end
    end

    munge do |value|
      if value.is_a?(String)
        if value[0] == '[' && value[-1] == ']'
          "[#{value[1..-2].split(',').map(&:strip).sort.join(",")}]"
        else
          super(value)
        end
      else
        super(String(value))
      end
    end
  end
end