Puppet Class: profile::ganeti

Defined in:
modules/profile/manifests/ganeti.pp

Overview

Parameters:

  • nodes (Array[Stdlib::Fqdn]) (defaults to: lookup('profile::ganeti::nodes'))
  • rapi_nodes (Array[Stdlib::Fqdn]) (defaults to: lookup('profile::ganeti::rapi_nodes'))
  • rapi_certificate (String) (defaults to: lookup('profile::ganeti::rapi::certificate'))
  • rapi_ro_user (Optional[String]) (defaults to: lookup('profile::ganeti::rapi::ro_user', { default_value => undef }))
  • rapi_ro_password (Optional[String]) (defaults to: lookup('profile::ganeti::rapi::ro_password', { default_value => undef }))
  • critical_memory (Integer[0, 100]) (defaults to: lookup('profile::ganeti::critical_memory'))
  • warning_memory (Integer[0, 100]) (defaults to: lookup('profile::ganeti::warning_memory'))
  • routed (Boolean) (defaults to: lookup('profile::ganeti::routed'))
  • tap_ip4 (Optional[Stdlib::IP::Address]) (defaults to: lookup('profile::ganeti::tap_ip4', { default_value => undef }))
  • tftp_servers (Hash[Wmflib::Sites, Stdlib::IP::Address]) (defaults to: lookup('profile::installserver::dhcp::tftp_servers'))


53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
# File 'modules/profile/manifests/ganeti.pp', line 53

