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