示例#1
0
def get_inventory(clean=True, extra_args=None):
    "Return the inventory mapping in a dict."
    # Use the list argument to more closely mirror
    # Ansible's use of the callable.
    args = {'config': TARGET_DIR, 'list': True, 'environment': BASE_ENV_DIR}
    if extra_args:
        args.update(extra_args)
    try:
        inventory_string = di.main(**args)
        inventory = json.loads(inventory_string)
        return inventory
    finally:
        if clean:
            # Remove the file system artifacts since we want to force
            # fresh runs
            cleanup()
def get_inventory(clean=True, extra_args=None):
    "Return the inventory mapping in a dict."
    # Use the list argument to more closely mirror
    # Ansible's use of the callable.
    args = {'config': TARGET_DIR, 'list': True,
            'environment': BASE_ENV_DIR}
    if extra_args:
        args.update(extra_args)
    try:
        inventory_string = di.main(**args)
        inventory = json.loads(inventory_string)
        return inventory
    finally:
        if clean:
            # Remove the file system artifacts since we want to force
            # fresh runs
            cleanup()
 def test_duplicated_ip(self):
     self.duplicate_ip()
     self.write_config()
     with self.assertRaises(di.MultipleHostsWithOneIPError) as context:
         di.main(config=TARGET_DIR, check=True, environment=BASE_ENV_DIR)
     self.assertEqual(context.exception.ip, '172.29.236.100')
 def test_checking_good_config(self):
     output = di.main(config=TARGET_DIR, check=True,
                      environment=BASE_ENV_DIR)
     self.assertEqual(output, 'Configuration ok!')
 def test_duplicated_ip(self):
     self.duplicate_ip()
     self.write_config()
     with self.assertRaises(di.MultipleHostsWithOneIPError) as context:
         di.main(config=TARGET_DIR, check=True, environment=BASE_ENV_DIR)
     self.assertEqual(context.exception.ip, '172.29.236.100')
 def test_checking_good_config(self):
     output = di.main(config=TARGET_DIR, check=True,
                      environment=BASE_ENV_DIR)
     self.assertEqual(output, 'Configuration ok!')
示例#7
0
        '--check',
        help="Configuration check only, don't generate inventory",
        action='store_true',
    )

    parser.add_argument(
        '-d',
        '--debug',
        help=('Output debug messages to log file. '
              'File is appended to, not overwritten'),
        action='store_true',
        default=False,
    )

    parser.add_argument(
        '-e',
        '--environment',
        help=('Directory that contains the base env.d directory.\n'
              'Defaults to <OSA_ROOT>/inventory/.'),
        required=False,
        default=os.path.dirname(__file__),
    )

    return vars(parser.parse_args(arg_list))


if __name__ == '__main__':
    all_args = args(sys.argv[1:])
    output = generate.main(**all_args)
    print(output)
        '--check',
        help="Configuration check only, don't generate inventory",
        action='store_true',
    )

    parser.add_argument(
        '-d',
        '--debug',
        help=('Output debug messages to log file. '
              'File is appended to, not overwritten'),
        action='store_true',
        default=False,
    )

    parser.add_argument(
        '-e',
        '--environment',
        help=('Directory that contains the base env.d directory.\n'
              'Defaults to <OSA_ROOT>/inventory/.'),
        required=False,
        default=os.path.dirname(__file__),
    )

    return vars(parser.parse_args(arg_list))


if __name__ == '__main__':
    all_args = args(sys.argv[1:])
    output = generate.main(**all_args)
    print(output)