Remove double quotes around EOF
[kuberef.git] / functions.sh
1 #!/bin/bash
2 # SPDX-license-identifier: Apache-2.0
3 ##############################################################################
4 # Copyright (c)
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
10
11 # Clean up
12 clean_up() {
13     if sudo virsh list --all | grep "${VM_NAME}.*running" ; then
14         sudo virsh destroy "$VM_NAME"
15     fi
16     if sudo virsh list --all | grep "${VM_NAME}" ; then
17         sudo virsh undefine "$VM_NAME"
18     fi
19     sudo rm -rf "/var/lib/libvirt/images/$VM_NAME"
20     sleep 5
21 }
22
23 # Create jumphost VM
24 create_jump() {
25     ./create_vm.sh "$VM_NAME"
26     sleep 30
27 }
28
29 # Get jumphost VM IP
30 get_vm_ip() {
31     sudo virsh domifaddr "$VM_NAME" | awk 'FNR == 3 {gsub(/\/.*/, ""); print $4}'
32 }
33
34 # Setup PXE network
35 setup_PXE_network() {
36     # shellcheck disable=SC2087
37     ssh -o StrictHostKeyChecking=no -tT "$USERNAME"@"$(get_vm_ip)" << EOF
38 sudo ifconfig $PXE_IF up
39 sudo ifconfig $PXE_IF $PXE_IF_IP netmask $NETMASK
40 sudo ifconfig $PXE_IF hw ether $PXE_IF_MAC
41 EOF
42 }
43
44 # Copy files needed by Infra engine & BMRA in the jumphost VM
45 copy_files_jump() {
46     scp -r -o StrictHostKeyChecking=no \
47     "$CURRENTPATH"/{hw_config/"$VENDOR"/,sw_config/"$INSTALLER"/} \
48     "$USERNAME@$(get_vm_ip):$PROJECT_ROOT"
49 }
50
51 # Host Provisioning
52 provision_hosts() {
53     # shellcheck disable=SC2087
54     ssh -tT "$USERNAME"@"$(get_vm_ip)" << EOF
55 # Install and run cloud-infra
56 if [ ! -d "${PROJECT_ROOT}/engine" ]; then
57     ssh-keygen -t rsa -N "" -f ${PROJECT_ROOT}/.ssh/id_rsa
58     git clone https://gerrit.nordix.org/infra/engine.git
59     cp $PROJECT_ROOT/$VENDOR/{pdf.yaml,idf.yaml} \
60     ${PROJECT_ROOT}/engine/engine
61 # NOTE: will be removed when centos image path will be added in infra-engine
62 sudo mkdir /httpboot
63 # sudo cp -r ${PROJECT_ROOT}/deployment_image.qcow2 /httpboot
64 fi
65 cd ${PROJECT_ROOT}/engine/engine
66 ./deploy.sh -s ironic -d centos7 \
67 -p file:///${PROJECT_ROOT}/engine/engine/pdf.yaml \
68 -i file:///${PROJECT_ROOT}/engine/engine/idf.yaml
69 EOF
70 }
71
72 # Setup networking on provisioned hosts (Adapt setup_network.sh according to your network setup)
73 setup_network() {
74     # shellcheck disable=SC2087
75     ssh -tT  "$USERNAME"@"$(get_vm_ip)" << EOF
76 ssh -o StrictHostKeyChecking=no root@$MASTER_IP \
77     'bash -s' <  ${PROJECT_ROOT}/${VENDOR}/setup_network.sh
78 ssh -o StrictHostKeyChecking=no root@$WORKER_IP \
79     'bash -s' <  ${PROJECT_ROOT}/${VENDOR}/setup_network.sh
80 EOF
81 }
82
83 # k8s Provisioning (currently BMRA)
84 provision_k8s() {
85     # shellcheck disable=SC2087
86     ssh -tT  "$USERNAME"@"$(get_vm_ip)" << EOF
87 # Install BMRA
88 if [ ! -d "${PROJECT_ROOT}/container-experience-kits" ]; then
89     curl -fsSL https://get.docker.com/ | sh
90     printf "Waiting for docker service..."
91     until sudo docker info; do
92         printf "."
93         sleep 2
94     done
95     git clone https://github.com/intel/container-experience-kits.git
96     cd ${PROJECT_ROOT}/container-experience-kits
97     git checkout v1.4.1
98     git submodule update --init
99     cp -r examples/group_vars examples/host_vars .
100     cp ${PROJECT_ROOT}/${INSTALLER}/inventory.ini \
101     ${PROJECT_ROOT}/container-experience-kits/
102     cp ${PROJECT_ROOT}/${INSTALLER}/all.yml \
103     ${PROJECT_ROOT}/container-experience-kits/group_vars/
104     cp ${PROJECT_ROOT}/${INSTALLER}/node1.yml \
105     ${PROJECT_ROOT}/container-experience-kits/host_vars/
106 fi
107 sudo service docker start
108 sudo docker run --rm \
109 -v ${PROJECT_ROOT}/container-experience-kits:/bmra \
110 -v ~/.ssh/:/root/.ssh/ rihabbanday/bmra-install:centos \
111 ansible-playbook -i /bmra/inventory.ini /bmra/playbooks/cluster.yml
112 EOF
113 }