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