source: installer/vagrant/provision_esxi_net.sh @ ba0edc7

configure-oglivelgromero-new-oglivemainmount-efivarfsuse-local-agent-oglive
Last change on this file since ba0edc7 was 7485678, checked in by Natalia Serrano <natalia.serrano@…>, 15 months ago

refs #162 use vlan identifiers starting from 3000

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