7b3bb6433d9e458ee83c146eb0ca5782b5cd4e3a
[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 'kvm*' pkg.install bridge-utils
45 salt 'kvm*' cmd.run 'salt-call state.sls linux.network; reboot'
46 wait_for "! salt '*' test.ping | fgrep -q 'Not connected'"
47
48 salt -C '* and not cfg01* and not mas01*' state.apply linux,ntp
49
50 salt -C 'kvm*' state.sls libvirt
51
52 salt -C '* and not cfg01* and not mas01*' state.apply salt
53 salt -C 'kvm*' state.sls salt.control
54
55 salt -C '* and not cfg01* and not mas01*' saltutil.sync_all
56 salt -C '* and not cfg01* and not mas01*' state.apply salt
57 salt -C '* and not cfg01* and not mas01*' state.apply linux,ntp