def parse_options(): parser = argparse.ArgumentParser( description='Tool to simplify testing and development in RHEVM lab.') parser.add_argument('--lab', nargs=1, help='Either BOS or BRQ', default=[locals.DEFAULT_LOCATION], required=False) parser.add_argument('--template', help='The template from which the VM should be ' 'created.', required=False) parser.add_argument('--clean', help='Creates a clean VM.', action='store_true') parser.add_argument('--firewall', help='Turn the firewall on.', action='store_true') parser.add_argument('--selinux', help='Put SELinux into enforcing mode.', action='store_true') parser.add_argument('--debug', help='Just for option validation testing.', action='store_true') parser.add_argument('--build', nargs='+', metavar=('WHAT', 'WHICH'), help='Build the rpms from selected source (master, ' 'selected branch, or master with selected patch ' 'on top). For origin/master use: --build branch ' 'master. For branch use: --build branch ' 'BRANCHNAME. For patch use: --build patch ' 'PATCHNUMBER [PATCHNUMBER..]') parser.add_argument('--source', metavar='NUM', help='VM number for sources / prepared rpms. This is ' 'not needed to specify when using --build option') parser.add_argument('--replicas', metavar='NUM', type=int, help='The number of replicas to be created.') parser.add_argument('--clients', metavar='NUM', type=int, help='The number of replicas to be created.') parser.add_argument('--install', nargs=2, metavar=('WHAT', 'FROM'), help='WHAT is either ipa or packages. FROM is either ' 'rpms or repo or develrepo. ', required=False) parser.add_argument('--trust', help='Setup trust with global AD server in the lab.', action='store_true') parser.add_argument('--test', help='Run unit test suite. Use with --install ipa' 'option only.', action='store_true') parser.add_argument('--connect', help='Do not create a new VM but rather connect ' 'to existing one.', action='store_true') parser.add_argument('--remove', help='Remove VM in case it already exists.', action='store_true') parser.add_argument('--local', help='Flag that makes sure name is used as hostname.', action='store_true') parser.add_argument('--ipadevel', nargs='+', metavar=('PACKAGES'), help='Use this option to specify packages that should' 'be installed from the ipa-devel repo.') parser.add_argument( '--workspace', help='Create workspace. This is not done automatically,' ' since it is better (performance-wise) to do this' ' once in the template.', action='store_true') parser.add_argument('--name', help='The name of VM in the lab.', required=True) args = parser.parse_args() # Set global variables locals.set_locale(args.lab[0]) if args.template is None: args.template = locals.TEMPLATE_NAME if args.debug: sys.exit(0) #show('Running pre-setup checks:') #show.tab() # Additional option validation # TODO: support build validation in local VMs #if args.build and not args.local: # validateBuild(args) #if args.install: # validateInstall(args) return args
'option only.', action='store_true') parser.add_argument('--connect', help='Do not create a new VM but rather connect ' 'to existing one.', action='store_true') parser.add_argument('--name', help='The name of VM in the lab.', required=True) args = parser.parse_args() # Set global variables locals.set_locale(args.lab[0]) if args.template is None: args.template = locals.TEMPLATE_NAME if args.debug: sys.exit(0) try: main(args) except Exception, e: print '***The command above has FAILED***' print 'You can find the logs in ~/<hostname>.log on the VM' print '' print str(e)
def parse_options(): parser = argparse.ArgumentParser(description="Tool to simplify testing and development in RHEVM lab.") parser.add_argument("--lab", nargs=1, help="Either BOS or BRQ", default=[locals.DEFAULT_LOCATION], required=False) parser.add_argument("--template", help="The template from which the VM should be " "created.", required=False) parser.add_argument("--clean", help="Creates a clean VM.", action="store_true") parser.add_argument("--firewall", help="Turn the firewall on.", action="store_true") parser.add_argument("--selinux", help="Put SELinux into enforcing mode.", action="store_true") parser.add_argument("--debug", help="Just for option validation testing.", action="store_true") parser.add_argument( "--build", nargs="+", metavar=("WHAT", "WHICH"), help="Build the rpms from selected source (master, " "selected branch, or master with selected patch " "on top). For origin/master use: --build branch " "master. For branch use: --build branch " "BRANCHNAME. For patch use: --build patch " "PATCHNUMBER [PATCHNUMBER..]", ) parser.add_argument( "--source", metavar="NUM", help="VM number for sources / prepared rpms. This is " "not needed to specify when using --build option", ) parser.add_argument("--replicas", metavar="NUM", type=int, help="The number of replicas to be created.") parser.add_argument("--clients", metavar="NUM", type=int, help="The number of replicas to be created.") parser.add_argument( "--install", nargs=2, metavar=("WHAT", "FROM"), help="WHAT is either ipa or packages. FROM is either " "rpms or repo or develrepo. ", required=False, ) parser.add_argument("--trust", help="Setup trust with global AD server in the lab.", action="store_true") parser.add_argument( "--test", help="Run unit test suite. Use with --install ipa" "option only.", action="store_true" ) parser.add_argument( "--connect", help="Do not create a new VM but rather connect " "to existing one.", action="store_true" ) parser.add_argument("--remove", help="Remove VM in case it already exists.", action="store_true") parser.add_argument("--local", help="Flag that makes sure name is used as hostname.", action="store_true") parser.add_argument( "--ipadevel", nargs="+", metavar=("PACKAGES"), help="Use this option to specify packages that should" "be installed from the ipa-devel repo.", ) parser.add_argument( "--workspace", help="Create workspace. This is not done automatically," " since it is better (performance-wise) to do this" " once in the template.", action="store_true", ) parser.add_argument("--name", help="The name of VM in the lab.", required=True) args = parser.parse_args() # Set global variables locals.set_locale(args.lab[0]) if args.template is None: args.template = locals.TEMPLATE_NAME if args.debug: sys.exit(0) # show('Running pre-setup checks:') # show.tab() # Additional option validation # TODO: support build validation in local VMs # if args.build and not args.local: # validateBuild(args) # if args.install: # validateInstall(args) return args
configfile.write(resulttext) with open(testrc_file, 'w') as testrcfile: testrcfile.write(locals.TESTRCSKEL % (testrc_hosts[0], " ".join(testrc_hosts[1:]), config_file)) if __name__ == '__main__': prefix = options.prefix or os.environ['USER'] num_replicas = options.num_vms or locals.NUM_VMS if options.initial_vm_num: vm_array = range(options.initial_vm_num, num_replicas + 1) else: vm_array = range(num_replicas + 1)[1:] vm_suffix = options.suffix or locals.VM_SUFFIX locals.set_locale(options.lab) api = RHEVM(url=locals.URL, cluster_name=locals.CLUSTER_NAME, ca_file=locals.CA_FILE, username=locals.USERNAME, password=locals.PASSWORD, kerberos=locals.KERBEROS) template_name = options.template or locals.TEMPLATE_NAME if options.action == 'create': create_vms(prefix, vm_suffix, template_name, vm_array) elif options.action == 'start': vm_list = get_vm_list(prefix, vm_suffix, vm_array) start_vms(vm_list) elif options.action == 'snapshot': vm_list = get_vm_list(prefix, vm_suffix, vm_array) make_snapshots(vm_list) elif options.action == 'revert':