Merge "Change default bond-mode"
[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 include ::tripleo::packages
17
18 define add_devices(
19   $swift_zones = '1'
20 ){
21
22   # NOTE(dprince): Swift zones is not yet properly wired into the Heat
23   # templates. See: https://review.openstack.org/#/c/97758/3
24   # For now our regex supports the r1z1-192.0.2.6:%PORT%/d1 syntax or the
25   # newer r1z%<controller or SwiftStorage><N>%-192.0.2.6:%PORT%/d1 syntax.
26   $server_num_or_device = regsubst($name,'^r1z%+[A-Za-z]*([0-9]+)%+-(.*)$','\1')
27   if (is_integer($server_num_or_device)) {
28     $server_num = $server_num_or_device
29   } else {
30     $server_num = '1'
31   }
32   # Function to place server in its zone.  Zone is calculated by
33   # server number in heat template modulo the number of zones + 1.
34   $zone = (($server_num%$swift_zones) + 1)
35
36   # add the rings
37   $base = regsubst($name,'^r1.*-(.*)$','\1')
38   $object = regsubst($base, '%PORT%', '6000')
39   ring_object_device { $object:
40     zone   => '1',
41     weight => 100,
42   }
43   $container = regsubst($base, '%PORT%', '6001')
44   ring_container_device { $container:
45     zone   => '1',
46     weight => 100,
47   }
48   $account = regsubst($base, '%PORT%', '6002')
49   ring_account_device { $account:
50     zone   => '1',
51     weight => 100,
52   }
53 }
54
55 class tripleo::ringbuilder (
56   $swift_zones     = '1',
57   $devices         = '',
58   $build_ring      = true,
59   $part_power,
60   $replicas,
61   $min_part_hours,
62 ) {
63
64   validate_bool($build_ring)
65
66   if $build_ring {
67
68     $device_array = strip(split(rstrip($devices), ','))
69
70     # create local rings
71     swift::ringbuilder::create{ ['object', 'account', 'container']:
72       part_power     => $part_power,
73       replicas       => $replicas,
74       min_part_hours => $min_part_hours,
75     } ->
76
77     # add all other devices
78     add_devices {$device_array:
79       swift_zones => $swift_zones,
80     } ->
81
82     # rebalance
83     swift::ringbuilder::rebalance{ ['object', 'account', 'container']:
84       seed => 999,
85     }
86
87     Ring_object_device<| |> ~> Exec['rebalance_object']
88     Ring_object_device<| |> ~> Exec['rebalance_account']
89     Ring_object_device<| |> ~> Exec['rebalance_container']
90
91   }
92 }
93
94 include ::tripleo::ringbuilder
95
96 package_manifest{'/var/lib/tripleo/installed-packages/ringbuilder': ensure => present}