class profile::ganeti (
    Array[Stdlib::Fqdn]                      $nodes            = lookup('profile::ganeti::nodes'),
    Array[Stdlib::Fqdn]                      $rapi_nodes       = lookup('profile::ganeti::rapi_nodes'),
    String                                   $rapi_certificate = lookup('profile::ganeti::rapi::certificate'),
    Optional[String]                         $rapi_ro_user     = lookup('profile::ganeti::rapi::ro_user',
                                                                        { default_value => undef }),
    Optional[String]                         $rapi_ro_password = lookup('profile::ganeti::rapi::ro_password',
                                                                        { default_value => undef }),
    Integer[0, 100]                          $critical_memory  = lookup('profile::ganeti::critical_memory'),
    Integer[0, 100]                          $warning_memory   = lookup('profile::ganeti::warning_memory'),
    Boolean                                  $routed           = lookup('profile::ganeti::routed'),
    Optional[Stdlib::IP::Address]            $tap_ip4          = lookup('profile::ganeti::tap_ip4',
                                                                        { default_value => undef }),
    Hash[Wmflib::Sites, Stdlib::IP::Address] $tftp_servers     = lookup('profile::installserver::dhcp::tftp_servers'),
) {

    class { 'ganeti':
        certname => $rapi_certificate,
    }

    class { 'ganeti::prometheus':
        rapi_endpoint    => $rapi_certificate,
        rapi_ro_user     => $rapi_ro_user,
        rapi_ro_password => $rapi_ro_password,
    }

    # Ganeti needs intracluster SSH root access
    # DSS+RSA keys in here, but note that DSS is deprecated
    ssh::userkey { 'root-ganeti':
        ensure => present,
        user   => 'root',
        skey   => 'ganeti',
        source => 'puppet:///modules/profile/ganeti/ganeti.pub',
    }

    # The RSA private key
    file { '/root/.ssh/id_rsa':
        ensure    => present,
        owner     => 'root',
        group     => 'root',
        mode      => '0400',
        content   => secret('ganeti/id_rsa'),
        show_diff => false,
    }
    # This is here for completeness
    file { '/root/.ssh/id_rsa.pub':
        ensure => present,
        owner  => 'root',
        group  => 'root',
        mode   => '0400',
        source => 'puppet:///modules/profile/ganeti/id_rsa.pub',
    }

    motd::script { 'ganeti-master-motd':
        ensure => present,
        source => 'puppet:///modules/profile/ganeti/motd',
    }

    if defined('$rapi_ro_user') and defined('$rapi_ro_password') {
        # Authentication for RAPI (for now just a single read-only user)
        $ro_password_hash = md5("${rapi_ro_user}:Ganeti Remote API:${rapi_ro_password}")
        $real_content = "${rapi_ro_user} {HA1}${ro_password_hash} read\n"
    } else {
        # Provide a blank authentication file for the RAPI server (no users will be defined, thus denying all)
        $real_content = ''
    }

    file { '/var/lib/ganeti/rapi':
        ensure => directory,
        owner  => 'gnt-rapi',
        group  => 'gnt-masterd',
        mode   => '0750',
    }

    file { '/var/lib/ganeti/rapi/users':
        ensure  => present,
        owner   => 'gnt-rapi',
        group   => 'gnt-masterd',
        mode    => '0640',
        content => $real_content,
        require => Class['ganeti'],
    }

    # Allow SSH between ganeti cluster members
    firewall::service { 'ganeti_ssh_cluster':
        proto  => 'tcp',
        port   => 22,
        srange => $nodes,
    }

    # RAPI is the API of ganeti
    firewall::service { 'ganeti_rapi_cluster':
        proto  => 'tcp',
        port   => 5080,
        srange => $nodes + $rapi_nodes,
    }

    # Ganeti noded is responsible for all cluster/node actions
    firewall::service { 'ganeti_noded_cluster':
        proto  => 'tcp',
        port   => 1811,
        srange => $nodes,
    }

    # Ganeti confd provides a HA and fast way to query cluster configuration
    firewall::service { 'ganeti_confd_cluster':
        proto  => 'udp',
        port   => 1814,
        srange => $nodes,
    }

    # Ganeti mond is the monitoring daemon. Data is available via port 1815
    firewall::service { 'ganeti_mond_cluster':
        proto  => 'tcp',
        port   => 1815,
        srange => $nodes,
    }

    # DRBD is used for HA of disk images. Port range for ganeti is 11000-14999
    firewall::service { 'ganeti_drbd':
        proto      => 'tcp',
        port_range => [11000,14999],
        srange     => $nodes,
    }

    # Migration is done over TCP port
    firewall::service { 'ganeti_migration':
        proto  => 'tcp',
        port   => 8102,
        srange => $nodes,
    }

    file { '/usr/local/sbin/ganeti_rebalance':
        ensure => present,
        mode   => '0755',
        owner  => 'root',
        group  => 'root',
        source => 'puppet:///modules/profile/ganeti/ganeti_rebalance.sh',
    }

    # If ganeti_cluster fact is not defined, the node has not been added to a
    # cluster yet, so don't monitor
    if $facts['ganeti_cluster'] {

        # Service monitoring
        nrpe::monitor_service{ 'ganeti-noded':
            description  => 'ganeti-noded running',
            nrpe_command => '/usr/lib/nagios/plugins/check_procs -w 1:2 -c 1:2 -u root -C ganeti-noded',
            notes_url    => 'https://wikitech.wikimedia.org/wiki/Ganeti',
        }

        nrpe::monitor_service{ 'ganeti-confd':
            description  => 'ganeti-confd running',
            nrpe_command => '/usr/lib/nagios/plugins/check_procs -w 1:1 -c 1:1 -u gnt-confd -C ganeti-confd',
            notes_url    => 'https://wikitech.wikimedia.org/wiki/Ganeti',
        }

        nrpe::monitor_service{ 'ganeti-mond':
            description  => 'ganeti-mond running',
            nrpe_command => '/usr/lib/nagios/plugins/check_procs -w 1:1 -c 1:1 -u root -C ganeti-mond',
            notes_url    => 'https://wikitech.wikimedia.org/wiki/Ganeti',
        }

        # Memory monitoring
        ensure_packages( 'monitoring-plugins-contrib' )  # for pmp-check-unix-memory
        $check_path = '/usr/lib/nagios/plugins/pmp-check-unix-memory'
        $check_command = "${check_path} -c ${critical_memory} -w ${warning_memory}"
        nrpe::monitor_service { 'ganeti_memory':
            ensure       => absent,
            description  => 'Ganeti memory',
            nrpe_command => $check_command,
            notes_url    => 'https://wikitech.wikimedia.org/wiki/Ganeti#Memory_pressure',
        }

        if $facts['ganeti_master'] == $facts['fqdn'] {
            nrpe::monitor_service { "https-gnt-rapi-${::site}":
                description  => "HTTPS Ganeti RAPI ${::site}",
                nrpe_command => "/usr/lib/nagios/plugins/check_http -H ${facts['ganeti_cluster']} -p 5080 -S -e 401",
                notes_url    => 'https://www.mediawiki.org/wiki/Ganeti#RAPI_daemon',
            }

            nrpe::monitor_service{ 'ganeti-wconfd':
                description  => 'ganeti-wconfd running',
                nrpe_command => '/usr/lib/nagios/plugins/check_procs -w 1:1 -c 1:1 -u gnt-masterd -C ganeti-wconfd',
                notes_url    => 'https://wikitech.wikimedia.org/wiki/Ganeti',
            }
        }
        # Run a montly rebalancing for all nodegroups
        # Note: We only run this on the first Wednesday of the month
        # This should only be run on the master and absented from all other
        # nodes
        $hbal_presence = $facts['ganeti_master'] ? {
            $facts['fqdn'] => absent,
            default        => absent,
        }
        systemd::timer::job { 'monthly_ganeti_rebalance':
            ensure      => $hbal_presence,
            description => 'Run a monthly rebalance of Ganeti instances',
            command     => '/usr/local/sbin/ganeti_rebalance',
            user        => 'root',
            interval    => [{
                'start'    => 'OnCalendar',
                'interval' => 'Wed *-*-01,02,03,04,05,06,07 11:47:00',
                }
            ]
        }
    }
    if $routed {
        if $tap_ip4 == undef {
            fail('In routed mode, `profile::ganeti::tap_ip4` must be defined.')
        }
        systemd::mask { 'isc-dhcp-relay.service': }
        ensure_packages('isc-dhcp-relay')
        # To be replaced by finer grained policies
        # DHCP, BGP
        nftables::file::input { 'ganeti_guest_vm_all_in':
            content => "iifname \"tap*\" accept\n",
            order   => 10,
        }
        # TODO ideally get those from Netbox or data.yaml
        $v6_prefixes = $::site ? {
            'codfw' => {'private' => '2620:0:860:140', 'public' => '2620:0:860:5'},
            'eqiad' => {'private' => '2620:0:861:140', 'public' => '2620:0:861:5'},
        }
        # Override the Package provided net-common script
        file { '/usr/lib/ganeti/3.0/usr/lib/ganeti/net-common':
            ensure  => present,
            owner   => 'root',
            group   => 'root',
            mode    => '0755',
            content => template('profile/ganeti/net-common.erb'),
        }

        sysctl::parameters { 'primary-nic-ip-forward':
            values => {
                'net.ipv4.ip_forward'                                     => 1,
                "net.ipv4.conf.${$facts['interface_primary']}.ip_forward" => 1,
                "net.ipv6.conf.${$facts['interface_primary']}.accept_ra"  => 2,
                "net.ipv6.conf.${$facts['interface_primary']}.ip_forward" => 1,
                'net.ipv6.conf.all.ip_forward'                            => 1,
            },
        }

        class { 'bird':
            bfd             => false,
            do_ipv6         => true,
            multihop        => false,
            config_template => 'bird/bird_ganeti.conf.erb',
        }
    }
}