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