Merge "virtual: odl-router: Stop overriding Ubuntu repos"
[fuel.git] / mcp / config / states / maas
1 #!/bin/bash
2 function wait_for() {
3   local cmdstr=$@
4   local total_attempts=360
5   local sleep_time=10
6   local attempt=1
7   echo "[NOTE] Waiting for cmd to return success: ${cmdstr}"
8   while ((attempt <= total_attempts)); do
9     eval "${cmdstr}" && break || true
10     echo -n '.'; sleep "${sleep_time}"
11     ((attempt+=1))
12   done
13 }
14
15 # MaaS rack/region controller, node commissioning
16 salt -C 'mas01*' cmd.run "add-apt-repository ppa:maas/stable"
17
18 salt -C 'mas01*' state.apply linux,salt,openssh,ntp
19 salt -C 'mas01*' state.apply linux.network.interface
20 salt -C 'mas01*' state.apply maas.pxe_nat
21 salt -C 'mas01*' state.apply maas.cluster
22 salt -C 'cfg01*' cmd.run \
23   "route add -net 192.168.11.0/24 gw ${MAAS_IP:-192.168.10.3}"
24
25 wait_for "salt -C 'mas01*' state.apply maas.region"
26
27 salt -C 'mas01*' state.apply maas.machines
28 # TODO: relax cond, as this is not re-entrant (e.g. nodes already deployed)
29 wait_for "salt 'mas01*' --out yaml state.apply maas.machines.status | " \
30          "tee /dev/stderr | fgrep -q 'Ready: 5'"
31
32 # MaaS node deployment
33 salt -C 'mas01*' state.apply maas.machines.deploy
34 wait_for "salt 'mas01*' --out yaml state.apply maas.machines.status | " \
35          "tee /dev/stderr | fgrep -q 'Deployed: 5'"
36
37 salt -C 'mas01*' pillar.item\
38   maas:region:admin:username \
39   maas:region:admin:password
40
41 # KVM, compute node prereqs (libvirt first), VCP deployment
42 salt -C '* and not cfg01* and not mas01*' saltutil.sync_all
43
44 salt -C 'kvm*' pkg.install bridge-utils
45 salt -C 'kvm*' state.apply linux.network
46 salt -C 'kvm*' system.reboot
47 wait_for "! salt '*' test.ping | tee /dev/stderr | fgrep -q 'Not connected'"
48
49 salt -C '* and not cfg01* and not mas01*' state.apply linux,ntp
50
51 salt -C 'kvm*' state.sls libvirt
52
53 salt -C '* and not cfg01* and not mas01*' state.apply salt
54 salt -C 'kvm*' state.sls salt.control
55
56 vcp_nodes=$(salt --out yaml 'kvm01*' pillar.get salt:control:cluster:internal:node | awk '/\s+\w+:$/ {gsub(/:$/, "*"); print $1}')
57
58 # Check all vcp nodes are available
59 rc=1
60 while [ $rc -ne 0 ]; do
61   rc=0
62   for node in $vcp_nodes; do
63     salt "$node" test.ping 2>/dev/null 1>&2 || { rc=$?; break; };
64   done
65 done
66
67 salt -C '* and not cfg01* and not mas01*' saltutil.sync_all
68 salt -C '* and not cfg01* and not mas01*' state.apply salt
69 salt -C '* and not cfg01* and not mas01*' state.apply linux,ntp