Sergio Slobodrian | ee4b2bc | 2017-06-05 10:08:59 -0400 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
Sergio Slobodrian | 7c48362 | 2017-06-13 15:51:34 -0400 | [diff] [blame] | 3 | |
Sergio Slobodrian | c547771 | 2017-06-07 11:56:56 -0400 | [diff] [blame] | 4 | iVmName="vInstaller" |
Sergio Slobodrian | ba9cbd8 | 2017-06-22 11:45:49 -0400 | [diff] [blame] | 5 | vVmName="voltha_voltha" |
Sergio Slobodrian | 7c48362 | 2017-06-13 15:51:34 -0400 | [diff] [blame] | 6 | baseImage="Ubuntu1604LTS" |
Sergio Slobodrian | ee4b2bc | 2017-06-05 10:08:59 -0400 | [diff] [blame] | 7 | iVmNetwork="vagrant-libvirt" |
Sergio Slobodrian | c547771 | 2017-06-07 11:56:56 -0400 | [diff] [blame] | 8 | installerArchive="installer.tar.bz2" |
| 9 | installerDirectory="volthaInstaller" |
| 10 | installerPart="installer.part" |
Sergio Slobodrian | ee4b2bc | 2017-06-05 10:08:59 -0400 | [diff] [blame] | 11 | shutdownTimeout=5 |
| 12 | ipTimeout=10 |
| 13 | |
Sergio Slobodrian | f74fa07 | 2017-06-28 09:33:24 -0400 | [diff] [blame] | 14 | # Command line argument variables |
| 15 | testMode="no" |
Sergio Slobodrian | cab0a39 | 2017-07-13 08:42:10 -0400 | [diff] [blame] | 16 | rebuildVoltha="no" |
Stephane Barbarie | 2cbffca | 2018-03-26 16:20:03 -0400 | [diff] [blame] | 17 | useKubernetes="no" |
Sergio Slobodrian | f74fa07 | 2017-06-28 09:33:24 -0400 | [diff] [blame] | 18 | |
| 19 | |
| 20 | |
Sergio Slobodrian | ee4b2bc | 2017-06-05 10:08:59 -0400 | [diff] [blame] | 21 | lBlue='\033[1;34m' |
| 22 | green='\033[0;32m' |
| 23 | orange='\033[0;33m' |
| 24 | NC='\033[0m' |
| 25 | red='\033[0;31m' |
| 26 | yellow='\033[1;33m' |
| 27 | dGrey='\033[1;30m' |
| 28 | lGrey='\033[1;37m' |
| 29 | lCyan='\033[1;36m' |
| 30 | |
Sergio Slobodrian | 7c48362 | 2017-06-13 15:51:34 -0400 | [diff] [blame] | 31 | uId=`id -u` |
Sergio Slobodrian | ee4b2bc | 2017-06-05 10:08:59 -0400 | [diff] [blame] | 32 | wd=`pwd` |
| 33 | |
Sergio Slobodrian | f74fa07 | 2017-06-28 09:33:24 -0400 | [diff] [blame] | 34 | parse_args() |
| 35 | { |
| 36 | for i in $@ |
| 37 | do |
| 38 | case "$i" in |
| 39 | "test" ) |
| 40 | testMode="yes" |
| 41 | echo -e "${lBlue}Test mode is ${green}enabled${NC}" |
| 42 | ;; |
Sergio Slobodrian | cab0a39 | 2017-07-13 08:42:10 -0400 | [diff] [blame] | 43 | "rebuild" ) |
| 44 | rebuildVoltha="yes" |
| 45 | echo -e "${lBlue}Voltha rebuild is ${green}enabled${NC}" |
| 46 | ;; |
Stephane Barbarie | 2cbffca | 2018-03-26 16:20:03 -0400 | [diff] [blame] | 47 | "k8s" ) |
| 48 | useKubernetes="yes" |
| 49 | echo -e "${lBlue}Kubernetes framework is ${green}enabled${NC}" |
| 50 | ;; |
Sergio Slobodrian | f74fa07 | 2017-06-28 09:33:24 -0400 | [diff] [blame] | 51 | esac |
| 52 | done |
| 53 | } |
| 54 | |
| 55 | |
| 56 | ###################################### |
| 57 | # MAIN MAIN MAIN MAIN MAIN MAIN MAIN # |
| 58 | ###################################### |
| 59 | parse_args $@ |
Sergio Slobodrian | ee4b2bc | 2017-06-05 10:08:59 -0400 | [diff] [blame] | 60 | # Validate that vagrant is installed. |
| 61 | echo -e "${lBlue}Ensure that ${lCyan}vagrant${lBlue} is installed${NC}" |
| 62 | vInst=`which vagrant` |
| 63 | |
| 64 | if [ -z "$vInst" ]; then |
| 65 | wget https://releases.hashicorp.com/vagrant/1.9.5/vagrant_1.9.5_x86_64.deb |
| 66 | sudo dpkg -i vagrant_1.8.5_x86_64.deb |
| 67 | rm vagrant_1.8.5_x86_64.deb |
| 68 | fi |
| 69 | unset vInst |
| 70 | |
| 71 | # Validate that ansible is installed |
| 72 | echo -e "${lBlue}Ensure that ${lCyan}ansible${lBlue} is installed${NC}" |
| 73 | aInst=`which ansible` |
| 74 | |
| 75 | if [ -z "$aInst" ]; then |
Sergio Slobodrian | c547771 | 2017-06-07 11:56:56 -0400 | [diff] [blame] | 76 | sudo apt-get install -y software-properties-common |
Sergio Slobodrian | ee4b2bc | 2017-06-05 10:08:59 -0400 | [diff] [blame] | 77 | sudo apt-add-repository ppa:ansible/ansible |
| 78 | sudo apt-get update |
Sergio Slobodrian | c547771 | 2017-06-07 11:56:56 -0400 | [diff] [blame] | 79 | sudo apt-get install -y ansible |
Sergio Slobodrian | ee4b2bc | 2017-06-05 10:08:59 -0400 | [diff] [blame] | 80 | fi |
| 81 | unset vInst |
| 82 | |
Sergio Slobodrian | 6128779 | 2017-06-27 12:14:05 -0400 | [diff] [blame] | 83 | # Verify if this is intended to be a test environment, if so |
| 84 | # configure the 3 VMs which will be started later to emulate |
| 85 | # the production installation cluster. |
Sergio Slobodrian | f74fa07 | 2017-06-28 09:33:24 -0400 | [diff] [blame] | 86 | if [ "$testMode" == "yes" ]; then |
| 87 | echo -e "${lBlue}Test mode ${green}enabled${lBlue}, configure the ${lCyan}ha-serv${lBlue} VMs${NC}" |
Sergio Slobodrian | 7c48362 | 2017-06-13 15:51:34 -0400 | [diff] [blame] | 88 | # Update the vagrant settings file |
| 89 | sed -i -e '/server_name/s/.*/server_name: "ha-serv'${uId}'-"/' settings.vagrant.yaml |
| 90 | sed -i -e '/docker_push_registry/s/.*/docker_push_registry: "vinstall'${uId}':5000"/' ansible/group_vars/all |
| 91 | sed -i -e "/vinstall/s/vinstall/vinstall${uId}/" ../ansible/roles/docker/templates/daemon.json |
| 92 | |
| 93 | # Set the insecure registry configuration based on the installer hostname |
Sergio Slobodrian | f74fa07 | 2017-06-28 09:33:24 -0400 | [diff] [blame] | 94 | echo -e "${lBlue}Set up the insecure registry config for hostname ${lCyan}vinstall${uId}${NC}" |
Sergio Slobodrian | 7c48362 | 2017-06-13 15:51:34 -0400 | [diff] [blame] | 95 | echo '{' > ansible/roles/voltha/templates/daemon.json |
| 96 | echo '"insecure-registries" : ["vinstall'${uId}':5000"]' >> ansible/roles/voltha/templates/daemon.json |
| 97 | echo '}' >> ansible/roles/voltha/templates/daemon.json |
| 98 | |
Sergio Slobodrian | 7c48362 | 2017-06-13 15:51:34 -0400 | [diff] [blame] | 99 | # Change the installer name |
| 100 | iVmName="vInstaller${uId}" |
Sergio Slobodrian | ee4b2bc | 2017-06-05 10:08:59 -0400 | [diff] [blame] | 101 | else |
| 102 | rm -fr .test |
Sergio Slobodrian | c547771 | 2017-06-07 11:56:56 -0400 | [diff] [blame] | 103 | # Clean out the install config file keeping only the commented lines |
| 104 | # which serve as documentation. |
| 105 | sed -i -e '/^#/!d' install.cfg |
Sergio Slobodrian | 7c48362 | 2017-06-13 15:51:34 -0400 | [diff] [blame] | 106 | # Set the insecure registry configuration based on the installer hostname |
Sergio Slobodrian | 497e6e8 | 2017-07-18 15:10:38 -0400 | [diff] [blame] | 107 | echo -e "${lBlue}Set up the inescure registry config for hostname ${lCyan}vinstall${NC}" |
Sergio Slobodrian | ba9cbd8 | 2017-06-22 11:45:49 -0400 | [diff] [blame] | 108 | sed -i -e '/docker_push_registry/s/.*/docker_push_registry: "vinstall:5000"/' ansible/group_vars/all |
Sergio Slobodrian | 7c48362 | 2017-06-13 15:51:34 -0400 | [diff] [blame] | 109 | echo '{' > ansible/roles/voltha/templates/daemon.json |
| 110 | echo '"insecure-registries" : ["vinstall:5000"]' >> ansible/roles/voltha/templates/daemon.json |
| 111 | echo '}' >> ansible/roles/voltha/templates/daemon.json |
Sergio Slobodrian | ee4b2bc | 2017-06-05 10:08:59 -0400 | [diff] [blame] | 112 | fi |
| 113 | |
Sergio Slobodrian | 73e311a | 2017-07-26 11:12:45 -0400 | [diff] [blame] | 114 | # Check to make sure that the vagrant-libvirt network is both defined and started |
| 115 | echo -e "${lBlue}Verify tha the ${lCyan}vagrant-libvirt${lBlue} network is defined and started${NC}" |
Sergio Slobodrian | 7c5e885 | 2017-07-31 20:17:14 -0400 | [diff] [blame] | 116 | virsh net-list --all | grep "vagrant-libvirt" > /dev/null |
Sergio Slobodrian | 73e311a | 2017-07-26 11:12:45 -0400 | [diff] [blame] | 117 | rtrn=$? |
| 118 | if [ $rtrn -eq 1 ]; then |
Sergio Slobodrian | 7c5e885 | 2017-07-31 20:17:14 -0400 | [diff] [blame] | 119 | # Not defined |
| 120 | echo -e "${lBlue}Defining the ${lCyan}vagrant-libvirt${lBlue} network${NC}" |
| 121 | virsh net-define vagrant-libvirt.xml |
| 122 | echo -e "${lBlue}Starting the ${lCyan}vagrant-libvirt${lBlue} network${NC}" |
| 123 | virsh net-start vagrant-libvirt |
| 124 | else |
| 125 | virsh net-list | grep "vagrant-libvirt" > /dev/null |
Sergio Slobodrian | 73e311a | 2017-07-26 11:12:45 -0400 | [diff] [blame] | 126 | rtrn=$? |
| 127 | if [ $rtrn -eq 1 ]; then |
Sergio Slobodrian | 73e311a | 2017-07-26 11:12:45 -0400 | [diff] [blame] | 128 | # Defined but not started |
| 129 | echo -e "${lBlue}Starting the ${lCyan}vagrant-libvirt${lBlue} network${NC}" |
| 130 | virsh net-start vagrant-libvirt |
Sergio Slobodrian | 7c5e885 | 2017-07-31 20:17:14 -0400 | [diff] [blame] | 131 | |
| 132 | else |
| 133 | # Defined and running |
| 134 | echo -e "${lBlue}The ${lCyan}vagrant-libvirt${lBlue} network is ${green} running${NC}" |
Sergio Slobodrian | 73e311a | 2017-07-26 11:12:45 -0400 | [diff] [blame] | 135 | fi |
Sergio Slobodrian | 7c5e885 | 2017-07-31 20:17:14 -0400 | [diff] [blame] | 136 | fi |
| 137 | |
| 138 | # Check that the default storage pool exists and create it if it doesn't |
| 139 | virsh pool-list --all | grep default > /dev/null |
| 140 | rtrn=$? |
| 141 | if [ $rtrn -eq 1 ]; then |
| 142 | # Not defined |
| 143 | echo -e "${lBlue}Defining the ${lCyan}defaul${lBlue} storage pool${NC}" |
| 144 | virsh pool-define-as --name default --type dir --target /var/lib/libvirt/images/ |
| 145 | virsh pool-autostart default |
| 146 | echo -e "${lBlue}Starting the ${lCyan}defaul${lBlue} storage pool${NC}" |
| 147 | virsh pool-start default |
Sergio Slobodrian | 73e311a | 2017-07-26 11:12:45 -0400 | [diff] [blame] | 148 | else |
Sergio Slobodrian | 7c5e885 | 2017-07-31 20:17:14 -0400 | [diff] [blame] | 149 | virsh pool-list | grep default > /dev/null |
| 150 | rtrn=$? |
| 151 | if [ $rtrn -eq 1 ]; then |
| 152 | # Defined but not started |
| 153 | echo -e "${lBlue}Starting the ${lCyan}defaul${lBlue} storage pool${NC}" |
| 154 | virsh pool-start default |
| 155 | else |
| 156 | # Defined and running |
| 157 | echo -e "${lBlue}The ${lCyan}default${lBlue} storage pool ${green} running${NC}" |
| 158 | fi |
Sergio Slobodrian | 73e311a | 2017-07-26 11:12:45 -0400 | [diff] [blame] | 159 | fi |
| 160 | |
Sergio Slobodrian | 7c48362 | 2017-06-13 15:51:34 -0400 | [diff] [blame] | 161 | |
Sergio Slobodrian | ee4b2bc | 2017-06-05 10:08:59 -0400 | [diff] [blame] | 162 | # Shut down the domain in case it's running. |
| 163 | echo -e "${lBlue}Shut down the ${lCyan}$iVmName${lBlue} VM if running${NC}" |
| 164 | ctr=0 |
| 165 | vStat=`virsh list | grep $iVmName` |
Sergio Slobodrian | c547771 | 2017-06-07 11:56:56 -0400 | [diff] [blame] | 166 | virsh shutdown $iVmName |
Sergio Slobodrian | ee4b2bc | 2017-06-05 10:08:59 -0400 | [diff] [blame] | 167 | while [ ! -z "$vStat" ]; |
| 168 | do |
Sergio Slobodrian | ee4b2bc | 2017-06-05 10:08:59 -0400 | [diff] [blame] | 169 | echo "Waiting for $iVmName to shut down" |
| 170 | sleep 2 |
Sergio Slobodrian | 497e6e8 | 2017-07-18 15:10:38 -0400 | [diff] [blame] | 171 | vStat=`virsh list | grep "$iVmName "` |
Sergio Slobodrian | ee4b2bc | 2017-06-05 10:08:59 -0400 | [diff] [blame] | 172 | ctr=`expr $ctr + 1` |
| 173 | if [ $ctr -eq $shutdownTimeout ]; then |
| 174 | echo -e "${red}Tired of waiting, forcing the VM off${NC}" |
| 175 | virsh destroy $iVmName |
Sergio Slobodrian | 497e6e8 | 2017-07-18 15:10:38 -0400 | [diff] [blame] | 176 | vStat=`virsh list | grep "$iVmName "` |
Sergio Slobodrian | ee4b2bc | 2017-06-05 10:08:59 -0400 | [diff] [blame] | 177 | fi |
| 178 | done |
| 179 | |
| 180 | |
| 181 | # Delete the VM and ignore any errors should they occur |
| 182 | echo -e "${lBlue}Undefining the ${lCyan}$iVmName${lBlue} domain${NC}" |
| 183 | virsh undefine $iVmName |
| 184 | |
| 185 | # Remove the associated volume |
| 186 | echo -e "${lBlue}Removing the ${lCyan}$iVmName.qcow2${lBlue} volume${NC}" |
| 187 | virsh vol-delete "${iVmName}.qcow2" default |
| 188 | |
| 189 | # Clone the base vanilla ubuntu install |
| 190 | echo -e "${lBlue}Cloning the ${lCyan}$baseImage.qcow2${lBlue} to ${lCyan}$iVmName.qcow2${NC}" |
| 191 | virsh vol-clone "${baseImage}.qcow2" "${iVmName}.qcow2" default |
| 192 | |
| 193 | # Create the xml file and define the VM for virsh |
| 194 | echo -e "${lBlue}Defining the ${lCyan}$iVmName${lBlue} virtual machine${NC}" |
Sergio Slobodrian | c547771 | 2017-06-07 11:56:56 -0400 | [diff] [blame] | 195 | cat vmTemplate.xml | sed -e "s/{{ VMName }}/$iVmName/g" | sed -e "s/{{ VMNetwork }}/$iVmNetwork/g" > tmp.xml |
Sergio Slobodrian | ee4b2bc | 2017-06-05 10:08:59 -0400 | [diff] [blame] | 196 | |
| 197 | virsh define tmp.xml |
| 198 | |
| 199 | rm tmp.xml |
| 200 | |
| 201 | # Start the VMm, if it's already running just ignore the error |
| 202 | echo -e "${lBlue}Starting the ${lCyan}$iVmName${lBlue} virtual machine${NC}" |
| 203 | virsh start $iVmName > /dev/null 2>&1 |
| 204 | |
| 205 | # Generate a keypair for communicating with the VM |
| 206 | echo -e "${lBlue}Generating the key-pair for communication with the VM${NC}" |
| 207 | ssh-keygen -f ./key -t rsa -N '' |
| 208 | |
| 209 | mv key key.pem |
| 210 | |
| 211 | # Clone BashLogin.sh and add the public key to it for later use. |
| 212 | echo -e "${lBlue}Creating the pre-configuration script${NC}" |
| 213 | cp BashLogin.sh bash_login.sh |
| 214 | echo "cat <<HERE > .ssh/authorized_keys" >> bash_login.sh |
| 215 | cat key.pub >> bash_login.sh |
| 216 | echo "HERE" >> bash_login.sh |
| 217 | echo "chmod 400 .ssh/authorized_keys" >> bash_login.sh |
| 218 | echo "rm .bash_login" >> bash_login.sh |
| 219 | echo "logout" >> bash_login.sh |
| 220 | rm key.pub |
| 221 | |
| 222 | |
| 223 | |
| 224 | # Get the VM's IP address |
| 225 | ctr=0 |
| 226 | ipAddr="" |
| 227 | while [ -z "$ipAddr" ]; |
| 228 | do |
| 229 | echo -e "${lBlue}Waiting for the VM's IP address${NC}" |
| 230 | ipAddr=`virsh domifaddr $iVmName | tail -n +3 | awk '{ print $4 }' | sed -e 's~/.*~~'` |
| 231 | sleep 3 |
| 232 | if [ $ctr -eq $ipTimeout ]; then |
| 233 | echo -e "${red}Tired of waiting, please adjust the ipTimeout if the VM is slow to start${NC}" |
| 234 | exit |
| 235 | fi |
| 236 | ctr=`expr $ctr + 1` |
| 237 | done |
| 238 | |
| 239 | echo -e "${lBlue}The IP address is: ${lCyan}$ipAddr${NC}" |
| 240 | |
| 241 | # Copy the pre-config file to the VM |
| 242 | echo -e "${lBlue}Transfering pre-configuration script to the VM${NC}" |
| 243 | scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no bash_login.sh vinstall@$ipAddr:.bash_login |
| 244 | |
| 245 | rm bash_login.sh |
| 246 | |
| 247 | # Run the pre-config file on the VM |
| 248 | echo -e "${lBlue}Running the pre-configuration script on the VM${NC}" |
| 249 | ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no vinstall@$ipAddr |
| 250 | |
Sergio Slobodrian | 7c48362 | 2017-06-13 15:51:34 -0400 | [diff] [blame] | 251 | # If we're in test mode, change the hostname of the installer vm |
Sergio Slobodrian | 6128779 | 2017-06-27 12:14:05 -0400 | [diff] [blame] | 252 | # also start the 3 vagrant target VMs |
Sergio Slobodrian | f74fa07 | 2017-06-28 09:33:24 -0400 | [diff] [blame] | 253 | if [ "$testMode" == "yes" ]; then |
| 254 | echo -e "${lBlue}Test mode, change the installer host name to ${lCyan}vinstall${uId}${NC}" |
Sergio Slobodrian | 7c48362 | 2017-06-13 15:51:34 -0400 | [diff] [blame] | 255 | ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i key.pem vinstall@$ipAddr \ |
| 256 | sudo hostnamectl set-hostname vinstall${uId} |
| 257 | ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i key.pem vinstall@$ipAddr \ |
| 258 | sudo service networking restart |
Sergio Slobodrian | 6128779 | 2017-06-27 12:14:05 -0400 | [diff] [blame] | 259 | |
| 260 | echo -e "${lBlue}Testing, start the ${lCyan}ha-serv${lBlue} VMs${NC}" |
| 261 | vagrant destroy ha-serv${uId}-{1,2,3} |
| 262 | vagrant up ha-serv${uId}-{1,2,3} |
| 263 | ./devSetHostList.sh |
Stephane Barbarie | 2cbffca | 2018-03-26 16:20:03 -0400 | [diff] [blame] | 264 | |
| 265 | if [ "$useKubernetes" == "yes" ]; then |
| 266 | ./devSetKubernetes.sh |
| 267 | fi |
Sergio Slobodrian | 7c48362 | 2017-06-13 15:51:34 -0400 | [diff] [blame] | 268 | fi |
| 269 | |
Sergio Slobodrian | 36e1655 | 2017-06-19 11:00:45 -0400 | [diff] [blame] | 270 | # Ensure that the voltha VM is running so that images can be secured |
| 271 | echo -e "${lBlue}Ensure that the ${lCyan}voltha VM${lBlue} is running${NC}" |
Sergio Slobodrian | cab0a39 | 2017-07-13 08:42:10 -0400 | [diff] [blame] | 272 | vVm=`virsh list | grep "voltha_voltha${uId}"` |
| 273 | #echo "vVm: $vVm" |
| 274 | #echo "rebuildVoltha: $rebuildVoltha" |
Sergio Slobodrian | 36e1655 | 2017-06-19 11:00:45 -0400 | [diff] [blame] | 275 | |
Sergio Slobodrian | cab0a39 | 2017-07-13 08:42:10 -0400 | [diff] [blame] | 276 | |
| 277 | if [ -z "$vVm" -o "$rebuildVoltha" == "yes" ]; then |
Sergio Slobodrian | f74fa07 | 2017-06-28 09:33:24 -0400 | [diff] [blame] | 278 | if [ "$testMode" == "yes" ]; then |
Sergio Slobodrian | 92136d0 | 2017-08-22 21:48:42 -0400 | [diff] [blame] | 279 | ./BuildVoltha.sh "test" |
Sergio Slobodrian | 6128779 | 2017-06-27 12:14:05 -0400 | [diff] [blame] | 280 | rtrn=$? |
Sergio Slobodrian | 36e1655 | 2017-06-19 11:00:45 -0400 | [diff] [blame] | 281 | else |
| 282 | # Default to installer mode |
Sergio Slobodrian | 92136d0 | 2017-08-22 21:48:42 -0400 | [diff] [blame] | 283 | ./BuildVoltha.sh "install" |
Sergio Slobodrian | 6128779 | 2017-06-27 12:14:05 -0400 | [diff] [blame] | 284 | rtrn=$? |
Sergio Slobodrian | ba9cbd8 | 2017-06-22 11:45:49 -0400 | [diff] [blame] | 285 | fi |
| 286 | if [ $rtrn -ne 0 ]; then |
Sergio Slobodrian | f74fa07 | 2017-06-28 09:33:24 -0400 | [diff] [blame] | 287 | echo -e "${red}Voltha build failed!! ${lCyan}Please review the log and correct${lBlue} is running${NC}" |
Sergio Slobodrian | ba9cbd8 | 2017-06-22 11:45:49 -0400 | [diff] [blame] | 288 | exit 1 |
Sergio Slobodrian | 36e1655 | 2017-06-19 11:00:45 -0400 | [diff] [blame] | 289 | fi |
Stephane Barbarie | 2cbffca | 2018-03-26 16:20:03 -0400 | [diff] [blame] | 290 | |
| 291 | if [ "$useKubernetes" == "yes" ]; then |
| 292 | # Load required k8s libraries on the voltha instance |
| 293 | ./preloadKubernetes.sh |
| 294 | fi |
Sergio Slobodrian | 36e1655 | 2017-06-19 11:00:45 -0400 | [diff] [blame] | 295 | fi |
| 296 | |
Sergio Slobodrian | ba9cbd8 | 2017-06-22 11:45:49 -0400 | [diff] [blame] | 297 | # Extract all the image names and tags from the running voltha VM |
Sergio Slobodrian | 6128779 | 2017-06-27 12:14:05 -0400 | [diff] [blame] | 298 | # when running in test mode. This will provide the entire suite |
| 299 | # of available containers to the VM cluster. |
| 300 | |
Sergio Slobodrian | f74fa07 | 2017-06-28 09:33:24 -0400 | [diff] [blame] | 301 | if [ "$testMode" == "yes" ]; then |
Sergio Slobodrian | 6128779 | 2017-06-27 12:14:05 -0400 | [diff] [blame] | 302 | echo -e "${lBlue}Extracting the docker image list from the voltha VM${NC}" |
| 303 | volIpAddr=`virsh domifaddr $vVmName${uId} | tail -n +3 | awk '{ print $4 }' | sed -e 's~/.*~~'` |
| 304 | ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i ../.vagrant/machines/voltha${uId}/libvirt/private_key vagrant@$volIpAddr "docker image ls" > images.tmp |
Stephane Barbarie | 2cbffca | 2018-03-26 16:20:03 -0400 | [diff] [blame] | 305 | # Construct list of images; exclude all entries that point to the registry |
| 306 | cat images.tmp | grep -v :5000 | tail -n +2 | awk '{printf(" - %s:%s\n", $1, $2)}' | grep -v "<none>" > image-list.cfg |
Sergio Slobodrian | 6128779 | 2017-06-27 12:14:05 -0400 | [diff] [blame] | 307 | rm -f images.tmp |
| 308 | sed -i -e '/voltha_containers:/,$d' ansible/group_vars/all |
| 309 | echo "voltha_containers:" >> ansible/group_vars/all |
| 310 | cat image-list.cfg >> ansible/group_vars/all |
| 311 | rm -f image-list.cfg |
Sergio Slobodrian | 6e270c1 | 2017-08-09 23:06:49 -0400 | [diff] [blame] | 312 | echo -e "${lBlue}Gussing at the cord home directory for ${yellow}`whoami`${NC}" |
| 313 | sed -i -e "/cord_home:/s#.*#cord_home: `pwd | sed -e 's~/incubator/voltha/install~~'`#" ansible/group_vars/all |
Sergio Slobodrian | 6128779 | 2017-06-27 12:14:05 -0400 | [diff] [blame] | 314 | else |
Sergio Slobodrian | f74fa07 | 2017-06-28 09:33:24 -0400 | [diff] [blame] | 315 | echo -e "${lBlue}Set up the docker image list from ${lCyan}containers.cfg${NC}" |
Sergio Slobodrian | 6128779 | 2017-06-27 12:14:05 -0400 | [diff] [blame] | 316 | sed -i -e '/voltha_containers:/,$d' ansible/group_vars/all |
Stephane Barbarie | 2cbffca | 2018-03-26 16:20:03 -0400 | [diff] [blame] | 317 | |
| 318 | if [ "$useKubernetes" == "yes" ]; then |
| 319 | cat containers.cfg.k8s >> ansible/group_vars/all |
| 320 | else |
| 321 | cat containers.cfg >> ansible/group_vars/all |
| 322 | fi |
Sergio Slobodrian | 6128779 | 2017-06-27 12:14:05 -0400 | [diff] [blame] | 323 | fi |
Sergio Slobodrian | ba9cbd8 | 2017-06-22 11:45:49 -0400 | [diff] [blame] | 324 | |
Sergio Slobodrian | 9d9c844 | 2017-07-25 07:55:42 -0400 | [diff] [blame] | 325 | |
Sergio Slobodrian | ee4b2bc | 2017-06-05 10:08:59 -0400 | [diff] [blame] | 326 | # Install python which is required for ansible |
Sergio Slobodrian | 9d9c844 | 2017-07-25 07:55:42 -0400 | [diff] [blame] | 327 | echo -e "${lBlue}Installing ${lCyan}Python${NC}" |
Sergio Slobodrian | ee4b2bc | 2017-06-05 10:08:59 -0400 | [diff] [blame] | 328 | ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i key.pem vinstall@$ipAddr sudo apt-get update |
Stephane Barbarie | 2cbffca | 2018-03-26 16:20:03 -0400 | [diff] [blame] | 329 | ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i key.pem vinstall@$ipAddr sudo apt-get -y install python python-netaddr |
Sergio Slobodrian | 9d9c844 | 2017-07-25 07:55:42 -0400 | [diff] [blame] | 330 | |
| 331 | # Move all the python deb files to their own directory so they can be installed first |
| 332 | echo -e "${lBlue}Caching ${lCyan}Python${lBlue} install${NC}" |
| 333 | ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i key.pem vinstall@$ipAddr mkdir python-deb |
| 334 | ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i key.pem vinstall@$ipAddr "sudo mv /var/cache/apt/archives/*.deb /home/vinstall/python-deb" |
| 335 | ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i key.pem vinstall@$ipAddr "sudo chown -R vinstall.vinstall /home/vinstall/python-deb" |
| 336 | |
Stephane Barbarie | 2cbffca | 2018-03-26 16:20:03 -0400 | [diff] [blame] | 337 | if [ "$useKubernetes" == "yes" ]; then |
| 338 | echo -e "${lBlue}Cloning ${lCyan}Kubespray${lBlue} repository${NC}" |
Stephane Barbarie | 78d9fa6 | 2018-04-19 14:11:05 -0400 | [diff] [blame] | 339 | ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i key.pem vinstall@$ipAddr "git clone --branch v2.5.0 https://github.com/kubernetes-incubator/kubespray.git /home/vinstall/kubespray" |
Stephane Barbarie | 2cbffca | 2018-03-26 16:20:03 -0400 | [diff] [blame] | 340 | ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i key.pem vinstall@$ipAddr "sudo chown -R vinstall.vinstall /home/vinstall/kubespray" |
| 341 | fi |
Sergio Slobodrian | ee4b2bc | 2017-06-05 10:08:59 -0400 | [diff] [blame] | 342 | |
Sergio Slobodrian | ee4b2bc | 2017-06-05 10:08:59 -0400 | [diff] [blame] | 343 | # Create the docker.cfg file in the ansible tree using the VMs IP address |
| 344 | echo 'DOCKER_OPTS="$DOCKER_OPTS --insecure-registry '$ipAddr':5000 -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock --registry-mirror=http://'$ipAddr':5001"' > ansible/roles/docker/templates/docker.cfg |
| 345 | |
| 346 | # Add the voltha vm's information to the ansible tree |
| 347 | echo -e "${lBlue}Add the voltha vm and key to the ansible accessible hosts${NC}" |
Sergio Slobodrian | 7c48362 | 2017-06-13 15:51:34 -0400 | [diff] [blame] | 348 | vIpAddr=`virsh domifaddr voltha_voltha${uId} | tail -n +3 | awk '{ print $4 }' | sed -e 's~/.*~~'` |
Sergio Slobodrian | ee4b2bc | 2017-06-05 10:08:59 -0400 | [diff] [blame] | 349 | echo "[voltha]" > ansible/hosts/voltha |
| 350 | echo $vIpAddr >> ansible/hosts/voltha |
Sergio Slobodrian | 7c48362 | 2017-06-13 15:51:34 -0400 | [diff] [blame] | 351 | echo "ansible_ssh_private_key_file: $wd/../.vagrant/machines/voltha${uId}/libvirt/private_key" > ansible/host_vars/$vIpAddr |
Sergio Slobodrian | ee4b2bc | 2017-06-05 10:08:59 -0400 | [diff] [blame] | 352 | |
| 353 | |
| 354 | # Prepare to launch the ansible playbook to configure the installer VM |
| 355 | echo -e "${lBlue}Prepare to launch the ansible playbook to configure the VM${NC}" |
| 356 | echo "[installer]" > ansible/hosts/installer |
| 357 | echo "$ipAddr" >> ansible/hosts/installer |
| 358 | echo "ansible_ssh_private_key_file: $wd/key.pem" > ansible/host_vars/$ipAddr |
| 359 | |
Sergio Slobodrian | f74fa07 | 2017-06-28 09:33:24 -0400 | [diff] [blame] | 360 | # Launch the ansible playbooks |
| 361 | |
| 362 | echo -e "${lBlue}Launching the ${lCyan}volthainstall${lBlue} ansible playbook on the installer vm${NC}" |
Sergio Slobodrian | ee4b2bc | 2017-06-05 10:08:59 -0400 | [diff] [blame] | 363 | ansible-playbook ansible/volthainstall.yml -i ansible/hosts/installer |
Sergio Slobodrian | f74fa07 | 2017-06-28 09:33:24 -0400 | [diff] [blame] | 364 | rtrn=$? |
| 365 | if [ $rtrn -ne 0 ]; then |
Sergio Slobodrian | c547771 | 2017-06-07 11:56:56 -0400 | [diff] [blame] | 366 | echo -e "${red}PLAYBOOK FAILED, Exiting${NC}" |
| 367 | exit |
| 368 | fi |
| 369 | |
Sergio Slobodrian | f74fa07 | 2017-06-28 09:33:24 -0400 | [diff] [blame] | 370 | |
| 371 | echo -e "${lBlue}Launching the ${lCyan}volthainstall${lBlue} ansible playbook on the voltha vm${NC}" |
| 372 | ansible-playbook ansible/volthainstall.yml -i ansible/hosts/voltha |
| 373 | rtrn=$? |
| 374 | if [ $rtrn -ne 0 ]; then |
| 375 | echo -e "${red}PLAYBOOK FAILED, Exiting${NC}" |
| 376 | exit |
| 377 | fi |
| 378 | |
| 379 | if [ "$testMode" == "yes" ]; then |
Sergio Slobodrian | d24189e | 2017-06-10 23:27:15 -0400 | [diff] [blame] | 380 | echo -e "${lBlue}Testing, the install image ${red}WILL NOT${lBlue} be built${NC}" |
Sergio Slobodrian | 6128779 | 2017-06-27 12:14:05 -0400 | [diff] [blame] | 381 | |
| 382 | |
| 383 | # Reboot the installer |
| 384 | echo -e "${lBlue}Rebooting the installer${NC}" |
| 385 | ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i key.pem vinstall@$ipAddr sudo telinit 6 |
| 386 | # Wait for the host to shut down |
| 387 | sleep 5 |
| 388 | |
| 389 | ctr=0 |
| 390 | ipAddr="" |
| 391 | while [ -z "$ipAddr" ]; |
| 392 | do |
| 393 | echo -e "${lBlue}Waiting for the VM's IP address${NC}" |
| 394 | ipAddr=`virsh domifaddr $iVmName | tail -n +3 | awk '{ print $4 }' | sed -e 's~/.*~~'` |
| 395 | sleep 3 |
| 396 | if [ $ctr -eq $ipTimeout ]; then |
| 397 | echo -e "${red}Tired of waiting, please adjust the ipTimeout if the VM is slow to start${NC}" |
| 398 | exit |
| 399 | fi |
| 400 | ctr=`expr $ctr + 1` |
| 401 | done |
| 402 | |
| 403 | echo -e "${lBlue}Running the installer${NC}" |
| 404 | echo "~/installer.sh" > tmp_bash_login |
| 405 | echo "rm ~/.bash_login" >> tmp_bash_login |
| 406 | echo "logout" >> tmp_bash_login |
| 407 | scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i key.pem tmp_bash_login vinstall@$ipAddr:.bash_login |
| 408 | rm -f tmp_bash_login |
| 409 | ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i key.pem vinstall@$ipAddr |
| 410 | |
Sergio Slobodrian | c547771 | 2017-06-07 11:56:56 -0400 | [diff] [blame] | 411 | else |
| 412 | echo -e "${lBlue}Building, the install image (this can take a while)${NC}" |
| 413 | # Create a temporary directory for all the installer files |
| 414 | mkdir tmp_installer |
| 415 | cp vmTemplate.xml tmp_installer |
| 416 | # Shut down the installer vm |
| 417 | ctr=0 |
| 418 | vStat=`virsh list | grep $iVmName` |
| 419 | virsh shutdown $iVmName |
| 420 | while [ ! -z "$vStat" ]; |
| 421 | do |
| 422 | echo "Waiting for $iVmName to shut down" |
| 423 | sleep 2 |
Sergio Slobodrian | 497e6e8 | 2017-07-18 15:10:38 -0400 | [diff] [blame] | 424 | vStat=`virsh list | grep "$iVmName "` |
Sergio Slobodrian | c547771 | 2017-06-07 11:56:56 -0400 | [diff] [blame] | 425 | ctr=`expr $ctr + 1` |
| 426 | if [ $ctr -eq $shutdownTimeout ]; then |
| 427 | echo -e "${red}Tired of waiting, forcing the VM off${NC}" |
| 428 | virsh destroy $iVmName |
Sergio Slobodrian | 497e6e8 | 2017-07-18 15:10:38 -0400 | [diff] [blame] | 429 | vStat=`virsh list | grep "$iVmName "` |
Sergio Slobodrian | c547771 | 2017-06-07 11:56:56 -0400 | [diff] [blame] | 430 | fi |
| 431 | done |
| 432 | # Copy the install bootstrap script to the installer directory |
| 433 | cp BootstrapInstaller.sh tmp_installer |
| 434 | # Copy the private key to access the VM |
| 435 | cp key.pem tmp_installer |
| 436 | pushd tmp_installer > /dev/null 2>&1 |
| 437 | # Copy the vm image to the installer directory |
| 438 | virsh vol-dumpxml $iVmName.qcow2 default | sed -e 's/<key.*key>//' | sed -e '/^[ ]*$/d' > ${iVmName}_volume.xml |
| 439 | virsh pool-create-as installer --type dir --target `pwd` |
| 440 | virsh vol-create-from installer ${iVmName}_volume.xml $iVmName.qcow2 --inputpool default |
| 441 | virsh pool-destroy installer |
| 442 | # The image is copied in as root. It needs to have ownership changed |
| 443 | # this will result in a password prompt. |
| 444 | sudo chown `whoami`.`whoami` $iVmName.qcow2 |
| 445 | # Now create the installer tar file |
| 446 | tar cjf ../$installerArchive . |
| 447 | popd > /dev/null 2>&1 |
| 448 | # Clean up |
| 449 | rm -fr tmp_installer |
| 450 | # Final location for the installer |
| 451 | rm -fr $installerDirectory |
| 452 | mkdir $installerDirectory |
Sergio Slobodrian | 36e1655 | 2017-06-19 11:00:45 -0400 | [diff] [blame] | 453 | cp deployInstaller.sh $installerDirectory |
Sergio Slobodrian | c547771 | 2017-06-07 11:56:56 -0400 | [diff] [blame] | 454 | # Check the image size and determine if it needs to be split. |
| 455 | # To be safe, split the image into chunks smaller than 2G so that |
| 456 | # it will fit on a FAT32 volume. |
| 457 | fSize=`ls -l $installerArchive | awk '{print $5'}` |
| 458 | if [ $fSize -gt 2000000000 ]; then |
| 459 | echo -e "${lBlue}Installer file too large, breaking into parts${NC}" |
| 460 | # The file is too large, breaking it up into parts |
| 461 | sPos=0 |
| 462 | fnn="00" |
| 463 | while dd if=$installerArchive of=${installerDirectory}/${installerPart}$fnn \ |
| 464 | bs=1900MB count=1 skip=$sPos > /dev/null 2>&1 |
| 465 | do |
| 466 | sPos=`expr $sPos + 1` |
| 467 | if [ ! -s ${installerDirectory}/${installerPart}$fnn ]; then |
| 468 | rm -f ${installerDirectory}/${installerPart}$fnn |
| 469 | break |
| 470 | fi |
| 471 | if [ $sPos -lt 10 ]; then |
| 472 | fnn="0$sPos" |
| 473 | else |
| 474 | fnn="$sPos" |
| 475 | fi |
| 476 | done |
| 477 | else |
| 478 | cp $installerArchive $installerDirectory |
| 479 | fi |
| 480 | # Clean up |
| 481 | rm $installerArchive |
Sergio Slobodrian | f74fa07 | 2017-06-28 09:33:24 -0400 | [diff] [blame] | 482 | echo -e "${lBlue}The install image is built and can be found in ${lCyan}$installerDirectory${NC}" |
| 483 | echo -e "${lBlue}Copy all the files in ${lCyan}$installerDirectory${lBlue} to the traasnport media${NC}" |
Sergio Slobodrian | c547771 | 2017-06-07 11:56:56 -0400 | [diff] [blame] | 484 | fi |