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