source: installer/vagrant/provision_esxi_net.sh

lgromero-new-oglive
Last change on this file was cf14a94, checked in by Natalia Serrano <natalia.serrano@…>, 6 months ago

refs #941 try to make installer on ESXi pick oglive/ogagent from NFS

  • Property mode set to 100755
File size: 1.3 KB
Line 
1#!/bin/bash
2
3set -e
4
5BRANCH=$1
6BRANCH=${BRANCH:-"main"}
7ESXCLI=/usr/bin/esxcli
8VSWITCH="vSwitch2"
9source ~/.pass
10
11
12# Check if portgroup exists
13function checkIfPortgroupExists () {
14    local i=0
15    PORTGROUPS=( $($ESXCLI network vswitch standard portgroup list | grep $BRANCH | awk ' { print $1 }')  )
16    for portgroup in "${PORTGROUPS[@]}"; do
17        if [ $portgroup == $BRANCH ] ; then
18                echo "Portgroup $BRANCH is not going to be created, already exists"
19                echo "Please Check ESXI configuration"
20                exit 0
21        fi
22    done 
23}
24function createPortGroup() {
25        echo Adding portgroup $BRANCH to $VSWITCH
26        $ESXCLI network vswitch standard portgroup add --portgroup-name=$BRANCH --vswitch-name=$VSWITCH
27}
28
29function getMaxVlan(){
30    PORTGROUPS=( $($ESXCLI --formatter=csv network vswitch standard portgroup list | grep $VSWITCH | cut -d "," -f3 )  )
31    IFS=$'\n'
32    MAX_VLAN=$(echo "${PORTGROUPS[*]}" | sort -nr | head -n1)
33    NEXT_VLAN=$(( MAX_VLAN + 1 ))
34    [[ $NEXT_VLAN -lt 3000 ]] && NEXT_VLAN=3000
35    echo VLAN assigned is $NEXT_VLAN
36}
37
38function setVlan(){
39    $ESXCLI network vswitch standard portgroup set -p $BRANCH --vlan-id $1
40}
41
42#### SCRIPT
43checkIfPortgroupExists
44createPortGroup
45getMaxVlan
46setVlan $NEXT_VLAN
47echo portgroup $BRANCH created with vlan_id $NEXT_VLAN
Note: See TracBrowser for help on using the repository browser.