Esempio n. 1
0
    cr.PRINT = True
    nc.PRINT = True

lab_path = args.path.replace('"', '').replace("'", '')
if args.directory:
    lab_path = args.directory.replace('"', '').replace("'", '')

# getting options from args.options and later append them to the options dictionary
additional_options = []
if args.options:
    for opt in args.options:
        app = opt.replace('"', '').replace("'", '').split("=")
        additional_options.append((app[0].strip(), app[1].strip()))

# get lab machines, options, links and metadata
(machines, links, options, metadata) = nc.lab_parse(lab_path, force=FORCE_LAB)

# applying parameter options (2/3)
# adding additional_options to options
for machine_name, _ in options.items():
    options[machine_name] = options[machine_name] + additional_options

filtered_machines = machines

# filter machines based on machine_name_args (if at least one)
if len(machine_name_args) >= 1:
    filtered_machines = dict((k, machines[k]) for k, v in machines.items()
                             if k in machine_name_args)

# if force-lab is set true and we have no machines from lab.conf we need to set machine names from args
if FORCE_LAB and (len(filtered_machines.items()) == 0):
Esempio n. 2
0
def lstart_command_writer():
    command = '"' + machine_path + '"'
    if args.xterm:
        command += " --xterm=" + args.xterm
    if args.print_only:
        command += " --print"
    if (len(sys.argv) <= 3) and args.machine_name:
        command += " -F " + args.machine_name
    return command


#starting machine already existing in current lab
if args.hostlab:
    if (os.path.exists(os.path.join(args.hostlab, "lab.conf"))):
        (machines, links, options, metadata) = nc.lab_parse(args.hostlab)
        if machines.get(args.machine_name) != None:
            #creating and updating interfaces in lab.conf
            conf_lines = {}
            if (args.eths != None):
                new_eths = eths_line_writer(args.eths)
                conf_lines = u.merge_two_dicts(
                    u.couple_list_to_dict(machines[args.machine_name]),
                    new_eths)
            else:
                conf_lines = u.couple_list_to_dict(machines[args.machine_name])
            conf_lines = conf_line_writer(conf_lines)

            create_lab(machine_path, args.machine_name, conf_lines)

            #copying and appending commands to startup file
Esempio n. 3
0
    '-F',
    '--force-lab',
    dest='force_lab',
    required=False,
    action='store_true',
    help='Force the lab to start without a lab.conf or lab.dep file.')

args, unknown = parser.parse_known_args()

lab_path = args.path.replace('"', '').replace("'", '')
if args.directory:
    lab_path = args.directory.replace('"', '').replace("'", '')

if args.full:
    has_invalid_characters = False
    (machines, links, _, _) = nc.lab_parse(lab_path, force=args.force_lab)
    for machine_name, _ in machines.items():
        if (' ' in machine_name) or ('"' in machine_name) or ("'"
                                                              in machine_name):
            has_invalid_characters = True
            break
    if not has_invalid_characters:
        for link in links:
            if (' ' in link) or ('"' in link) or ("'" in link):
                has_invalid_characters = True
                break

    if has_invalid_characters:
        print("Invalid characters in machine names or link names\n")
        sys.exit(1)
Esempio n. 4
0
parser.add_argument('path')
parser.add_argument('-d',
                    '--directory',
                    required=False,
                    help='Folder contining the lab.')
parser.add_argument(
    '--print',
    dest="print_only",
    required=False,
    action='store_true',
    help=
    'Print commands used to start the containers to stderr (containers are not started).'
)

args, unknown = parser.parse_known_args()

lab_path = args.path.replace('"', '')
if args.directory:
    lab_path = args.directory.replace('"', '')

# get lab machines, options, links and metadata
(_, _, _, metadata) = nc.lab_parse(lab_path)

if not args.print_only:
    print("========================= Starting Lab ==========================")
    if len(metadata.items()) >= 1:
        for key, value in metadata.items():
            print('{message: <20}'.format(message=key + ":") + value)
        print(
            "================================================================="
        )