Skip to content

Commit

Permalink
update samples for python3
Browse files Browse the repository at this point in the history
Small changes related to python 3 compatability.

partial vmware#55
  • Loading branch information
hartsock committed Jun 26, 2014
1 parent 85dec72 commit f7dd0d0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
28 changes: 14 additions & 14 deletions sample/getallvms.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,20 @@ def PrintVmInfo(vm, depth=1):
return

summary = vm.summary
print "Name : ", summary.config.name
print "Path : ", summary.config.vmPathName
print "Guest : ", summary.config.guestFullName
print("Name : ", summary.config.name)
print("Path : ", summary.config.vmPathName)
print("Guest : ", summary.config.guestFullName)
annotation = summary.config.annotation
if annotation != None and annotation != "":
print "Annotation : ", annotation
print "State : ", summary.runtime.powerState
print("Annotation : ", annotation)
print("State : ", summary.runtime.powerState)
if summary.guest != None:
ip = summary.guest.ipAddress
if ip != None and ip != "":
print "IP : ", ip
print("IP : ", ip)
if summary.runtime.question != None:
print "Question : ", summary.runtime.question.text
print ""
print("Question : ", summary.runtime.question.text)
print("")

def main():
"""
Expand All @@ -90,10 +90,10 @@ def main():
user=args.user,
pwd=password,
port=int(args.port))
except IOError, e:
except IOError as e:
pass
if not si:
print "Could not connect to the specified host using specified username and password"
print("Could not connect to the specified host using specified username and password")
return -1

atexit.register(Disconnect, si)
Expand All @@ -104,11 +104,11 @@ def main():
vmList = vmFolder.childEntity
for vm in vmList:
PrintVmInfo(vm)
except vmodl.MethodFault, e:
print "Caught vmodl fault : " + e.msg
except vmodl.MethodFault as e:
print("Caught vmodl fault : " + e.msg)
return -1
except Exception, e:
print "Caught exception : " + str(e)
except Exception as e:
print("Caught exception : " + str(e))
return -1

return 0
Expand Down
16 changes: 8 additions & 8 deletions sample/poweronvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def main():
try:
vmnames = args.vmname
if not len(vmnames):
print "No virtual machine specified for poweron"
print("No virtual machine specified for poweron")
sys.exit()

si = None
Expand All @@ -116,10 +116,10 @@ def main():
user=args.user,
pwd=password,
port=int(args.port))
except IOError, e:
except IOError as e:
pass
if not si:
print "Cannot connect to specified host using specified username and password"
print("Cannot connect to specified host using specified username and password")
sys.exit()

atexit.register(Disconnect, si)
Expand All @@ -139,11 +139,11 @@ def main():
# Wait for power on to complete
WaitForTasks(tasks, si)

print "Virtual Machine(s) have been powered on successfully"
except vmodl.MethodFault, e:
print "Caught vmodl fault : " + e.msg
except Exception, e:
print "Caught Exception : " + str(e)
print("Virtual Machine(s) have been powered on successfully")
except vmodl.MethodFault as e:
print("Caught vmodl fault : " + e.msg)
except Exception as e:
print("Caught Exception : " + str(e))

# Start program
if __name__ == "__main__":
Expand Down

0 comments on commit f7dd0d0

Please sign in to comment.