Defined Type: interface::aggregate

Defined in:
modules/interface/manifests/aggregate.pp

Overview

Parameters:

  • orig_interface (Any) (defaults to: undef)
  • members (Any) (defaults to: [])
  • lacp_rate (Any) (defaults to: 'fast')
  • hash_policy (Any) (defaults to: 'layer2+3')


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
# File 'modules/interface/manifests/aggregate.pp', line 1

define interface::aggregate($orig_interface=undef, $members=[], $lacp_rate='fast', $hash_policy='layer2+3') {
    require_package('ifenslave-2.6')

    # Use the definition title as the destination (aggregated) interface
    $aggr_interface = $title

    if $orig_interface != '' {
        # Convert an existing interface, e.g. from eth0 to bond0
        $augeas_changes = [
            "set auto[./1 = '${orig_interface}']/1 '${aggr_interface}'",
            "set iface[. = '${orig_interface}'] '${aggr_interface}'"
        ]

        # Bring down the old interface after conversion
        exec { "ip addr flush dev ${orig_interface}":
            command     => "/sbin/ip addr flush dev ${orig_interface}",
            before      => Exec["ifup ${aggr_interface}"],
            subscribe   => Augeas["create ${aggr_interface}"],
            refreshonly => true,
            notify      => Exec["ifup ${aggr_interface}"]
        }
    } else {
        $augeas_changes = [
            "set auto[./1 = '${aggr_interface}']/1 '${aggr_interface}'",
            "set iface[. = '${aggr_interface}'] '${aggr_interface}'",
            "set iface[. = '${aggr_interface}']/family 'inet'",
            "set iface[. = '${aggr_interface}']/method 'manual'"
        ]
    }

    augeas { "create ${aggr_interface}":
        context => '/files/etc/network/interfaces/',
        changes => $augeas_changes,
        onlyif  => "match iface[. = '${aggr_interface}'] size == 0",
        notify  => Exec["ifup ${aggr_interface}"]
    }

    augeas { "configure ${aggr_interface}":
        require => Augeas["create ${aggr_interface}"],
        context => '/files/etc/network/interfaces/',
        changes => [
            inline_template("set iface[. = '<%= aggr_interface %>']/bond-slaves '<%= members.join(' ') %>"),
            "set iface[. = '${aggr_interface}']/bond-mode '802.3ad'",
            "set iface[. = '${aggr_interface}']/bond-lacp-rate '${lacp_rate}'",
            "set iface[. = '${aggr_interface}']/bond-miimon '100'",
            "set iface[. = '${aggr_interface}']/bond-xmit-hash-policy '${hash_policy}'"
        ],
        notify  => Exec["ifup ${aggr_interface}"]
    }

    # Define all aggregate members
    interface::aggregate_member{ $members:
        require => Augeas["create ${aggr_interface}"],
        master  => $aggr_interface,
        notify  => Exec["ifup ${aggr_interface}"]
    }

    # Bring up the new interface
    exec { "ifup ${aggr_interface}":
        command     => "/sbin/ifup --force ${aggr_interface}",
        require     => Interface::Aggregate_member[$members],
        refreshonly => true
    }
}