Remove creation of httpboot folder
[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     ssh -o StrictHostKeyChecking=no -tT "$USERNAME"@"$(get_vm_ip)" << "EOF"
37 sudo ifconfig $PXE_IF up
38 sudo ifconfig $PXE_IF $PXE_IF_IP netmask $NETMASK
39 sudo ifconfig $PXE_IF hw ether $PXE_IF_MAC
40 EOF
41 }
42
43 # Copy files needed by Infra engine & BMRA in the jumphost VM
44 copy_files_jump() {
45     scp -r -o StrictHostKeyChecking=no \
46     "$CURRENTPATH/{hw_config/$VENDOR/,sw_config/$INSTALLER/}" \
47     "$USERNAME@$(get_vm_ip):$PROJECT_ROOT"
48 }
49
50 # Host Provisioning
51 provision_hosts() {
52     ssh -tT "$USERNAME"@"$(get_vm_ip)" << "EOF"
53 # Install and run cloud-infra
54 if [ ! -d "${PROJECT_ROOT}/engine" ]; then
55     ssh-keygen -t rsa -N "" -f ${PROJECT_ROOT}/.ssh/id_rsa
56     git clone https://gerrit.nordix.org/infra/engine.git
57     cp $PROJECT_ROOT/$VENDOR/{pdf.yaml,idf.yaml} \
58     ${PROJECT_ROOT}/engine/engine
59 fi
60 cd ${PROJECT_ROOT}/engine/engine
61 ./deploy.sh -s ironic -d centos7 \
62 -p file:///${PROJECT_ROOT}/engine/engine/pdf.yaml \
63 -i file:///${PROJECT_ROOT}/engine/engine/idf.yaml
64 EOF
65 }
66
67 # Setup networking on provisioned hosts (Adapt setup_network.sh according to your network setup)
68 setup_network() {
69     ssh -tT  "$USERNAME"@"$(get_vm_ip)" << "EOF"
70 ssh -o StrictHostKeyChecking=no root@$MASTER_IP \
71     'bash -s' <  ${PROJECT_ROOT}/${VENDOR}/setup_network.sh
72 ssh -o StrictHostKeyChecking=no root@$WORKER_IP \
73     'bash -s' <  ${PROJECT_ROOT}/${VENDOR}/setup_network.sh
74 EOF
75 }
76
77 # k8s Provisioning (currently BMRA)
78 provision_k8s() {
79     ssh -tT  "$USERNAME"@"$(get_vm_ip)" << "EOF"
80 # Install BMRA
81 if [ ! -d "${PROJECT_ROOT}/container-experience-kits" ]; then
82     curl -fsSL https://get.docker.com/ | sh
83     printf "Waiting for docker service..."
84     until sudo docker info; do
85         printf "."
86         sleep 2
87     done
88     git clone https://github.com/intel/container-experience-kits.git
89     cd ${PROJECT_ROOT}/container-experience-kits
90     git checkout v1.4.1
91     git submodule update --init
92     cp -r examples/group_vars examples/host_vars .
93     cp ${PROJECT_ROOT}/${INSTALLER}/inventory.ini \
94     ${PROJECT_ROOT}/container-experience-kits/
95     cp ${PROJECT_ROOT}/${INSTALLER}/all.yml \
96     ${PROJECT_ROOT}/container-experience-kits/group_vars/
97     cp ${PROJECT_ROOT}/${INSTALLER}/node1.yml \
98     ${PROJECT_ROOT}/container-experience-kits/host_vars/
99 fi
100 sudo service docker start
101 sudo docker run --rm \
102 -v ${PROJECT_ROOT}/container-experience-kits:/bmra \
103 -v ~/.ssh/:/root/.ssh/ rihabbanday/bmra-install:centos \
104 ansible-playbook -i /bmra/inventory.ini /bmra/playbooks/cluster.yml
105 EOF
106 }