Merge "MaaS: DHCP iprange fix: use dynamic, not reserved"
[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          "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          "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 | 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 salt -C '* and not cfg01* and not mas01*' saltutil.sync_all
57 salt -C '* and not cfg01* and not mas01*' state.apply salt
58 salt -C '* and not cfg01* and not mas01*' state.apply linux,ntp