Created
August 7, 2015 15:03
-
-
Save pathcl/1552535ffb55931894cd to your computer and use it in GitHub Desktop.
Power on machines by uuid on VMware
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
#!/usr/bin/env python | |
# PowerOn machines based on uuid | |
from pyVim import connect | |
from tools import cli | |
from tools import tasks | |
from pyVmomi import vim | |
import ssl | |
import atexit | |
ssl._create_default_https_context = ssl._create_unverified_context | |
def setup_args(): | |
parser = cli.build_arg_parser() | |
# TODO | |
#parser.add_argument('-j', '--uuid', | |
# help='file of uuid', | |
# required=False) | |
my_args = parser.parse_args() | |
return cli.prompt_for_password(my_args) | |
ARGS = setup_args() | |
try: | |
SI = connect.SmartConnect(host=ARGS.host, | |
user=ARGS.user, | |
pwd=ARGS.password, | |
port=ARGS.port) | |
atexit.register(connect.Disconnect, SI) | |
except IOError: | |
pass | |
with open('uuid-to-poweron.txt') as uuid: | |
for line in uuid: | |
line = line.strip() | |
if uuid: | |
try: | |
VM = SI.content.searchIndex.FindByUuid(None, line, True, True) | |
print("The current powerState is: {0}".format(VM.runtime.powerState)) | |
TASK = VM.PowerOn() | |
tasks.wait_for_tasks(SI, [TASK]) | |
print("") | |
print("The current powerState is: {0}".format(VM.runtime.powerState)) | |
print("") | |
print("its done") | |
except vim.fault.InvalidPowerState: | |
print("") | |
print("{0} Its already powered On!!".format(line)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment