Allow to enable fencing, pass through fencing config
[apex-tripleo-heat-templates.git] / puppet / manifests / ringbuilder.pp
1 # Copyright 2015 Red Hat, Inc.
2 # All Rights Reserved.
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License"); you may
5 # not use this file except in compliance with the License. You may obtain
6 # a copy of the License at
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 # License for the specific language governing permissions and limitations
14 # under the License.
15
16 if str2bool(hiera('disable_package_install', 'false')) {
17   case $::osfamily {
18     'RedHat': {
19       Package { provider => 'norpm' } # provided by tripleo-puppet
20     }
21     default: {
22       warning('disable_package_install option not supported.')
23     }
24   }
25 }
26
27 define add_devices(
28   $swift_zones = '1'
29 ){
30
31   # NOTE(dprince): Swift zones is not yet properly wired into the Heat
32   # templates. See: https://review.openstack.org/#/c/97758/3
33   # For now our regex supports the r1z1-192.0.2.6:%PORT%/d1 syntax or the
34   # newer r1z%<controller or SwiftStorage><N>%-192.0.2.6:%PORT%/d1 syntax.
35   $server_num_or_device = regsubst($name,'^r1z%+[A-Za-z]*([0-9]+)%+-(.*)$','\1')
36   if (is_integer($server_num_or_device)) {
37     $server_num = $server_num_or_device
38   } else {
39     $server_num = '1'
40   }
41   # Function to place server in its zone.  Zone is calculated by
42   # server number in heat template modulo the number of zones + 1.
43   $zone = (($server_num%$swift_zones) + 1)
44
45   # add the rings
46   $base = regsubst($name,'^r1.*-(.*)$','\1')
47   $object = regsubst($base, '%PORT%', '6000')
48   ring_object_device { $object:
49     zone        => '1',
50     weight      => 100,
51   }
52   $container = regsubst($base, '%PORT%', '6001')
53   ring_container_device { $container:
54     zone        => '1',
55     weight      => 100,
56   }
57   $account = regsubst($base, '%PORT%', '6002')
58   ring_account_device { $account:
59     zone        => '1',
60     weight      => 100,
61   }
62 }
63
64 class tripleo::ringbuilder (
65   $swift_zones     = '1',
66   $devices         = '',
67   $build_ring      = 'True',
68   $part_power,
69   $replicas,
70   $min_part_hours,
71 ) {
72
73   if str2bool(downcase("$build_ring")) {
74
75     $device_array = strip(split(rstrip($devices), ','))
76
77     # create local rings
78     swift::ringbuilder::create{ ['object', 'account', 'container']:
79       part_power     => $part_power,
80       replicas       => $replicas,
81       min_part_hours => $min_part_hours,
82     } ->
83
84     # add all other devices
85     add_devices {$device_array:
86       swift_zones => $swift_zones
87     } ->
88
89     # rebalance
90     swift::ringbuilder::rebalance{ ['object', 'account', 'container']:
91       seed => 999,
92     }
93
94     Ring_object_device<| |> ~> Exec['rebalance_object']
95     Ring_object_device<| |> ~> Exec['rebalance_account']
96     Ring_object_device<| |> ~> Exec['rebalance_container']
97
98   }
99 }
100
101 include ::tripleo::ringbuilder