Nov 25, 2023, 12:44 PM
This commit is contained in:
parent
76f1e4b6a5
commit
e3e27df519
1
shell-frags/RackRentalVirtualPowerMgmt/README.md
Normal file
1
shell-frags/RackRentalVirtualPowerMgmt/README.md
Normal file
@ -0,0 +1 @@
|
|||||||
|
# power-vtps
|
10
shell-frags/RackRentalVirtualPowerMgmt/esxi-PowerCycle.ps1
Normal file
10
shell-frags/RackRentalVirtualPowerMgmt/esxi-PowerCycle.ps1
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
param(
|
||||||
|
[string]$vcenter,
|
||||||
|
[string]$vm
|
||||||
|
)
|
||||||
|
|
||||||
|
Get-Module -ListAvailable PowerCLI* | Import-Module -Verbose:$false > /dev/null
|
||||||
|
Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false > /dev/null
|
||||||
|
Connect-ViServer -Server $vcenter -User tplab\powervtps -Password h7x14vFGkJr5 -Verbose:$false > /dev/null
|
||||||
|
Stop-VM -RunAsync -VM "$vm" -Confirm:$false -Verbose:$false > /dev/null
|
||||||
|
Start-VM -RunAsync -VM "$vm" -Confirm:$false -Verbose:$false > /dev/null
|
9
shell-frags/RackRentalVirtualPowerMgmt/esxi-PowerOff.ps1
Normal file
9
shell-frags/RackRentalVirtualPowerMgmt/esxi-PowerOff.ps1
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
param(
|
||||||
|
[string]$vcenter,
|
||||||
|
[string]$vm
|
||||||
|
)
|
||||||
|
|
||||||
|
Get-Module -ListAvailable PowerCLI* | Import-Module -Verbose:$false > /dev/null
|
||||||
|
Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false > /dev/null
|
||||||
|
Connect-ViServer -Server $vcenter -User tplab\powervtps -Password h7x14vFGkJr5 -Verbose:$false > /dev/null
|
||||||
|
Stop-VM -RunAsync -VM "$vm" -Confirm:$false -Verbose:$false > /dev/null
|
9
shell-frags/RackRentalVirtualPowerMgmt/esxi-PowerOn.ps1
Normal file
9
shell-frags/RackRentalVirtualPowerMgmt/esxi-PowerOn.ps1
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
param(
|
||||||
|
[string]$vcenter,
|
||||||
|
[string]$vm
|
||||||
|
)
|
||||||
|
|
||||||
|
Get-Module -ListAvailable PowerCLI* | Import-Module -Verbose:$false > /dev/null
|
||||||
|
Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false > /dev/null
|
||||||
|
Connect-ViServer -Server $vcenter -User tplab\powervtps -Password h7x14vFGkJr5 -Verbose:$false > /dev/null
|
||||||
|
Start-VM -RunAsync -VM "$vm" -Confirm:$false -Verbose:$false > /dev/null
|
12
shell-frags/RackRentalVirtualPowerMgmt/kvm-PowerCycle.sh
Normal file
12
shell-frags/RackRentalVirtualPowerMgmt/kvm-PowerCycle.sh
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
VMHOSTFULL="$1"
|
||||||
|
USER_SUPPLIED_VMNAME="$2"
|
||||||
|
SSH_ALIAS="ssh -q"
|
||||||
|
|
||||||
|
VIRSH_ALIAS="virsh -c qemu+ssh://root@$VMHOSTFULL/system?no_verify=1"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$VIRSH_ALIAS destroy $USER_SUPPLIED_VMNAME
|
||||||
|
$VIRSH_ALIAS start $USER_SUPPLIED_VMNAME
|
11
shell-frags/RackRentalVirtualPowerMgmt/kvm-PowerOff.sh
Normal file
11
shell-frags/RackRentalVirtualPowerMgmt/kvm-PowerOff.sh
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
VMHOSTFULL="$1"
|
||||||
|
USER_SUPPLIED_VMNAME="$2"
|
||||||
|
SSH_ALIAS="ssh -q"
|
||||||
|
|
||||||
|
VIRSH_ALIAS="virsh -c qemu+ssh://root@$VMHOSTFULL/system?no_verify=1"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$VIRSH_ALIAS destroy $USER_SUPPLIED_VMNAME
|
10
shell-frags/RackRentalVirtualPowerMgmt/kvm-PowerOn.sh
Normal file
10
shell-frags/RackRentalVirtualPowerMgmt/kvm-PowerOn.sh
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
VMHOSTFULL="$1"
|
||||||
|
USER_SUPPLIED_VMNAME="$2"
|
||||||
|
SSH_ALIAS="ssh -q"
|
||||||
|
|
||||||
|
VIRSH_ALIAS="virsh -c qemu+ssh://root@$VMHOSTFULL/system?no_verify=1"
|
||||||
|
|
||||||
|
|
||||||
|
$VIRSH_ALIAS start $USER_SUPPLIED_VMNAME
|
136
shell-frags/RackRentalVirtualPowerMgmt/nocpowervtps.sh
Normal file
136
shell-frags/RackRentalVirtualPowerMgmt/nocpowervtps.sh
Normal file
@ -0,0 +1,136 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
#function declarations
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
usage()
|
||||||
|
#Usage message
|
||||||
|
{
|
||||||
|
|
||||||
|
echo "$0 needs to be invoked with two required argument:
|
||||||
|
----------------------------------------------------------------------------
|
||||||
|
--jig ottov<xx>
|
||||||
|
--action (One of: on,off,cycle)
|
||||||
|
----------------------------------------------------------------------------"
|
||||||
|
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
error_out()
|
||||||
|
#Error reporting code
|
||||||
|
{
|
||||||
|
echo "A critical error has occured. Please see above line for portion that failed."
|
||||||
|
echo "This script will now exit..."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
bail_out()
|
||||||
|
#Exit code
|
||||||
|
{
|
||||||
|
echo "Exiting...."
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
#Start execution
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
if [[ $# -eq 0 ]]; then
|
||||||
|
usage
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$1" = "-help" ]; then
|
||||||
|
usage
|
||||||
|
fi
|
||||||
|
|
||||||
|
COUNTER=0
|
||||||
|
ARGS=("$@")
|
||||||
|
while [ $COUNTER -lt $# ]
|
||||||
|
do
|
||||||
|
arg=${ARGS[$COUNTER]}
|
||||||
|
let COUNTER=COUNTER+1
|
||||||
|
nextArg=${ARGS[$COUNTER]}
|
||||||
|
argKey="$arg"
|
||||||
|
argVal="$nextArg"
|
||||||
|
skipNext=1
|
||||||
|
|
||||||
|
case "$argKey" in
|
||||||
|
--jig)
|
||||||
|
export USER_SUPPLIED_VMNAME="$argVal"
|
||||||
|
;;
|
||||||
|
--action)
|
||||||
|
export USER_SUPPLIED_ACTION="$argVal"
|
||||||
|
;;
|
||||||
|
-h|--help|-help|--h)
|
||||||
|
usage
|
||||||
|
exit
|
||||||
|
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
#Check for proper inputs
|
||||||
|
|
||||||
|
#Check for vmName
|
||||||
|
echo "Checking if DUT name was provided..."
|
||||||
|
if [ -z "$USER_SUPPLIED_VMNAME" ]; then
|
||||||
|
error_out
|
||||||
|
else
|
||||||
|
echo "Using DUT $USER_SUPPLIED_VMNAME"
|
||||||
|
fi
|
||||||
|
|
||||||
|
#Check for action
|
||||||
|
echo "Checking if action was provided..."
|
||||||
|
if [ -z $USER_SUPPLIED_ACTION ]; then
|
||||||
|
error_out
|
||||||
|
else
|
||||||
|
echo "Performing action $USER_SUPPLIED_ACTION"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "All preflight checks passsed. Proceeding with power operation."
|
||||||
|
|
||||||
|
|
||||||
|
export LMOUT="$(labman device $USER_SUPPLIED_VMNAME)"
|
||||||
|
export VCENTER_FQDN="$(echo "$LMOUT" | grep -w 'VM Management Server' |awk -F ':' '{print $2}'|sed 's/ //g')"
|
||||||
|
export VMHOSTFULL="$(echo "$LMOUT" | grep -w 'VM Host' |awk -F ':' '{print $2}'|sed 's/ //g')"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if [ $(echo $VMHOSTFULL | grep esxi -c) -eq 1 ]; then
|
||||||
|
|
||||||
|
if [ "$USER_SUPPLIED_ACTION" = on ] ; then
|
||||||
|
echo "Powering $USER_SUPPLIED_VMNAME in $VCENTER_FQDN on..."
|
||||||
|
powershell /local/powervtps/nocpowervtps/esxi-PowerOn.ps1 $VCENTER_FQDN $USER_SUPPLIED_VMNAME
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$USER_SUPPLIED_ACTION" = off ] ; then
|
||||||
|
echo "Powering $USER_SUPPLIED_VMNAME in $VCENTER_FQDN off..."
|
||||||
|
powershell /local/powervtps/nocpowervtps/esxi-PowerOff.ps1 $VCENTER_FQDN $USER_SUPPLIED_VMNAME
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$USER_SUPPLIED_ACTION" = cycle ] ; then
|
||||||
|
echo "Cycling $USER_SUPPLIED_VMNAME in $VCENTER_FQDN..."
|
||||||
|
powershell /local/powervtps/nocpowervtps/esxi-PowerCycle.ps1 $VCENTER_FQDN $USER_SUPPLIED_VMNAME
|
||||||
|
fi
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $(echo $VMHOSTFULL | grep kvm -c) -eq 1 ]; then
|
||||||
|
|
||||||
|
if [ "$USER_SUPPLIED_ACTION" = on ] ; then
|
||||||
|
echo "Powering $USER_SUPPLIED_VMNAME on $VMHOSTFULL on..."
|
||||||
|
bash /local/powervtps/nocpowervtps/kvm-PowerOn.sh $VMHOSTFULL $USER_SUPPLIED_VMNAME
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$USER_SUPPLIED_ACTION" = off ] ; then
|
||||||
|
echo "Powering $USER_SUPPLIED_VMNAME on $VMHOSTFULL off..."
|
||||||
|
bash /local/powervtps/nocpowervtps/kvm-PowerOff.sh $VMHOSTFULL $USER_SUPPLIED_VMNAME
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$USER_SUPPLIED_ACTION" = cycle ] ; then
|
||||||
|
echo "Cycling $USER_SUPPLIED_VMNAME on $VMHOSTFULL..."
|
||||||
|
bash /local/powervtps/nocpowervtps/kvm-PowerCycle.sh $VMHOSTFULL $USER_SUPPLIED_VMNAME
|
||||||
|
fi
|
||||||
|
fi
|
Loading…
Reference in New Issue
Block a user