예제 #1
0
파일: machine.py 프로젝트: iMorozov/ceasar
# args check
if len(sys.argv) >= 3:
    machines = []
    flines = []
    tmp = sys.argv[1:][0].split()
    for p in tmp: # prepare machine list
        if p[0] == '@': # if list
            with open(basepath+p[1:], 'r') as f: flines  = f.read().splitlines()
            machines = machines+flines
        else:
            machines.append(p)
    print 'Job will be executed at:', machines

    for m in machines:
        if validate_regexp(m) == True:
            found_machine = preg_grep('.*'+m+'.*', config)
            if len(found_machine) == 1:
                load_machine(config[found_machine[0]])
                for i in sys.argv[2:]:
                    if validate_regexp(i) == True:
                        found_cmd = preg_grep('.*'+i+'.*', machine['job'])
                        if len(found_cmd) == 1:
                            print found_machine[0]+': job ->', found_cmd[0]
                            print dfl( do(machine['job'][found_cmd[0]]) )
                        else:
                            print found_machine[0]+': job ->', i, '- not found'
                    else:
                       print found_machine[0], '- invalid job'
            else:
                print 'len(found_machine) =', len(found_machine)
        else:
예제 #2
0
파일: cisco.py 프로젝트: iMorozov/ceasar
           exit()
       else:
           print 'bad encrypt'
           exit()

    for p in tmp: # prepare device list
        if p[0] == '@': # if list
            with open(basepath+p[1:], 'r') as f: flines  = f.read().splitlines()
            devices = devices+flines
        else:
            devices.append(p)
    print 'Job will be executed at:', devices

    for d in devices: # foreach device
        if validate_regexp(d) == True:
            found_device = preg_grep('.*'+d+'.*', config)
            if len(found_device) == 1:
                load_device(config[found_device[0]])
                for i in sys.argv[2:]:
                    if validate_regexp(i) == True:

                        jobs = {}
                        if not 'job' in device:
                            device['job'] = config['defaults']['job']
                            jobs = config['defaults']['job']
                        else:
                            jobs.update(config['defaults']['job'])
                            jobs.update(device['job'])

                        found_cmd = preg_grep('.*'+i+'.*', jobs)