Projet

Général

Profil

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

root / manifests / set.pp @ ae9872e2

Historique | Voir | Annoter | Télécharger (1,93 ko)

1
# manage a named set
2
define nftables::set(
3
  Enum['present','absent']
4
    $ensure = 'present',
5
  Pattern[/^[-a-zA-Z0-9_]+$/]
6
    $setname = $title,
7
  Pattern[/^\d\d$/]
8
    $order = '10',
9
  Optional[Enum['ipv4_addr', 'ipv6_addr', 'ether_addr', 'inet_proto', 'inet_service', 'mark']]
10
    $type = undef,
11
  String
12
    $table = 'inet-filter',
13
  Array[Enum['constant', 'dynamic', 'interval', 'timeout'], 0, 4]
14
    $flags = [],
15
  Optional[Integer]
16
    $timeout = undef,
17
  Optional[Integer]
18
    $gc_interval = undef,
19
  Optional[Array[String]]
20
    $elements = undef,
21
  Optional[Integer]
22
    $size = undef,
23
  Optional[Enum['performance', 'memory']]
24
    $policy = undef,
25
  Boolean
26
    $auto_merge = false,
27
  Optional[String]
28
    $content = undef,
29
  Optional[Variant[String,Array[String,1]]]
30
    $source = undef,
31
){
32

    
33
  if $size and $elements {
34
    if length($elements) > $size {
35
      fail("Max size of set ${setname} of ${size} is not being respected")
36
    }
37
  }
38

    
39
  if $ensure == 'present' {
40
    concat::fragment{
41
      "nftables-${table}-set-${setname}":
42
        order  => $order,
43
        target => "nftables-${table}",
44
    }
45

    
46
    if $content {
47
      Concat::Fragment["nftables-${table}-set-${setname}"]{
48
        content => "  ${content}",
49
      }
50
    } elsif $source {
51
      Concat::Fragment["nftables-${table}-set-${setname}"]{
52
        source => $source,
53
      }
54
    } else {
55
      if $type == undef {
56
        fail('The way the resource is configured must have a type set')
57
      }
58
      Concat::Fragment["nftables-${table}-set-${setname}"]{
59
        content => epp('nftables/set.epp',
60
          {
61
            'name'        => $setname,
62
            'type'        => $type,
63
            'flags'       => $flags,
64
            'timeout'     => $timeout,
65
            'gc_interval' => $gc_interval,
66
            'elements'    => $elements,
67
            'size'        => $size,
68
            'policy'      => $policy,
69
            'auto_merge'  => $auto_merge,
70
          }
71
        )
72
      }
73
    }
74
  }
75
}