configure-oglivelgromero-new-oglivemainmaint-cronmount-efivarfsmultivmmultivm-ogboot-installerogClonningEngineoglive-ipv6test-python-scriptsticket-301ticket-50ticket-50-oldticket-577ticket-585ticket-611ticket-612ticket-693ticket-700ubu24tplunification2use-local-agent-oglivevarios-instalacion
Last change
on this file since 4bc4eb0 was
eec3970,
checked in by Natalia Serrano <natalia.serrano@…>, 15 months ago
|
refs #162 Change ESXi vSwitch
|
-
Property mode set to
100644
|
File size:
1.3 KB
|
Rev | Line | |
---|
[2cfd626] | 1 | #!/bin/bash |
---|
| 2 | |
---|
| 3 | #!/usr/bin/bash |
---|
| 4 | |
---|
| 5 | set -e |
---|
| 6 | |
---|
| 7 | BRANCH=$1 |
---|
[85df22be] | 8 | BRANCH=${BRANCH:-"main"} |
---|
[2cfd626] | 9 | ESXCLI=/usr/bin/esxcli |
---|
[eec3970] | 10 | VSWITCH="vSwitch2" |
---|
[2cfd626] | 11 | source ~/.pass |
---|
| 12 | |
---|
| 13 | |
---|
| 14 | # Check if portgroup exists |
---|
| 15 | function 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" |
---|
[739add5] | 22 | exit 0 |
---|
[2cfd626] | 23 | fi |
---|
| 24 | done |
---|
| 25 | } |
---|
| 26 | function createPortGroup() { |
---|
| 27 | echo Adding portgroup $BRANCH to $VSWITCH |
---|
| 28 | $ESXCLI network vswitch standard portgroup add --portgroup-name=$BRANCH --vswitch-name=$VSWITCH |
---|
| 29 | } |
---|
| 30 | |
---|
| 31 | function getMaxVlan(){ |
---|
[0d7894b] | 32 | PORTGROUPS=( $($ESXCLI --formatter=csv network vswitch standard portgroup list | grep $VSWITCH | cut -d "," -f3 ) ) |
---|
[2cfd626] | 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 | |
---|
| 39 | function setVlan(){ |
---|
| 40 | $ESXCLI network vswitch standard portgroup set -p $BRANCH --vlan-id $1 |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | #### SCRIPT |
---|
| 44 | checkIfPortgroupExists |
---|
| 45 | createPortGroup |
---|
| 46 | getMaxVlan |
---|
| 47 | setVlan $NEXT_VLAN |
---|
| 48 | echo portgroup $BRANCH created with vlan_id $NEXT_VLAN |
---|
Note: See
TracBrowser
for help on using the repository browser.