Created
February 20, 2019 06:09
-
-
Save tenstormavi/8aba2bd382cab059764d98adfeeb6758 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#################################### | |
## This method will check the power status of the VM and will off the vm based on the condition provided | |
############################################# | |
vmware = $evm.vmdb('ems').find_by_name('vmware-XL') | |
#method to power off first 500 vms | |
first_slot = vmware.vms.first(500) | |
first_slot.each do |vm| | |
$evm.log("info", "VM name is #{vm.name}") | |
if vm.power_state == 'on' | |
vm.stop | |
else | |
$evm.log('info', "Do nothing") | |
end | |
end | |
=begin | |
#Code will execute the method in batch of 50 vms . 1000 vms in your provider 1000/50 = 20 batches | |
vmware.vms.each_slice(50) do |batch| | |
batch.each do |vm| | |
$evm.log('info', "VM Name is #{vm.name}") | |
if vm.power_state == 'on' | |
vm.power_off | |
sleep(10) | |
$evm.log('info', "VM is with power state #{vm.power_state}") | |
else | |
$evm.log('info', "VM is powered off") | |
end | |
end | |
end | |
=end | |
#################################### | |
## This method will check the power status of the VM and will off the vm based on the condition provided | |
############################################# | |
vmware = $evm.vmdb('ems').find_by_name('vmware-XL') | |
#method to power off first 250 vms | |
first_slot = vmware.vms.first(250) | |
first_slot.each do |vm| | |
if vm.power_state == 'off' | |
$evm.log("info", "VM name is #{vm.name}") | |
vm.start | |
else | |
$evm.log('info', "Do nothing") | |
end | |
end | |
=begin | |
#Code will execute the method in batch of 50 vms . 1000 vms in your provider 1000/50 = 20 batches | |
vmware.vms.each_slice(50) do |batch| | |
batch.each do |vm| | |
$evm.log('info', "VM Name is #{vm.name}") | |
if vm.power_state == 'on' | |
vm.power_off | |
sleep(10) | |
$evm.log('info', "VM is with power state #{vm.power_state}") | |
else | |
$evm.log('info', "VM is powered off") | |
end | |
end | |
end | |
=end | |
#################################### | |
## This method will check the power status of the VM and will off the vm based on the condition provided | |
############################################# | |
vmware = $evm.vmdb('ems').find_by_name('vmware-L') | |
#method to power off first 250 vms | |
#first_slot = vmware.vms.first(250) | |
vmware.vms.each do |vm| | |
if vm.power_state == 'on' | |
$evm.log("info", "VM name is #{vm.name}") | |
vm.stop | |
else | |
$evm.log('info', "Do nothing") | |
end | |
end | |
=begin | |
#Code will execute the method in batch of 50 vms . 1000 vms in your provider 1000/50 = 20 batches | |
vmware.vms.each_slice(50) do |batch| | |
batch.each do |vm| | |
$evm.log('info', "VM Name is #{vm.name}") | |
if vm.power_state == 'on' | |
vm.power_off | |
sleep(10) | |
$evm.log('info', "VM is with power state #{vm.power_state}") | |
else | |
$evm.log('info', "VM is powered off") | |
end | |
end | |
end | |
=end | |
# | |
# Description: <Method description here> | |
# | |
vmware = $evm.vmdb('ems').find_by_name('vmware-L') | |
vm1 = $evm.vmdb('vm').find_by_name('DC0_H69_VM3') | |
vm1.stop | |
$evm.log('info',"Vm is stopped #{vm1.name}") | |
=begin | |
#method to power off first 10 vms | |
first_slot = vmware.vms.first(10) | |
first_slot.each do |vm| | |
if vm.power_state == 'on' | |
$evm.log("info", "VM name is #{vm.name}") | |
vm.stop | |
else | |
$evm.log('info', "Do nothing") | |
end | |
end | |
=end | |
================================== | |
vmware = $evm.vmdb('ems').find_by_name('vmware-L') | |
first_slot = vmware.vms.first(1500) | |
first_slot.each do |vm| | |
if vm.power_state == 'on' | |
$evm.log("info", "VM name is #{vm.name}") | |
vm.stop | |
end | |
end | |
vmware = $evm.vmdb('ems').find_by_name('vmware-L') | |
vmware.vms.each do |vm| | |
if vm.power_state == 'off' | |
$evm.log("info", "VM name is #{vm.name}") | |
vm.start | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment