2 #placeholder for deployment script.
8 #install the packages needed
9 sudo apt-add-repository ppa:opnfv-team/proposed -y
10 sudo apt-add-repository ppa:maas-deployers/stable -y
11 sudo apt-add-repository ppa:juju/stable -y
12 sudo apt-add-repository ppa:maas/stable -y
13 sudo apt-add-repository cloud-archive:mitaka -y
14 sudo apt-get update -y
15 sudo apt-get dist-upgrade -y
16 sudo pip install --upgrade pip
17 sudo apt-get install openssh-server bzr git maas-deployer juju juju-deployer \
18 maas-cli python-pip python-psutil python-openstackclient \
19 python-congressclient gsutil charm-tools pastebinit -y
21 #first parameter should be custom and second should be either
22 # absolute location of file (including file name) or url of the
32 # Get labconfig and generate deployment.yaml for MAAS and deployconfig.yaml
34 intelpod[569]|orangepod[12]|cengnpod[12] )
35 array=(${labname//pod/ })
36 cp ../labconfig/${array[0]}/pod${array[1]}/labconfig.yaml .
37 python genMAASConfig.py -l labconfig.yaml > deployment.yaml
38 python genDeploymentConfig.py -l labconfig.yaml > deployconfig.yaml
41 cp ../labconfig/att/virpod1/labconfig.yaml .
42 python genMAASConfig.py -l labconfig.yaml > deployment.yaml
43 python genDeploymentConfig.py -l labconfig.yaml > deployconfig.yaml
46 cp maas/juniper/pod1/deployment.yaml ./deployment.yaml
49 if [ -e $labfile ]; then
50 cp $labfile ./labconfig.yaml || true
52 wget $labconfigfile -t 3 -T 10 -O ./labconfig.yaml || true
53 count=`wc -l labconfig.yaml | cut -d " " -f 1`
54 if [ $count -lt 10 ]; then
58 if [ ! -e ./labconfig.yaml ]; then
61 python genMAASConfig.py -l labconfig.yaml > deployment.yaml
62 python genDeploymentConfig.py -l labconfig.yaml > deployconfig.yaml
63 labname=`grep "maas_name" deployment.yaml | cut -d ':' -f 2 | sed -e 's/ //'`
71 # In the case of a virtual deployment get deployment.yaml and deployconfig.yaml
72 if [ "$virtinstall" -eq 1 ]; then
75 cp ../labconfig/default/deployment.yaml ./
76 cp ../labconfig/default/labconfig.yaml ./
77 cp ../labconfig/default/deployconfig.yaml ./
81 # Prepare local environment to avoid password asking
84 # make sure no password asked during the deployment.
85 echo "$USER ALL=(ALL) NOPASSWD:ALL" > 90-joid-init
87 if [ -e /etc/sudoers.d/90-joid-init ]; then
88 sudo cp /etc/sudoers.d/90-joid-init 91-joid-init
89 sudo chown $USER:$USER 91-joid-init
90 sudo chmod 660 91-joid-init
91 sudo cat 90-joid-init >> 91-joid-init
92 sudo chown root:root 91-joid-init
93 sudo mv 91-joid-init /etc/sudoers.d/
95 sudo chown root:root 90-joid-init
96 sudo mv 90-joid-init /etc/sudoers.d/
99 if [ ! -e $HOME/.ssh/id_rsa ]; then
100 ssh-keygen -N '' -f $HOME/.ssh/id_rsa
103 echo "... Deployment of maas Started ...."
109 # define the pool and try to start even though its already exist.
110 # For fresh install this may or may not there.
111 sudo apt-get install libvirt-bin -y
112 sudo adduser $USER libvirtd
113 sudo virsh pool-define-as default --type dir --target /var/lib/libvirt/images/ || true
114 sudo virsh pool-start default || true
115 sudo virsh pool-autostart default || true
117 # In case of virtual install set network
118 if [ "$virtinstall" -eq 1 ]; then
119 sudo virsh net-dumpxml default > default-net-org.xml
120 sudo sed -i '/dhcp/d' default-net-org.xml
121 sudo sed -i '/range/d' default-net-org.xml
122 sudo virsh net-define default-net-org.xml
123 sudo virsh net-destroy default
124 sudo virsh net-start default
127 # Ensure virsh can connect without ssh auth
128 cat $HOME/.ssh/id_rsa.pub >> $HOME/.ssh/authorized_keys
132 # Cleanup, juju init and config backup
135 # To avoid problem between apiclient/maas_client and apiclient from google
136 # we remove the package google-api-python-client from yardstick installer
137 if [ $(pip list |grep google-api-python-client |wc -l) == 1 ]; then
138 sudo pip uninstall google-api-python-client
141 #create backup directory
142 mkdir ~/joid_config/ || true
143 mkdir ~/.juju/ || true
152 sudo maas-deployer -c deployment.yaml -d --force
154 sudo chown $USER:$USER environments.yaml
156 echo "... Deployment of maas finish ...."
158 # Backup deployment.yaml and deployconfig.yaml in .juju folder
160 cp ./environments.yaml ~/.juju/
161 cp ./environments.yaml ~/joid_config/
163 if [ -e ./deployconfig.yaml ]; then
164 cp ./deployconfig.yaml ~/.juju/
165 cp ./labconfig.yaml ~/.juju/
166 cp ./deployconfig.yaml ~/joid_config/
167 cp ./labconfig.yaml ~/joid_config/
170 if [ -e ./deployment.yaml ]; then
171 cp ./deployment.yaml ~/.juju/
172 cp ./deployment.yaml ~/joid_config/
179 maas_ip=`grep " ip_address" deployment.yaml | cut -d ':' -f 2 | sed -e 's/ //'`
180 apikey=`grep maas-oauth: environments.yaml | cut -d "'" -f 2`
181 maas login maas http://${maas_ip}/MAAS/api/1.0 ${apikey}
182 maas maas sshkeys new key="`cat $HOME/.ssh/id_rsa.pub`"
184 #Added the Qtip public to run the Qtip test after install on bare metal nodes.
185 #maas maas sshkeys new key="`cat ./maas/sshkeys/QtipKey.pub`"
186 #maas maas sshkeys new key="`cat ./maas/sshkeys/DominoKey.pub`"
188 #adding compute and control nodes VM to MAAS for virtual deployment purpose.
189 if [ "$virtinstall" -eq 1 ]; then
190 # create two more VMs to do the deployment.
191 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
193 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
195 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
197 node1controlmac=`grep "mac address" node1-control | head -1 | cut -d "'" -f 2`
198 node2computemac=`grep "mac address" node2-compute | head -1 | cut -d "'" -f 2`
199 node5computemac=`grep "mac address" node5-compute | head -1 | cut -d "'" -f 2`
201 sudo virsh -c qemu:///system define --file node1-control
202 sudo virsh -c qemu:///system define --file node2-compute
203 sudo virsh -c qemu:///system define --file node5-compute
205 maas maas tags new name='control'
206 maas maas tags new name='compute'
208 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 `
210 maas maas tag update-nodes control add=$controlnodeid
212 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 `
214 maas maas tag update-nodes compute add=$computenodeid
216 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 `
218 maas maas tag update-nodes compute add=$computenodeid
222 # Functions for MAAS network customization
225 #Below function will mark the interfaces in Auto mode to enbled by MAAS
227 listofnodes=`maas maas nodes list | grep system_id | cut -d '"' -f 4`
228 for nodes in $listofnodes
230 maas maas interface link-subnet $nodes $1 mode=$2 subnet=$3
234 #Below function will mark the interfaces in Auto mode to enbled by MAAS
235 # using hostname of the node added into MAAS
236 enableautomodebyname() {
237 if [ ! -z "$4" ]; then
240 nodes=`maas maas nodes list | grep system_id | cut -d '"' -f 4`
241 if [ ! -z "$nodes" ]; then
242 maas maas interface link-subnet $nodes $1 mode=$2 subnet=$3
248 #Below function will create vlan and update interface with the new vlan
249 # will return the vlan id created
251 newvlanid=`maas maas vlans create $2 name=$3 vid=$4 | grep resource | cut -d '/' -f 6 `
252 maas maas subnet update $5 vlan=$newvlanid
253 eval "$1"="'$newvlanid'"
256 #Below function will create interface with new vlan and bind to physical interface
258 listofnodes=`maas maas nodes list | grep system_id | cut -d '"' -f 4`
260 for nodes in $listofnodes
262 parentid=`maas maas interface read $nodes $2 | grep interfaces | cut -d '/' -f 8`
263 maas maas interfaces create-vlan $nodes vlan=$1 parent=$parentid
267 #function for JUJU envronment
270 controllername=`awk 'NR==1{print $2}' environments.yaml`
271 cloudname=`awk 'NR==1{print $2}' environments.yaml`
273 echo "credentials:" > credential.yaml
274 echo " $controllername:" >> credential.yaml
275 echo " opnfv-credentials:" >> credential.yaml
276 echo " auth-type: oauth1" >> credential.yaml
277 echo " maas-oauth: $apikey" >> credential.yaml
279 juju add-credential $controllername -f credential.yaml --replace
283 controllername=`awk 'NR==1{print $2}' environments.yaml`
284 cloudname=`awk 'NR==1{print $2}' environments.yaml`
286 echo "clouds:" > maas-cloud.yaml
287 echo " $cloudname:" >> maas-cloud.yaml
288 echo " type: maas" >> maas-cloud.yaml
289 echo " auth-types: [oauth1]" >> maas-cloud.yaml
290 echo " endpoint: http://$maas_ip/MAAS" >> maas-cloud.yaml
292 juju add-cloud $cloudname maas-cloud.yaml --replace
303 crvlanupdsubnet vlan904 fabric-1 "MgmtNetwork" 904 2 || true
304 crvlanupdsubnet vlan905 fabric-2 "PublicNetwork" 905 3 || true
305 crnodevlanint $vlan905 eth1 || true
306 crnodevlanint $vlan905 eth3 || true
307 enableautomodebyname eth1.905 AUTO "10.9.15.0/24" || true
308 enableautomodebyname eth3.905 AUTO "10.9.15.0/24" || true
309 enableautomodebyname eth0 AUTO "10.9.12.0/24" || true
310 enableautomodebyname eth2 AUTO "10.9.12.0/24" || true
315 # Enable MAAS nodes interfaces
318 #read interface needed in Auto mode and enable it. Will be rmeoved once auto enablement will be implemented in the maas-deployer.
319 if [ -e ~/joid_config/deployconfig.yaml ]; then
320 cp ~/joid_config/deployconfig.yaml ./deployconfig.yaml
321 elif [ -e ~/.juju/deployconfig.yaml ]; then
322 cp ~/.juju/deployconfig.yaml ./deployconfig.yaml
325 if [ -e ./deployconfig.yaml ]; then
326 enableiflist=`grep "interface-enable" deployconfig.yaml | cut -d ' ' -f 4 `
327 datanet=`grep "dataNetwork" deployconfig.yaml | cut -d ' ' -f 4 | sed -e 's/ //'`
328 stornet=`grep "storageNetwork" deployconfig.yaml | cut -d ' ' -f 4 | sed -e 's/ //'`
329 pubnet=`grep "publicNetwork" deployconfig.yaml | cut -d ' ' -f 4 | sed -e 's/ //'`
331 # split EXTERNAL_NETWORK=first ip;last ip; gateway;network
333 if [ "$datanet" != "''" ]; then
334 EXTNET=(${enableiflist//,/ })
336 while [ ! -z "${EXTNET[i]}" ];
338 enableautomode ${EXTNET[i]} AUTO $datanet || true
342 if [ "$stornet" != "''" ]; then
343 EXTNET=(${enableiflist//,/ })
345 while [ ! -z "${EXTNET[i]}" ];
347 enableautomode ${EXTNET[i]} AUTO $stornet || true
351 if [ "$pubnet" != "''" ]; then
352 EXTNET=(${enableiflist//,/ })
354 while [ ! -z "${EXTNET[i]}" ];
356 enableautomode ${EXTNET[i]} AUTO $pubnet || true
363 # Add the cloud and controller credentials for MAAS for that lab.
364 jujuver=`juju --version`
366 if [[ "$jujuver" > "2" ]]; then
374 echo " .... MAAS deployment finished successfully ...."