Skip to content

Commit a1a1ae1

Browse files
committed
Adds some permission management scripts
1 parent ac2cfe7 commit a1a1ae1

4 files changed

+67
-0
lines changed

add-esxi-vm-permission.sh

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/sh
2+
set -e
3+
4+
if [ $# -ne 3 ]; then
5+
echo "Usage: $0 <vm_name> <user_name> <role>"
6+
exit 1
7+
fi
8+
9+
VM_NAME=$1
10+
USER_NAME=$2
11+
ROLE_NAME=$3
12+
13+
BASEDIR=$(dirname $0)
14+
15+
VMID=`$BASEDIR/get-esxi-vm-id.sh "$VM_NAME"`
16+
vim-cmd vimsvc/auth/entity_permission_add vim.VirtualMachine:$VMID $USER_NAME false $ROLE_NAME true
17+

get-esxi-users.sh

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/sh
2+
set -e
3+
4+
# This returns the list of users with permissions on ha-folder-root
5+
# TODO: find a way to return the full users list, if possible
6+
vim-cmd vimsvc/auth/entity_permissions vim.Folder:ha-folder-root | sed -rn 's/\ +principal = "(.+)",\ +/\1/p'

get-esxi-vm-id.sh

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/sh
2+
set -e
3+
4+
if [ $# -ne 1 ]; then
5+
echo "Usage: $0 <vm_name>"
6+
exit 1
7+
fi
8+
9+
VM_NAME=$1
10+
11+
/bin/vim-cmd vmsvc/getallvms | awk -vvmname="$VM_NAME" '{if ($2 == vmname) print $1}'
12+

set-esxi-vm-permission-all-users.sh

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/sh
2+
set -e
3+
4+
isinlist () {
5+
for ITEM in `echo $2 | sed -e 's/,/\n/g'`
6+
do
7+
if [ "$ITEM" == "$1" ]; then
8+
return 1
9+
fi
10+
done
11+
}
12+
13+
if [ $# -lt 2 ]; then
14+
echo "Usage: $0 <vm_name> <role> [<excluded_user_names>]"
15+
exit 1
16+
fi
17+
18+
VM_NAME=$1
19+
EXCLUDED_USER_NAMES=$3
20+
ROLE_NAME=$2
21+
22+
BASEDIR=$(dirname $0)
23+
24+
for USER_NAME in `$BASEDIR/get-esxi-users.sh`
25+
do
26+
isinlist $USER_NAME "root,dcui,vpxuser,$EXCLUDED_USER_NAMES"
27+
if [ "$?" -ne "1" ]; then
28+
echo "Applying permissions for $USER_NAME"
29+
$BASEDIR/add-esxi-vm-permission.sh $VM_NAME $USER_NAME $ROLE_NAME
30+
fi
31+
done
32+

0 commit comments

Comments
 (0)