コード例 #1
0
def run(dry_run=False,
        print_only=False,
        enable_deletion=False,
        thread_pool_size=10,
        defer=None):
    settings = queries.get_app_interface_settings()
    zones = queries.get_dns_zones()

    participating_account_names = [z['account']['name'] for z in zones]
    participating_accounts = [
        a for a in queries.get_aws_accounts()
        if a['name'] in participating_account_names
    ]

    ts = Terrascript(QONTRACT_INTEGRATION,
                     "",
                     thread_pool_size,
                     participating_accounts,
                     settings=settings)

    desired_state = build_desired_state(zones)

    error = ts.populate_route53(desired_state)
    if error:
        sys.exit(ExitCodes.ERROR)
    working_dirs = ts.dump(print_only=print_only)

    if print_only:
        sys.exit(ExitCodes.SUCCESS)

    tf = Terraform(QONTRACT_INTEGRATION, QONTRACT_INTEGRATION_VERSION, "",
                   working_dirs, thread_pool_size)

    if tf is None:
        sys.exit(ExitCodes.ERROR)

    defer(lambda: tf.cleanup())

    _, err = tf.plan(enable_deletion)
    if err:
        sys.exit(ExitCodes.ERROR)

    if dry_run:
        return

    err = tf.apply()
    if err:
        sys.exit(ExitCodes.ERROR)
コード例 #2
0
def aws_route53_zones(ctx):
    zones = queries.get_dns_zones()

    results = []
    for zone in zones:
        zone_name = zone['name']
        zone_records = zone['records']
        zone_nameservers = dnsutils.get_nameservers(zone_name)
        item = {
            'domain': zone_name,
            'records': len(zone_records),
            'nameservers': zone_nameservers
        }
        results.append(item)

    columns = ['domain', 'records', 'nameservers']
    print_output(ctx.obj['output'], results, columns)
コード例 #3
0
def run(dry_run=False, thread_pool_size=10):
    settings = queries.get_app_interface_settings()
    zones = queries.get_dns_zones()

    desired_state, err = build_desired_state(zones)
    if err:
        sys.exit(ExitCodes.ERROR)

    participating_accounts = [z['account'] for z in zones]
    awsapi = AWSApi(thread_pool_size, participating_accounts, settings)
    current_state, err = build_current_state(awsapi)
    if err:
        sys.exit(ExitCodes.ERROR)

    actions, err = reconcile_state(current_state, desired_state)
    if err:
        sys.exit(ExitCodes.ERROR)

    for action in actions:
        err = action[0](dry_run, awsapi, *action[1:])
        if err:
            sys.exit(ExitCodes.ERROR)
コード例 #4
0
def run(
    dry_run=False,
    print_to_file=None,
    enable_deletion=True,
    thread_pool_size=10,
    defer=None,
):
    settings = queries.get_app_interface_settings()
    zones = queries.get_dns_zones()

    all_accounts = queries.get_aws_accounts()
    participating_account_names = [z["account"]["name"] for z in zones]
    participating_accounts = [
        a for a in all_accounts if a["name"] in participating_account_names
    ]

    ts = Terrascript(
        QONTRACT_INTEGRATION,
        "",
        thread_pool_size,
        participating_accounts,
        settings=settings,
    )

    desired_state = build_desired_state(zones, all_accounts, settings)

    ts.populate_route53(desired_state)
    working_dirs = ts.dump(print_to_file=print_to_file)
    aws_api = AWSApi(1,
                     participating_accounts,
                     settings=settings,
                     init_users=False)

    if print_to_file:
        sys.exit(ExitCodes.SUCCESS)

    tf = Terraform(
        QONTRACT_INTEGRATION,
        QONTRACT_INTEGRATION_VERSION,
        "",
        participating_accounts,
        working_dirs,
        thread_pool_size,
        aws_api,
    )

    if tf is None:
        sys.exit(ExitCodes.ERROR)

    defer(tf.cleanup)

    _, err = tf.plan(enable_deletion)
    if err:
        sys.exit(ExitCodes.ERROR)

    if dry_run:
        return

    err = tf.apply()
    if err:
        sys.exit(ExitCodes.ERROR)