def start_vm(args): xenhost = Server(args.host, args.xsuser, args.xspass) xenhost.disable_known_hosts = True vm_uuid = lib.vm_by_name(xenhost, args.vm_name) lib.start_vm(xenhost, vm_uuid)
def export_xva(args): xenhost = Server(args.host, args.xsuser, args.xspass) xenhost.disable_known_hosts = True vm_uuid = lib.vm_by_name(xenhost, args.source_vm) lib.export_xva(xenhost, vm_uuid, args.target_xva)
def wait_for_halt(args): xenhost = Server(args.host, args.xsuser, args.xspass) xenhost.disable_known_hosts = True vm_uuid = lib.vm_by_name(xenhost, args.vm_name) while not lib.vm_halted(xenhost, vm_uuid): print "VM [{vm_name}] is not halted, sleeping".format( vm_name=args.vm_name) time.sleep(5)
def autostart_vm(args): xenhost = Server(args.host, args.xsuser, args.xspass) xenhost.disable_known_hosts = True vm_uuid = lib.vm_by_name(xenhost, args.vm_name) logger.info('Enabling auto_poweron on default pool') pool = xenhost.run('xe pool-list --minimal').strip() xenhost.run( 'xe pool-param-set uuid={pool} other-config:auto_poweron=true'.format( pool=pool)) logger.info('Enabling auto_poweron on guest') xenhost.run( 'xe vm-param-set uuid={vm_uuid} other-config:auto_poweron=true'.format( vm_uuid=vm_uuid))
def wait_for_vm_ssh(args): xenhost = Server(args.host, args.xsuser, args.xspass) xenhost.disable_known_hosts = True vm_uuid = lib.vm_by_name(xenhost, args.source_vm) ip_addr = "" while True: ip_addr = get_guest_ip.get_guest_ip(xenhost, vm_uuid) if ip_addr: break else: logger.info("No IP reported yet, sleeping") time.sleep(5) server = Server(ip_addr, None, None) if server.wait_for_ssh_with_retries( timeout=1, retry_condition=lambda x: x <10): print ip_addr sys.exit(0) sys.exit(1)
def command(user, password, host, guest): xenhost = boxes.Server(host, user, password) xenhost.disable_known_hosts = True vm_uuid = lib.vm_by_name(xenhost, guest) return get_guest_ip(xenhost, vm_uuid)