Import rest of modules.
This commit is contained in:
parent
02fa10f33c
commit
3f225ced9b
39 changed files with 2056 additions and 0 deletions
93
vmware/files/scripts/vmware-console
Executable file
93
vmware/files/scripts/vmware-console
Executable file
|
@ -0,0 +1,93 @@
|
|||
#!/bin/sh
|
||||
|
||||
. /usr/local/lib/vmware.sh
|
||||
|
||||
get_pipe_file() {
|
||||
vmware-vim-cmd vmsvc/device.getdevices $1 | awk '
|
||||
/backing = \(vim.vm.device.VirtualSerialPort.PipeBackingInfo\)/ {
|
||||
section = 1;
|
||||
}
|
||||
section == 1 {
|
||||
if (/},/) {
|
||||
if (pipe) {
|
||||
print pipe
|
||||
}
|
||||
section = 0;
|
||||
} else if (/pipeName = /) {
|
||||
pipe = $3;
|
||||
}
|
||||
}
|
||||
' | sed -n 's/^"\(.*\)",/\1/p'
|
||||
}
|
||||
|
||||
usage() {
|
||||
echo "Usage: `basename $0` [-g] <vm>" 1>&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
SOCAT="`which socat 2> /dev/null`"
|
||||
|
||||
if [ $# -gt 2 ]; then
|
||||
usage
|
||||
elif [ $# -eq 2 ]; then
|
||||
case $1 in
|
||||
-g)
|
||||
serial=0
|
||||
;;
|
||||
-s)
|
||||
if [ "${SOCAT}" = "" ]; then
|
||||
echo "Serial console not avaible, socat is missing" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
serial=2
|
||||
;;
|
||||
*)
|
||||
usage
|
||||
esac
|
||||
vm="$2"
|
||||
elif [ $# -eq 1 ]; then
|
||||
vm="$1"
|
||||
else
|
||||
usage
|
||||
fi
|
||||
|
||||
vmid="`vmid \"${vm}\"`"
|
||||
if [ "${vmid}" = "" ]; then
|
||||
echo "Cannot find virtual machine ${vm}" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "${serial}" != "0" -a "${SOCAT}" != "" ]; then
|
||||
pipe="`get_pipe_file ${vmid}`"
|
||||
if [ "${pipe}" != "" ]; then
|
||||
echo ${pipe} | egrep -q "^/"
|
||||
if [ $? -ne 0 ]; then
|
||||
vmpath="`abspath ${vmid}`"
|
||||
pipe="`dirname \"${vmpath}\"`/${pipe}"
|
||||
fi
|
||||
screen ${SOCAT} unix-connect:${pipe} stdio,echo=0,raw
|
||||
exit $?
|
||||
elif [ "${serial}" = "2" ]; then
|
||||
echo "Serial console not available for virtual machine ${vm}" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
platform="`uname -i`"
|
||||
case ${platform} in
|
||||
x86_64)
|
||||
platform=x64
|
||||
;;
|
||||
*)
|
||||
platform=x86
|
||||
;;
|
||||
esac
|
||||
xpifile="`find /usr/lib/vmware/webAccess/tomcat/apache-tomcat-*/webapps/ui/plugin/vmware-vmrc-linux-${platform}.xpi`"
|
||||
|
||||
tmpdir="`mktemp -d /tmp/vmware-vmrc-${LOGNAME}-XXXXXXXXXX`" && {
|
||||
cd ${tmpdir}
|
||||
unzip -q ${xpifile}
|
||||
vmware-vim-cmd vmsvc/acquiremksticket ${vmid}
|
||||
./plugins/vmware-vmrc -u root -h localhost:8333 -M ${vmid}
|
||||
rm -rf ${tmpdir}
|
||||
}
|
28
vmware/files/scripts/vmware-list
Executable file
28
vmware/files/scripts/vmware-list
Executable file
|
@ -0,0 +1,28 @@
|
|||
#!/bin/sh
|
||||
|
||||
. /usr/local/lib/vmware.sh
|
||||
|
||||
if [ "$1" != "-h" ]; then
|
||||
echo "Name ID Mem(MiB) VCPUs State"
|
||||
fi
|
||||
list_vms | while read vm ; do
|
||||
vmname="`echo ${vm} | cut -d '|' -f 2`"
|
||||
vmid=`echo ${vm} | cut -d '|' -f 1`
|
||||
printf '%-25s %5s' ${vmname} ${vmid}
|
||||
vmware-vim-cmd vmsvc/get.summary ${vmid} | \
|
||||
sed -n 's/^[ ]*\(powerState\|memorySizeMB\|numCpu\) = \(.*\),[ ]*$/\1 \2/p' | \
|
||||
awk '
|
||||
{
|
||||
if ($1 == "powerState") {
|
||||
power=substr($2, 2, length($2)-2)
|
||||
} else if ($1 == "memorySizeMB") {
|
||||
memory=$2
|
||||
} else if ($1 == "numCpu") {
|
||||
cpus=$2
|
||||
}
|
||||
}
|
||||
END {
|
||||
printf "%9s %5s %s\n", memory, cpus, power
|
||||
}
|
||||
'
|
||||
done
|
16
vmware/files/scripts/vmware-register
Executable file
16
vmware/files/scripts/vmware-register
Executable file
|
@ -0,0 +1,16 @@
|
|||
#!/bin/sh
|
||||
|
||||
. /usr/local/lib/vmware.sh
|
||||
|
||||
if [ $# -ne 1 ]; then
|
||||
echo "Usage: `basename $0` <vmx>" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
vmx="`abspath \"${1}\"`"
|
||||
if [ ! -f "${vmx}" ]; then
|
||||
echo "Cannot find vmx file ${vmx}" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
vmware-vim-cmd solo/registervm "${vmx}"
|
18
vmware/files/scripts/vmware-start
Executable file
18
vmware/files/scripts/vmware-start
Executable file
|
@ -0,0 +1,18 @@
|
|||
#!/bin/sh
|
||||
|
||||
. /usr/local/lib/vmware.sh
|
||||
|
||||
if [ $# -ne 1 ]; then
|
||||
echo "Usage: `basename $0` <vm>" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
vm="$1"
|
||||
|
||||
vmid="`vmid \"${vm}\"`"
|
||||
if [ "${vmid}" = "" ]; then
|
||||
echo "Cannot find virtual machine ${vm}" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
vmware-vim-cmd vmsvc/power.on ${vmid}
|
33
vmware/files/scripts/vmware-stop
Executable file
33
vmware/files/scripts/vmware-stop
Executable file
|
@ -0,0 +1,33 @@
|
|||
#!/bin/sh
|
||||
|
||||
. /usr/local/lib/vmware.sh
|
||||
|
||||
if [ $# -eq 1 ]; then
|
||||
mode="power.shutdown"
|
||||
elif [ $# -eq 2 ]; then
|
||||
case $2 in
|
||||
hard)
|
||||
mode="power.off"
|
||||
;;
|
||||
soft)
|
||||
mode="power.shutdown"
|
||||
;;
|
||||
default)
|
||||
echo "Invalid power mode $2" 1>&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
else
|
||||
echo "Usage: `basename $0` <vm> [hard|soft]" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
vm="$1"
|
||||
|
||||
vmid="`vmid \"${vm}\"`"
|
||||
if [ "${vmid}" = "" ]; then
|
||||
echo "Cannot find virtual machine ${vm}" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
vmware-vim-cmd vmsvc/${mode} ${vmid}
|
18
vmware/files/scripts/vmware-suspend
Executable file
18
vmware/files/scripts/vmware-suspend
Executable file
|
@ -0,0 +1,18 @@
|
|||
#!/bin/sh
|
||||
|
||||
. /usr/local/lib/vmware.sh
|
||||
|
||||
if [ $# -ne 1 ]; then
|
||||
echo "Usage: `basename $0` <vm>" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
vm="$1"
|
||||
|
||||
vmid="`vmid \"${vm}\"`"
|
||||
if [ "${vmid}" = "" ]; then
|
||||
echo "Cannot find virtual machine ${vm}" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
vmware-vim-cmd vmsvc/power.suspend ${vmid}
|
18
vmware/files/scripts/vmware-unregister
Executable file
18
vmware/files/scripts/vmware-unregister
Executable file
|
@ -0,0 +1,18 @@
|
|||
#!/bin/sh
|
||||
|
||||
. /usr/local/lib/vmware.sh
|
||||
|
||||
if [ $# -ne 1 ]; then
|
||||
echo "Usage: `basename $0` <vm>" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
vm="$1"
|
||||
|
||||
vmid="`vmid \"$1\"`"
|
||||
if [ "${vmid}" == "" ]; then
|
||||
echo "Cannot find virtual machine ${vm}" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
vmware-vim-cmd vmsvc/unregister ${vmid}
|
113
vmware/files/scripts/vmware.sh
Normal file
113
vmware/files/scripts/vmware.sh
Normal file
|
@ -0,0 +1,113 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# $Id: vmware.sh,v 1.4 2009/07/29 20:04:19 root Exp $
|
||||
#
|
||||
|
||||
# List all datastores on server
|
||||
list_datastores() {
|
||||
vmware-vim-cmd hostsvc/storage/fs_info | awk '
|
||||
/^[ ]*path = / {
|
||||
path = substr($3, 2, length($3)-3)
|
||||
}
|
||||
/^[ ]*name = / {
|
||||
print substr($3, 2, length($3)-3) " " path
|
||||
}
|
||||
'
|
||||
}
|
||||
|
||||
|
||||
# Get list of all registered virtual machines.
|
||||
#
|
||||
# Returns list in format:
|
||||
#
|
||||
# vmid|displayName|path
|
||||
#
|
||||
list_vms() {
|
||||
vmware-vim-cmd vmsvc/getallvms | sed -n \
|
||||
's/^\([0-9][0-9]*\)[ ]*\([^ ]*\)[ ]*\(\[[^ ]*\] [^ ]*\).*/\1|\2|\3/p'
|
||||
}
|
||||
|
||||
|
||||
# Convert given path into datastore format.
|
||||
#
|
||||
# Eg. dspath /vmfs/volumes/mystore/foo.vmx returns
|
||||
# [mystore] foo.vmx
|
||||
#
|
||||
dspath() {
|
||||
case "$1" in
|
||||
/*)
|
||||
list_datastores | while read n p ; do
|
||||
echo "$1" | egrep -q "^${p}" || continue
|
||||
echo -n "[${n}] "
|
||||
echo "$1" | cut -c `echo ${p} | wc -m`- | cut -c 2-
|
||||
break
|
||||
done
|
||||
;;
|
||||
[*)
|
||||
echo "$1"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
|
||||
# Convert given path into filesystem format.
|
||||
#
|
||||
# Eg. abspath [mystore] foo.vmx returns
|
||||
# /vmfs/volumes/mystore/foo.vmx
|
||||
#
|
||||
abspath() {
|
||||
case "$1" in
|
||||
/*)
|
||||
echo "$1"
|
||||
;;
|
||||
[*)
|
||||
ds=`echo "$1" | sed -e 's/^\[\(.*\)\] .*$/\1/'`
|
||||
vmware-vim-cmd hostsvc/datastore/info ds-local | \
|
||||
sed -n 's/^[ ]*path = \"\(.*\)\",[ ]*/\1/p' | uniq | tr '\n' '/'
|
||||
echo "$1" | sed -e 's/^\[.*\] \(.*\)$/\1/'
|
||||
;;
|
||||
[0-9]*)
|
||||
abspath "`list_vms | sed -n \"s/^$1|.*|\(\[.*\] .*\)$/\1/p\"`"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
|
||||
# Get id for given virtual machine
|
||||
#
|
||||
vmid() {
|
||||
case "$1" in
|
||||
/*)
|
||||
ds="`dspath "\${1}\"`"
|
||||
if [ "${ds}" == "" ]; then
|
||||
exit
|
||||
fi
|
||||
list_vms | awk -F'|' '{print $1 " " $3}' | while read vmid vmpath ; do
|
||||
if [ "${vmpath}" = "${ds}" ]; then
|
||||
echo ${vmid}
|
||||
break
|
||||
fi
|
||||
done
|
||||
;;
|
||||
[*)
|
||||
list_vms | awk -F'|' '{print $1 " " $3}' | while read vmid vmpath ; do
|
||||
if [ "${vmpath}" = "${1}" ]; then
|
||||
echo ${vmid}
|
||||
break
|
||||
fi
|
||||
done
|
||||
;;
|
||||
*)
|
||||
list_vms | awk -F'|' '{print $1 " " $2}' | while read vmid vmname ; do
|
||||
if [ "${vmid}" = "${1}" ]; then
|
||||
echo ${vmid}
|
||||
break
|
||||
elif [ "${vmname}" = "${1}" ]; then
|
||||
echo ${vmid}
|
||||
break
|
||||
fi
|
||||
done
|
||||
;;
|
||||
esac
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue