source: installer/vagrant/provision_esxi_net.sh @ fee080a

configure-oglivelgromero-new-oglivemainmaint-cronmount-efivarfsmultivmmultivm-ogboot-installerogClonningEngineogboot-installer-jenkinsoglive-ipv6test-python-scriptsticket-301ticket-50ticket-50-oldticket-577ticket-585ticket-611ticket-612ticket-693ticket-700ubu24tplunification2use-local-agent-oglivevarios-instalacion
Last change on this file since fee080a was 5830863, checked in by Nicolas Arenas <nicolas.arenas@…>, 20 months ago

Integrate vagrant with networking

  • 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:-"test"}
9ESXCLI=/usr/bin/esxcli
10VSWITCH="vSwitch1"
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 1 
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    echo VLAN assigned is $NEXT_VLAN
37}
38
39function setVlan(){
40    $ESXCLI network vswitch standard portgroup set -p $BRANCH --vlan-id $1
41}
42
43#### SCRIPT
44checkIfPortgroupExists
45createPortGroup
46getMaxVlan
47setVlan $NEXT_VLAN
48echo portgroup $BRANCH created with vlan_id $NEXT_VLAN
Note: See TracBrowser for help on using the repository browser.