Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / manifests / set.pp @ 51850192

Historique | Voir | Annoter | Télécharger (2,95 ko)

1
# @summary  manage a named set
2
#
3
# @example simple set
4
#  nftables::set{'my_set':
5
#    type       => 'ipv4_addr',
6
#    flags      => ['interval'],
7
#    elements   => ['192.168.0.1/24', '10.0.0.2'],
8
#    auto_merge => true,
9
#  }
10
#
11
# @param ensure should the set be created.
12
# @param setname name of set, equal to to title.
13
# @param order concat ordering.
14
# @param type type of set.
15
# @param table table or array of tables to add the set to.
16
# @param flags specify flags for set
17
# @param timeout timeout in seconds
18
# @param gc_interval garbage collection interval.
19
# @param elements initialize the set with some elements in it.
20
# @param size limits the maximum number of elements of the set.
21
# @param policy determines set selection policy.
22
# @param auto_merge automatically merge adjacent/overlapping set elements (only valid for interval sets)
23
# @param content specify content of set.
24
# @param source specify source of set.
25
define nftables::set (
26
  Enum['present','absent'] $ensure = 'present',
27
  Pattern[/^[-a-zA-Z0-9_]+$/] $setname = $title,
28
  Pattern[/^\d\d$/] $order = '10',
29
  Optional[Enum['ipv4_addr', 'ipv6_addr', 'ether_addr', 'inet_proto', 'inet_service', 'mark']] $type = undef,
30
  Variant[String, Array[String, 1]] $table = 'inet-filter',
31
  Array[Enum['constant', 'dynamic', 'interval', 'timeout'], 0, 4] $flags = [],
32
  Optional[Integer] $timeout = undef,
33
  Optional[Integer] $gc_interval = undef,
34
  Optional[Array[String]] $elements = undef,
35
  Optional[Integer] $size = undef,
36
  Optional[Enum['performance', 'memory']] $policy = undef,
37
  Boolean $auto_merge = false,
38
  Optional[String] $content = undef,
39
  Optional[Variant[String,Array[String,1]]] $source = undef,
40
) {
41
  if $size and $elements {
42
    if length($elements) > $size {
43
      fail("Max size of set ${setname} of ${size} is not being respected")
44
    }
45
  }
46

    
47
  $_tables = Array($table, true)
48

    
49
  if $ensure == 'present' {
50
    $_tables.each |Integer $index, String $_table| {
51
      concat::fragment {
52
        "nftables-${_table}-set-${setname}":
53
          order  => $order,
54
          target => "nftables-${_table}",
55
      }
56

    
57
      if $content {
58
        Concat::Fragment["nftables-${_table}-set-${setname}"] {
59
          content => "  ${content}",
60
        }
61
      } elsif $source {
62
        Concat::Fragment["nftables-${_table}-set-${setname}"] {
63
          source => $source,
64
        }
65
      } else {
66
        if $type == undef {
67
          fail('The way the resource is configured must have a type set')
68
        }
69
        Concat::Fragment["nftables-${_table}-set-${setname}"] {
70
          content => epp('nftables/set.epp',
71
            {
72
              'name'        => $setname,
73
              'type'        => $type,
74
              'flags'       => $flags,
75
              'timeout'     => $timeout,
76
              'gc_interval' => $gc_interval,
77
              'elements'    => $elements,
78
              'size'        => $size,
79
              'policy'      => $policy,
80
              'auto_merge'  => $auto_merge,
81
            }
82
          )
83
        }
84
      }
85
    }
86
  }
87
}