def power(args, server): u"""VM power control @param args Commandline argument @param server Instance of VIServer """ # Import import lib vm_names = args.vm_names for vm_name in vm_names: try: vm = server.get_vm_by_name(vm_name) if args.power == 'ON': lib.powered_on(vm, server) elif args.power == 'OFF': lib.powered_off(vm, server) elif args.power == 'Suspend': lib.suspend(vm, server) print '%s Done.' % vm_name except Exception, (strerror): print strerror
def power(args, session): u"""Powered Management @param args Commandline argument @param session Session """ # Import import sys import lib vm_names = args.vm_names for vm_name in vm_names: # Get VM vm = lib.get_vm(vm_name, session) if vm: try: if args.power == 'ON': # Powered on lib.powered_on(vm, session) elif args.power == 'OFF': # Powered off lib.powered_off(vm, session) elif args.power == 'Reboot': # Reboot lib.reboot(vm, session) elif args.power == 'Suspend': # Suspend lib.suspend(vm, session) else: # Pause lib.pause(vm, session) except: print 'Power Error for VM.' else: print 'Not found VM.'