added new labconfig file for each lab also the default config file.
[joid.git] / ci / 02-maasdeploy.sh
1 #!/bin/bash
2 #placeholder for deployment script.
3 set -ex
4
5 virtinstall=0
6
7 cp maas/deployment.yaml ./deployment.yaml
8 cp ../labconfig/intel/pod6/labconfig.yaml ./
9
10 case "$1" in
11     'intelpod5' )
12         cp maas/intel/pod5/deployment.yaml ./deployment.yaml
13         ;;
14     'intelpod6' )
15         cp ../labconfig/intel/pod6/labconfig.yaml ./
16         #to be removed later once converted for all labs.
17         python deploy.py
18         ;;
19     'intelpod9' )
20         cp maas/intel/pod9/deployment.yaml ./deployment.yaml
21         ;;
22     'orangepod1' )
23         cp maas/orange/pod1/deployment.yaml ./deployment.yaml
24         ;;
25     'orangepod2' )
26         cp maas/orange/pod2/deployment.yaml ./deployment.yaml
27         ;;
28     'attvirpod1' )
29         cp maas/att/virpod1/deployment.yaml ./deployment.yaml
30         ;;
31     'juniperpod1' )
32         cp maas/juniper/pod1/deployment.yaml ./deployment.yaml
33         ;;
34     'cengnlynxpod1' )
35         cp maas/cengn_lynx/pod1/deployment.yaml ./deployment.yaml
36         ;;
37     'custom' )
38         cp maas/custom/deployment.yaml ./deployment.yaml
39         ;;
40     * )
41         virtinstall=1
42         ./cleanvm.sh
43         cp maas/default/deployment.yaml ./deployment.yaml
44         ;;
45 esac
46
47
48 #make sure no password asked during the deployment.
49
50 echo "$USER ALL=(ALL) NOPASSWD:ALL" > 90-joid-init
51
52 if [ -e /etc/sudoers.d/90-joid-init ]; then
53     sudo cp /etc/sudoers.d/90-joid-init 91-joid-init
54     sudo chown $USER:$USER 91-joid-init
55     sudo chmod 660 91-joid-init
56     sudo cat 90-joid-init >> 91-joid-init
57     sudo chown root:root 91-joid-init
58     sudo mv 91-joid-init /etc/sudoers.d/
59 else
60     sudo chown root:root 90-joid-init
61     sudo mv 90-joid-init /etc/sudoers.d/
62 fi
63
64 echo "... Deployment of maas Started ...."
65
66 if [ ! -e $HOME/.ssh/id_rsa ]; then
67     ssh-keygen -N '' -f $HOME/.ssh/id_rsa
68 fi
69
70 #define the pool and try to start even though its already exist.
71 # For fresh install this may or may not there.
72
73 sudo apt-get install libvirt-bin -y
74 sudo adduser $USER libvirtd
75 sudo virsh pool-define-as default --type dir --target /var/lib/libvirt/images/ || true
76 sudo virsh pool-start default || true
77 sudo virsh pool-autostart default || true
78
79 sudo apt-add-repository ppa:maas-deployers/stable -y
80 sudo apt-add-repository ppa:juju/stable -y
81 sudo apt-add-repository ppa:maas/stable -y
82 sudo apt-add-repository cloud-archive:liberty -y
83 sudo apt-get update -y
84 sudo apt-get dist-upgrade -y
85 sudo apt-get install openssh-server git maas-deployer juju juju-deployer maas-cli python-pip python-openstackclient gsutil -y
86
87 # To avoid problem between apiclient/maas_client and apiclient from google
88 # we remove the package google-api-python-client from yardstick installer
89 if [ $(pip list |grep google-api-python-client |wc -l) == 1 ]; then
90     sudo pip uninstall google-api-python-client
91 fi
92
93 sudo pip install shyaml
94 juju init -f
95
96 cat $HOME/.ssh/id_rsa.pub >> $HOME/.ssh/authorized_keys
97
98 if [ "$virtinstall" -eq 1 ]; then
99     sudo virsh net-dumpxml default > default-net-org.xml
100     sudo sed -i '/dhcp/d' default-net-org.xml
101     sudo sed -i '/range/d' default-net-org.xml
102     sudo virsh net-define default-net-org.xml
103     sudo virsh net-destroy default
104     sudo virsh net-start default
105 fi
106
107 #Below function will mark the interfaces in Auto mode to enbled by MAAS
108 enableautomode() {
109     listofnodes=`maas maas nodes list | grep system_id | cut -d '"' -f 4`
110     for nodes in $listofnodes
111     do
112         maas maas interface link-subnet $nodes $1  mode=$2 subnet=$3
113     done
114 }
115
116 #Below function will mark the interfaces in Auto mode to enbled by MAAS
117 # using hostname of the node added into MAAS
118
119 enableautomodebyname() {
120     if [ ! -z "$4" ]; then
121         for i in `seq 1 7`;
122         do
123             nodes=`maas maas nodes list hostname=node$i-$4 | grep system_id | cut -d '"' -f 4`
124             if [ ! -z "$nodes" ]; then
125                 maas maas interface link-subnet $nodes $1  mode=$2 subnet=$3
126             fi
127        done
128     fi
129 }
130
131 #Below function will create vlan and update interface with the new vlan
132 # will return the vlan id created
133 crvlanupdsubnet() {
134     newvlanid=`maas maas vlans create $2 name=$3 vid=$4 | grep resource | cut -d '/' -f 6 `
135     maas maas subnet update $5 vlan=$newvlanid
136     eval "$1"="'$newvlanid'"
137 }
138
139 #Below function will create interface with new vlan and bind to physical interface
140 crnodevlanint() {
141     listofnodes=`maas maas nodes list | grep system_id | cut -d '"' -f 4`
142
143     for nodes in $listofnodes
144     do
145         parentid=`maas maas interface read $nodes $2 | grep interfaces | cut -d '/' -f 8`
146         maas maas interfaces create-vlan $nodes vlan=$1 parent=$parentid
147      done
148  }
149
150 #convert labconfig file to deployment.yaml to consume by MAAS.
151 #python deploy.py
152
153 #just make sure the ssh keys added into maas for the current user
154 sed --i "s@/home/ubuntu@$HOME@g" ./deployment.yaml
155 sed --i "s@qemu+ssh://ubuntu@qemu+ssh://$USER@g" ./deployment.yaml
156
157 sudo maas-deployer -c deployment.yaml -d --force
158
159 sudo chown $USER:$USER environments.yaml
160
161 echo "... Deployment of maas finish ...."
162
163 maas_ip=`grep " ip_address" deployment.yaml | cut -d " "  -f 10`
164 apikey=`grep maas-oauth: environments.yaml | cut -d "'" -f 2`
165 maas login maas http://${maas_ip}/MAAS/api/1.0 ${apikey}
166 maas maas sshkeys new key="`cat $HOME/.ssh/id_rsa.pub`"
167
168 #Added the Qtip public to run the Qtip test after install on bare metal nodes.
169 maas maas sshkeys new key="`cat ./maas/sshkeys/QtipKey.pub`"
170
171 #adding compute and control nodes VM to MAAS for deployment purpose.
172 if [ "$virtinstall" -eq 1 ]; then
173     # create two more VMs to do the deployment.
174     sudo virt-install --connect qemu:///system --name node1-control --ram 8192 --vcpus 4 --disk size=120,format=qcow2,bus=virtio,io=native,pool=default --network bridge=virbr0,model=virtio --network bridge=virbr0,model=virtio --boot network,hd,menu=off --noautoconsole --vnc --print-xml | tee node1-control
175
176     sudo virt-install --connect qemu:///system --name node2-compute --ram 8192 --vcpus 4 --disk size=120,format=qcow2,bus=virtio,io=native,pool=default --network bridge=virbr0,model=virtio --network bridge=virbr0,model=virtio --boot network,hd,menu=off --noautoconsole --vnc --print-xml | tee node2-compute
177
178     sudo virt-install --connect qemu:///system --name node5-compute --ram 8192 --vcpus 4 --disk size=120,format=qcow2,bus=virtio,io=native,pool=default --network bridge=virbr0,model=virtio --network bridge=virbr0,model=virtio --boot network,hd,menu=off --noautoconsole --vnc --print-xml | tee node5-compute
179
180     node1controlmac=`grep  "mac address" node1-control | head -1 | cut -d "'" -f 2`
181     node2computemac=`grep  "mac address" node2-compute | head -1 | cut -d "'" -f 2`
182     node5computemac=`grep  "mac address" node5-compute | head -1 | cut -d "'" -f 2`
183
184     sudo virsh -c qemu:///system define --file node1-control
185     sudo virsh -c qemu:///system define --file node2-compute
186     sudo virsh -c qemu:///system define --file node5-compute
187
188     maas maas tags new name='control'
189     maas maas tags new name='compute'
190
191     controlnodeid=`maas maas nodes new autodetect_nodegroup='yes' name='node1-control' tags='control' hostname='node1-control' power_type='virsh' mac_addresses=$node1controlmac power_parameters_power_address='qemu+ssh://'$USER'@192.168.122.1/system' architecture='amd64/generic' power_parameters_power_id='node1-control' | grep system_id | cut -d '"' -f 4 `
192
193     maas maas tag update-nodes control add=$controlnodeid
194
195     computenodeid=`maas maas nodes new autodetect_nodegroup='yes' name='node2-compute' tags='compute' hostname='node2-compute' power_type='virsh' mac_addresses=$node2computemac power_parameters_power_address='qemu+ssh://'$USER'@192.168.122.1/system' architecture='amd64/generic' power_parameters_power_id='node2-compute' | grep system_id | cut -d '"' -f 4 `
196
197     maas maas tag update-nodes compute add=$computenodeid
198
199     computenodeid=`maas maas nodes new autodetect_nodegroup='yes' name='node5-compute' tags='compute' hostname='node5-compute' power_type='virsh' mac_addresses=$node5computemac power_parameters_power_address='qemu+ssh://'$USER'@192.168.122.1/system' architecture='amd64/generic' power_parameters_power_id='node5-compute' | grep system_id | cut -d '"' -f 4 `
200
201     maas maas tag update-nodes compute add=$computenodeid
202 fi
203
204 # Enable vlan interfaces with maas
205 case "$1" in
206     'intelpod5' )
207         maas refresh
208         enableautomodebyname eth4 AUTO "10.5.12.0/24" compute || true
209         enableautomodebyname eth4 AUTO "10.5.12.0/24" control || true
210         ;;
211     'intelpod6' )
212         maas refresh
213         enableautomodebyname eth4 AUTO "10.6.12.0/24" compute || true
214         enableautomodebyname eth4 AUTO "10.6.12.0/24" control || true
215         ;;
216     'intelpod9' )
217         maas refresh
218         crvlanupdsubnet vlan902 1 "DataNetwork" 902 2 || true
219         crvlanupdsubnet vlan905 2 "PublicNetwork" 905 3 || true
220         crnodevlanint $vlan902 eth0 || true
221         crnodevlanint $vlan905 eth1 || true
222         enableautomodebyname eth0.902 AUTO "10.9.12.0/24" compute || true
223         enableautomodebyname eth1.905 AUTO "10.9.15.0/24" compute || true
224         enableautomodebyname eth0.902 AUTO "10.9.12.0/24" control || true
225         enableautomodebyname eth1.905 AUTO "10.9.15.0/24" control || true
226         ;;
227     'orangepod1' )
228         maas refresh
229         enableautomodebyname eth2 DHCP "192.168.21.0/24" compute || true
230         enableautomodebyname eth3 AUTO "192.168.11.0/24" compute || true
231         enableautomodebyname eth2 DHCP "192.168.21.0/24" control || true
232         enableautomodebyname eth3 AUTO "192.168.11.0/24" control || true
233         ;;
234     'orangepod2' )
235         maas refresh
236         enableautomodebyname eth4 DHCP "192.168.22.0/24" compute || true
237         enableautomodebyname eth5 AUTO "192.168.12.0/24" compute || true
238         enableautomodebyname eth2 DHCP "192.168.22.0/24" control || true
239         enableautomodebyname eth3 AUTO "192.168.12.0/24" control || true
240         ;;
241     'attvirpod1' )
242         enableautomodebyname eth1 AUTO "192.168.10.0/24" control || true
243         ;;
244     'juniperpod1' )
245         ;;
246     'cengnlynxpod1' )
247         maas refresh
248         crvlanupdsubnet vlan1201 1 "DataNetwork" 1201 2 || true
249         crvlanupdsubnet vlan1202 2 "PublicNetwork" 1202 3 || true
250         crnodevlanint $vlan1201 eth1 || true
251         crnodevlanint $vlan1202 eth1 || true
252         enableautomode eth1.1201 AUTO "172.16.121.3/24" compute || true
253         enableautomode eth1.1201 AUTO "172.16.121.3/24" control || true
254         ;;
255 esac
256
257 echo " .... MAAS deployment finished successfully ...."
258
259 #echo "... Deployment of opnfv release Started ...."
260 #python deploy.py $maas_ip