Beispiel #1
0
def main(argv):

    prependString = ""
    replace_vms = False
    esxi_file = "esxi_config.json"

    try:
        opts, args = getopt.getopt(argv[1:], "c:hp:r", ["prependString="])
    except getopt.GetoptError:
        print argv[0] + ' -n <numProcessors>'
        sys.exit(2)
    for opt, arg in opts:
        if opt == '-h':
            print argv[0] + " [options]"
            print '-c <file>, --esxiConfig=<file>   use alternate hypervisor config file'
            print '-p <string>, --prependString=<file>   prepend string to the beginning of VM names'
            print '-r, --replace                     replace existing msf_host'
            sys.exit()
        elif opt in ("-c", "--esxiConfig"):
            esxi_file = arg
        elif opt in ("-p", "--prependString"):
            prependString = arg
        elif opt in ("-r", "--replace"):
            replace_vms = True

    targets = glob.glob('msf_host_packer.json')

    vm_server = serverHelper(esxi_file)

    os.chdir("boxcutter/ubuntu")

    for target in tqdm(targets):
        build_base(target, replace_existing=replace_vms, vmServer=vm_server, prependString=prependString)

    return True
Beispiel #2
0
def main(argv):

    prependString = ""
    replace_vms = False
    esxi_file = "esxi_config.json"

    try:
        opts, args = getopt.getopt(argv[1:], "c:hp:r", ["prependString="])
    except getopt.GetoptError:
        print argv[0] + ' -n <numProcessors>'
        sys.exit(2)
    for opt, arg in opts:
        if opt == '-h':
            print argv[0] + " [options]"
            print '-c <file>, --esxiConfig=<file>   use alternate hypervisor config file'
            print '-p <string>, --prependString=<file>   prepend string to the beginning of VM names'
            print '-r, --replace                     replace existing msf_host'
            sys.exit()
        elif opt in ("-c", "--esxiConfig"):
            esxi_file = arg
        elif opt in ("-p", "--prependString"):
            prependString = arg
        elif opt in ("-r", "--replace"):
            replace_vms = True

    vm_server = serverHelper(esxi_file)

    os.chdir("boxcutter")

    for os_dir in os.listdir("."):
        if os.path.isdir(os.path.join(".", os_dir)):
            common_var_file = os.path.join("..", "linux_vars", os_dir + "_common.json")
            with open(os.path.join("", common_var_file)) as common_var_source:
                common_vars = json.load(common_var_source)

            os.chdir(os.path.join("", os_dir))
            packer_file = os_dir + ".json"

            targets = []
            for pattern in common_vars['file_patterns']:
                targets.extend(glob.glob(pattern))

            print "\nBuilding " + str(len(targets)) + " " + os_dir.capitalize() + " baselines:"
            for target in tqdm(targets):
                build_base(target, common_vars, packer_file, replace_existing=replace_vms, vmServer=vm_server, prependString=prependString)

            os.chdir("../")

    return True
def main(argv):
    num_processors = 1
    prependString = ""
    replace_vms = False

    try:
        opts, args = getopt.getopt(argv[1:], "c:hn:p:r", ["numProcessors="])
    except getopt.GetoptError:
        print argv[0] + ' -n <numProcessors>'
        sys.exit(2)
    for opt, arg in opts:
        if opt == '-h':
            print argv[0] + " [options]"
            print '-c <file>, --esxiConfig=<file>   use alternate hypervisor config file'
            print '-n <int>, --numProcessors=<int>   execute <int> parallel builds'
            print '-p <string>, --prependString=<file>   prepend string to the beginning of VM names'
            print '-r, --replace                     replace existing baselines'
            sys.exit()
        elif opt in ("-n", "--numProcessors"):
            num_processors = int(arg)
        elif opt in ("-c", "--esxiConfig"):
            global esxi_file
            esxi_file = arg
        elif opt in ("-p", "--prependString"):
            prependString = arg
        elif opt in ("-r", "--replace"):
            replace_vms = True

    with open("iso_list.json", 'r') as iso_config:
        iso_map = json.load(iso_config)

    original_sigint_handler = signal.signal(signal.SIGINT, signal.SIG_IGN)

    pool = None
    try:
        vmServer = serverHelper(esxi_file)
        if replace_vms and vmServer.get_esxi() is not None:
            print "removing baselines"
            for file_name in tqdm(iso_map):
                remove_baseline(vmServer, file_name, prependString)

        print "generating baselines"
        if num_processors > 1:
            pool = multiprocessing.Pool(num_processors)

            signal.signal(signal.SIGINT, original_sigint_handler)

            results = []
            for file_name in iso_map:
                pool.apply_async(build_base, [
                    file_name, iso_map[file_name], replace_vms, vmServer,
                    prependString
                ],
                                 callback=results.append)

            with tqdm(total=len(iso_map)) as progress:
                current_len = 0
                while len(results) < len(iso_map):
                    if (len(results) > current_len):
                        progress.update(len(results) - current_len)
                        current_len = len(results)
                    else:
                        progress.refresh()
                    time.sleep(5)
                progress.update(len(results))
        else:
            signal.signal(signal.SIGINT, original_sigint_handler)
            for file_name in tqdm(iso_map):
                build_base(file_name, iso_map[file_name], replace_vms,
                           vmServer, prependString)

    except KeyboardInterrupt:
        print("User cancel received, terminating all builds")
        if pool is not None:
            pool.terminate()
    else:
        print("Build complete")
        if pool is not None:
            pool.close()
            pool.join()