Esempio n. 1
0
def main(inventory_file, deployment_file, api_key):
    key = getattr(constants, api_key)
    print('API key gathered')

    inventory = helpers.parse_yaml(inventory_file)
    print('Inventory file "{}" parsed.'.format(inventory_file))

    deployment = helpers.parse_yaml("deployments/" + deployment_file)
    print('Deployment file "{}" parsed.'.format(deployment_file))

    for device, details in deployment.items():
        generated_config = helpers.generate_cfg_from_template(
            "templates/" + details['template'], details['data'])
        print('\n\tConfig for "{}" generated.'.format(device))

        prepared_config = helpers.prep_config(generated_config, key)
        print('\tConfig prepared.')

        print('\tPushing config to "{}"'.format(device))
        r = helpers.post_config(inventory[device]['address'], prepared_config)

        print('\tReturned result is "{}"'.format(r.text))

        print('\tSaving configuration...')
        r = helpers.save_config(inventory[device]['address'], key)
        print('\tReturned result is "{}"'.format(r.text))
Esempio n. 2
0
def main(inventory, verbose):
    parsed_inventory = helpers.parse_yaml(inventory)
    password = getpass.getpass('Please enter a password: '******'password'] = password
        config = helpers.run_show(params, COMMAND, verbose=verbose)
        configs[device] = config

    parsed_vrrp_dict = parse_vrrp(configs, VRRP_REGEX)

    for device, params in parsed_inventory.items():
        generated_config = generate_config(parsed_vrrp_dict[device])
        connection = helpers.connect(address=params['address'],
                                     username=params['username'],
                                     password=params['password'],
                                     port=params['port'])
        connection.login()
        connection.configure()
        print(device)
        print(generated_config)
        actions = helpers.run_commands(connection,
                                       generated_config,
                                       verbose=verbose)
        helpers.commit_and_save(connection, actions, verbose=True)
        connection.exit()
        connection.logout()
Esempio n. 3
0
def main(inventory, verbose, full, exclude):
    parsed_inventory = helpers.parse_yaml(inventory)
    password = getpass.getpass('Please enter a password: '******'show configuration commands | no-more'
    configs = []
    for device, params in parsed_inventory.items():
        params['password'] = password
        config = helpers.run_show(params, command, verbose=verbose)
        configs.append(config)
    
    if exclude:
        exclude_list = helpers.parse_yaml(exclude)
        filtered_left = helpers.filter_list(configs[0], exclude_list)
        filtered_right = helpers.filter_list(configs[1], exclude_list)
        diff = difflib.ndiff(filtered_left, filtered_right)
    else:
        diff = difflib.ndiff(configs[0], configs[1])
    
    for line in diff:
        if full:
            print(line.strip())
        else:
           if line.startswith(('*', '?', '+', '-')):
                print(line.strip())
Esempio n. 4
0
def main(inventory, commands, save, verbose):
    parsed_inventory = helpers.parse_yaml(inventory)
    password = getpass.getpass('Please enter a password: '******'password'] = password
        helpers.deploy(params, commands, save=save, verbose=verbose)
Esempio n. 5
0
  parse_yaml,
  dir_path
)

from cx_Oracle import (
  makedsn,
)

from infa_classes import (
  Infa_Rep,
  log,
  compare_repo_folder,
)


creds = parse_yaml(dir_path + '/creds.yml')
cred = d2(creds['INFA_DEV'])
cred = d2(creds['INFA_QA'])

def create_engine(cred):
  cred = d2(cred)
  if cred.type == 'oracle':
    dnsStr = makedsn(cred.host, cred.port, service_name=cred.instance)
    # dnsStr = cx_Oracle.makedsn(cred.host,cred.port,sid=cred.instance)
    # conn_str = 'oracle+cx_oracle://{user}:{password}@{host}:{port}/{instance}'
    conn_str = 'oracle+cx_oracle://{user}:{password}@' + dnsStr
  elif cred.type == 'mssql':
    conn_str = 'mssql+pymssql://{user}:{password}@{host}:{port}/{instance}'

  return sqlalchemy.create_engine(conn_str.format(**cred), pool_size=10)
def test_parse_yaml():
    path = os.path.join("tests", "api", "sample_config.yml")
    actual_output = parse_yaml(path)
    expected_output = {"test": {"test_host": "localhost:8080"}}
    assert actual_output == expected_output