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 apt-get install openssh-server bzr git maas-deployer juju juju-deployer \
17 maas-cli python-pip python-psutil python-openstackclient \
18 python-congressclient gsutil charm-tools pastebinit juju-core -y
20 #first parameter should be custom and second should be either
21 # absolute location of file (including file name) or url of the
31 # Get labconfig and generate deployment.yaml for MAAS and deployconfig.yaml
33 intelpod[569]|orangepod[12]|cengnpod[12] )
34 array=(${labname//pod/ })
35 cp ../labconfig/${array[0]}/pod${array[1]}/labconfig.yaml .
36 python genMAASConfig.py -l labconfig.yaml > deployment.yaml
37 python genDeploymentConfig.py -l labconfig.yaml > deployconfig.yaml
40 cp ../labconfig/att/virpod1/labconfig.yaml .
41 python genMAASConfig.py -l labconfig.yaml > deployment.yaml
42 python genDeploymentConfig.py -l labconfig.yaml > deployconfig.yaml
45 cp maas/juniper/pod1/deployment.yaml ./deployment.yaml
48 if [ -e $labfile ]; then
49 cp $labfile ./labconfig.yaml || true
51 wget $labconfigfile -t 3 -T 10 -O ./labconfig.yaml || true
52 count=`wc -l labconfig.yaml | cut -d " " -f 1`
53 if [ $count -lt 10 ]; then
57 if [ ! -e ./labconfig.yaml ]; then
60 python genMAASConfig.py -l labconfig.yaml > deployment.yaml
61 python genDeploymentConfig.py -l labconfig.yaml > deployconfig.yaml
62 labname=`grep "maas_name" deployment.yaml | cut -d ':' -f 2 | sed -e 's/ //'`
70 # In the case of a virtual deployment get deployment.yaml and deployconfig.yaml
71 if [ "$virtinstall" -eq 1 ]; then
74 cp ../labconfig/default/deployment.yaml ./
75 cp ../labconfig/default/labconfig.yaml ./
76 cp ../labconfig/default/deployconfig.yaml ./
80 # Prepare local environment to avoid password asking
83 # make sure no password asked during the deployment.
84 echo "$USER ALL=(ALL) NOPASSWD:ALL" > 90-joid-init
86 if [ -e /etc/sudoers.d/90-joid-init ]; then
87 sudo cp /etc/sudoers.d/90-joid-init 91-joid-init
88 sudo chown $USER:$USER 91-joid-init
89 sudo chmod 660 91-joid-init
90 sudo cat 90-joid-init >> 91-joid-init
91 sudo chown root:root 91-joid-init
92 sudo mv 91-joid-init /etc/sudoers.d/
94 sudo chown root:root 90-joid-init
95 sudo mv 90-joid-init /etc/sudoers.d/
98 if [ ! -e $HOME/.ssh/id_rsa ]; then
99 ssh-keygen -N '' -f $HOME/.ssh/id_rsa
102 echo "... Deployment of maas Started ...."
108 # define the pool and try to start even though its already exist.
109 # For fresh install this may or may not there.
110 sudo apt-get install libvirt-bin -y
111 sudo adduser $USER libvirtd
112 sudo virsh pool-define-as default --type dir --target /var/lib/libvirt/images/ || true
113 sudo virsh pool-start default || true
114 sudo virsh pool-autostart default || true
116 # In case of virtual install set network
117 if [ "$virtinstall" -eq 1 ]; then
118 sudo virsh net-dumpxml default > default-net-org.xml
119 sudo sed -i '/dhcp/d' default-net-org.xml
120 sudo sed -i '/range/d' default-net-org.xml
121 sudo virsh net-define default-net-org.xml
122 sudo virsh net-destroy default
123 sudo virsh net-start default
126 # Ensure virsh can connect without ssh auth
127 cat $HOME/.ssh/id_rsa.pub >> $HOME/.ssh/authorized_keys
131 # Cleanup, juju init and config backup
134 # To avoid problem between apiclient/maas_client and apiclient from google
135 # we remove the package google-api-python-client from yardstick installer
136 if [ $(pip list |grep google-api-python-client |wc -l) == 1 ]; then
137 sudo pip uninstall google-api-python-client
140 #create backup directory
141 mkdir ~/joid_config/ || true
142 mkdir ~/.juju/ || true
152 sudo apt-get install maas -y
158 sudo maas createadmin --username=ubuntu --email=ubuntu@ubuntu.com
166 sudo maas-deployer -c deployment.yaml -d --force
168 sudo chown $USER:$USER environments.yaml
170 echo "... Deployment of maas finish ...."
172 # Backup deployment.yaml and deployconfig.yaml in .juju folder
174 cp ./environments.yaml ~/.juju/
175 cp ./environments.yaml ~/joid_config/
177 if [ -e ./deployconfig.yaml ]; then
178 cp ./deployconfig.yaml ~/.juju/
179 cp ./labconfig.yaml ~/.juju/
180 cp ./deployconfig.yaml ~/joid_config/
181 cp ./labconfig.yaml ~/joid_config/
184 if [ -e ./deployment.yaml ]; then
185 cp ./deployment.yaml ~/.juju/
186 cp ./deployment.yaml ~/joid_config/
193 maas_ip=`grep " ip_address" deployment.yaml | cut -d ':' -f 2 | sed -e 's/ //'`
194 apikey=`grep maas-oauth: environments.yaml | cut -d "'" -f 2`
195 maas login maas http://${maas_ip}/MAAS/api/1.0 ${apikey}
196 maas maas sshkeys new key="`cat $HOME/.ssh/id_rsa.pub`"
198 #Added the Qtip public to run the Qtip test after install on bare metal nodes.
199 #maas maas sshkeys new key="`cat ./maas/sshkeys/QtipKey.pub`"
200 #maas maas sshkeys new key="`cat ./maas/sshkeys/DominoKey.pub`"
202 #adding compute and control nodes VM to MAAS for virtual deployment purpose.
203 if [ "$virtinstall" -eq 1 ]; then
204 # create two more VMs to do the deployment.
205 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
207 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
209 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
211 node1controlmac=`grep "mac address" node1-control | head -1 | cut -d "'" -f 2`
212 node2computemac=`grep "mac address" node2-compute | head -1 | cut -d "'" -f 2`
213 node5computemac=`grep "mac address" node5-compute | head -1 | cut -d "'" -f 2`
215 sudo virsh -c qemu:///system define --file node1-control
216 sudo virsh -c qemu:///system define --file node2-compute
217 sudo virsh -c qemu:///system define --file node5-compute
219 maas maas tags new name='control'
220 maas maas tags new name='compute'
222 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 `
224 maas maas tag update-nodes control add=$controlnodeid
226 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 `
228 maas maas tag update-nodes compute add=$computenodeid
230 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 `
232 maas maas tag update-nodes compute add=$computenodeid
236 # Functions for MAAS network customization
239 #Below function will mark the interfaces in Auto mode to enbled by MAAS
241 listofnodes=`maas maas nodes list | grep system_id | cut -d '"' -f 4`
242 for nodes in $listofnodes
244 maas maas interface link-subnet $nodes $1 mode=$2 subnet=$3
248 #Below function will mark the interfaces in Auto mode to enbled by MAAS
249 # using hostname of the node added into MAAS
250 enableautomodebyname() {
251 if [ ! -z "$4" ]; then
254 nodes=`maas maas nodes list | grep system_id | cut -d '"' -f 4`
255 if [ ! -z "$nodes" ]; then
256 maas maas interface link-subnet $nodes $1 mode=$2 subnet=$3
262 #Below function will create vlan and update interface with the new vlan
263 # will return the vlan id created
265 newvlanid=`maas maas vlans create $2 name=$3 vid=$4 | grep resource | cut -d '/' -f 6 `
266 maas maas subnet update $5 vlan=$newvlanid
267 eval "$1"="'$newvlanid'"
270 #Below function will create interface with new vlan and bind to physical interface
272 listofnodes=`maas maas nodes list | grep system_id | cut -d '"' -f 4`
274 for nodes in $listofnodes
276 parentid=`maas maas interface read $nodes $2 | grep interfaces | cut -d '/' -f 8`
277 maas maas interfaces create-vlan $nodes vlan=$1 parent=$parentid
281 #function for JUJU envronment
284 controllername=`awk 'NR==1{print $2}' environments.yaml`
285 cloudname=`awk 'NR==1{print $2}' environments.yaml`
287 echo "credentials:" > credential.yaml
288 echo " $controllername:" >> credential.yaml
289 echo " opnfv-credentials:" >> credential.yaml
290 echo " auth-type: oauth1" >> credential.yaml
291 echo " maas-oauth: $apikey" >> credential.yaml
293 juju add-credential $controllername -f credential.yaml --replace
297 controllername=`awk 'NR==1{print $2}' environments.yaml`
298 cloudname=`awk 'NR==1{print $2}' environments.yaml`
300 echo "clouds:" > maas-cloud.yaml
301 echo " $cloudname:" >> maas-cloud.yaml
302 echo " type: maas" >> maas-cloud.yaml
303 echo " auth-types: [oauth1]" >> maas-cloud.yaml
304 echo " endpoint: http://$maas_ip/MAAS" >> maas-cloud.yaml
306 juju add-cloud $cloudname maas-cloud.yaml --replace
317 crvlanupdsubnet vlan904 fabric-1 "MgmtNetwork" 904 2 || true
318 crvlanupdsubnet vlan905 fabric-2 "PublicNetwork" 905 3 || true
319 crnodevlanint $vlan905 eth1 || true
320 crnodevlanint $vlan905 eth3 || true
321 enableautomodebyname eth1.905 AUTO "10.9.15.0/24" || true
322 enableautomodebyname eth3.905 AUTO "10.9.15.0/24" || true
323 enableautomodebyname eth0 AUTO "10.9.12.0/24" || true
324 enableautomodebyname eth2 AUTO "10.9.12.0/24" || true
329 # Enable MAAS nodes interfaces
332 #read interface needed in Auto mode and enable it. Will be rmeoved once auto enablement will be implemented in the maas-deployer.
333 if [ -e ~/joid_config/deployconfig.yaml ]; then
334 cp ~/joid_config/deployconfig.yaml ./deployconfig.yaml
335 elif [ -e ~/.juju/deployconfig.yaml ]; then
336 cp ~/.juju/deployconfig.yaml ./deployconfig.yaml
339 enableiflist=`grep "interface-enable" deployconfig.yaml | cut -d ' ' -f 4 `
340 datanet=`grep "dataNetwork" deployconfig.yaml | cut -d ' ' -f 4 | sed -e 's/ //'`
341 stornet=`grep "storageNetwork" deployconfig.yaml | cut -d ' ' -f 4 | sed -e 's/ //'`
342 pubnet=`grep "publicNetwork" deployconfig.yaml | cut -d ' ' -f 4 | sed -e 's/ //'`
344 # split EXTERNAL_NETWORK=first ip;last ip; gateway;network
346 if [ "$datanet" != "''" ]; then
347 EXTNET=(${enableiflist//,/ })
349 while [ ! -z "${EXTNET[i]}" ];
351 enableautomode ${EXTNET[i]} AUTO $datanet || true
355 if [ "$stornet" != "''" ]; then
356 EXTNET=(${enableiflist//,/ })
358 while [ ! -z "${EXTNET[i]}" ];
360 enableautomode ${EXTNET[i]} AUTO $stornet || true
364 if [ "$pubnet" != "''" ]; then
365 EXTNET=(${enableiflist//,/ })
367 while [ ! -z "${EXTNET[i]}" ];
369 enableautomode ${EXTNET[i]} AUTO $pubnet || true
376 # Add the cloud and controller credentials for MAAS for that lab.
377 jujuver=`juju --version`
379 if [ "$jujuver" > "2" ]; then
387 echo " .... MAAS deployment finished successfully ...."