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