示例#1
0
def main():
    parser = ArgumentParser(description=__doc__.split('\n')[1])

    parser.add_argument('--config-file', required=True,
                        help='The Manager configuration file to use')
    parser.add_argument('--doit', action='store_true', default=False,
                        help='Whether to take action or just show what would '
                        'change')
    parser.add_argument('--force', action='store_true', default=False,
                        help='Acknowledge that significant changes are being '
                        'made and do them')

    parser.add_argument('zone', nargs='*', default=[],
                        help='Limit sync to the specified zone(s)')

    # --sources isn't an option here b/c filtering sources out would be super
    # dangerous since you could eaily end up with an empty zone and delete
    # everything, or even just part of things when there are multiple sources

    parser.add_argument('--target', default=[], action='append',
                        help='Limit sync to the specified target(s)')

    args = parser.parse_args()

    manager = Manager(args.config_file)
    manager.sync(eligible_zones=args.zone, eligible_targets=args.target,
                 dry_run=not args.doit, force=args.force)
示例#2
0
def main():
    """check-zone based on octodns config file and dns zone
    Will query all 4 DNS servers configured for the zone in GCP.
    """
    parser = ArgumentParser(description=__doc__.split('\n')[1])

    parser.add_argument('--config-file', required=True,
                        help='The OctoDNS configuration file to use')
    parser.add_argument('--zone', action='append', required=True, help='zone to check')

    args = parser.parse_args()

    manager = Manager(args.config_file)

    for zone_name in args.zone:
        print('Checking records for {}'.format(zone_name))
        zone = Zone(zone_name, manager.configured_sub_zones(zone_name))

        # Read our YAML configuration
        yaml_config = manager.providers['config']

        # Build a GCP provider in our project to read the nameservers from it
        gcp = manager.providers['gcp']
        project = gcp.gcloud_client.project
        
        # Retrieve the DNS Servers directly from the GCP configuration
        dns_servers = gcp.gcloud_zones[zone_name].name_servers

        # k8s.io resolvers for testing without access to gcp
        #dns_servers = ["NS-CLOUD-D1.GOOGLEDOMAINS.COM", "NS-CLOUD-D2.GOOGLEDOMAINS.COM", "NS-CLOUD-D3.GOOGLEDOMAINS.COM", "NS-CLOUD-D4.GOOGLEDOMAINS.COM"]
        print('Using GCP project {}'.format(project))
        print('name,type,ttl,{},consistent'.format(','.join(dns_servers)))
        
        # Populate the zone with those records defined in our YAML config
        yaml_config.populate(zone)

        # This would populate the zone with records already defined in Google Cloud DNS
        # gcp.populate(zone)

        # Configure Resolvers (one per DNS server)
        resolvers = configure_resolvers(dns_servers)

        # Populate the queries to make based on zone record configuration
        queries = {}
        for record in sorted(zone.records):
            queries[record] = [r.query(record.fqdn, record._type)
                               for r in resolvers]
        # No dns_error unless we find one
        dns_error = False

        dns_error = verify_dns(queries)

        if dns_error:
            sys.exit(1)

    sys.exit(0)
示例#3
0
def main():
    parser = ArgumentParser(description=__doc__.split('\n')[1])

    parser.add_argument('--config-file',
                        default='./config/production.yaml',
                        help='The Manager configuration file to use')

    args = parser.parse_args(WARN)

    manager = Manager(args.config_file)
    manager.validate_configs()
示例#4
0
def main():
    parser = ArgumentParser(description=__doc__.split('\n')[1])

    parser.add_argument('--config-file',
                        required=True,
                        help='The Manager configuration file to use')

    args = parser.parse_args(WARN)

    manager = Manager(args.config_file)
    manager.validate_configs()
示例#5
0
def main():
    """check-zone based on octodns config file and dns zone
    Will query all 4 DNS servers configured for the zone in GCP.
    """
    parser = ArgumentParser(description=__doc__.split('\n')[1])

    parser.add_argument('--config-file',
                        required=True,
                        help='The OctoDNS configuration file to use')
    parser.add_argument('--zone',
                        action='append',
                        required=True,
                        help='zone to check')

    args = parser.parse_args()

    manager = Manager(args.config_file)

    for zone_name in args.zone:
        print('Checking records for {}'.format(zone_name))
        zone = Zone(zone_name, manager.configured_sub_zones(zone_name))
        gcp = manager.providers['gcp']
        project = gcp.gcloud_client.project
        gcp.populate(zone)

        # Retrieve the DNS Servers directly from the GCP configuration
        dns_servers = gcp.gcloud_zones[zone_name].name_servers
        print('Using GCP project {}'.format(project))
        print('name,type,ttl,{},consistent'.format(','.join(dns_servers)))

        # Configure Resolvers (one per DNS server)
        resolvers = configure_resolvers(dns_servers)

        # Populate the queries to make based on zone record configuration
        queries = {}
        for record in sorted(zone.records):
            queries[record] = [
                r.query(record.fqdn, record._type) for r in resolvers
            ]
        # No dns_error unless we find one
        dns_error = False

        dns_error = verify_dns(queries)

        if dns_error:
            sys.exit(1)

    sys.exit(0)
示例#6
0
def main():
    parser = ArgumentParser(description=__doc__.split('\n')[1])

    parser.add_argument('--config-file',
                        required=True,
                        help='The Manager configuration file to use')
    parser.add_argument('--sort',
                        action='store_true',
                        default=False,
                        help='Sort the zone before sending to validation')

    args = parser.parse_args(WARN)

    manager = Manager(args.config_file)

    manager.validate_configs(args.sort)
示例#7
0
def main():
    parser = ArgumentParser(description=__doc__.split('\n')[1])

    parser.add_argument(
        '--config-file',
        required=True,
        help='The Manager configuration file to use',
    )
    parser.add_argument(
        '--a',
        nargs='+',
        required=True,
        help='First source(s) to pull data from',
    )
    parser.add_argument(
        '--b',
        nargs='+',
        required=True,
        help='Second source(s) to pull data from',
    )
    parser.add_argument('--zone',
                        default=None,
                        required=True,
                        help='Zone to compare')
    parser.add_argument(
        '--ignore-prefix',
        default=None,
        required=False,
        help='Record prefix to ignore from list of changes',
    )
    args = parser.parse_args()

    manager = Manager(args.config_file)
    changes = manager.compare(args.a, args.b, args.zone)

    # Filter changes list based on ignore-prefix argument if present
    if args.ignore_prefix:
        pattern = args.ignore_prefix
        changes = [c for c in changes if not c.record.fqdn.startswith(pattern)]

    pprint(changes)

    # Exit with non-zero exit code if changes exist
    if len(changes):
        sys.exit(1)
示例#8
0
def main():
    parser = ArgumentParser(description=__doc__.split('\n')[1])

    parser.add_argument('--config-file', required=True,
                        help='The Manager configuration file to use')
    parser.add_argument('--output-dir', required=True,
                        help='The directory into which the results will be '
                        'written (Note: will overwrite existing files)')
    parser.add_argument('--lenient', action='store_true', default=False,
                        help='Ignore record validations and do a best effort '
                        'dump')
    parser.add_argument('zone', help='Zone to dump')
    parser.add_argument('source', nargs='+',
                        help='Source(s) to pull data from')

    args = parser.parse_args()

    manager = Manager(args.config_file)
    manager.dump(args.zone, args.output_dir, args.lenient, *args.source)
示例#9
0
def main():
    parser = ArgumentParser(description=__doc__.split('\n')[1])

    parser.add_argument('--config-file', required=True,
                        help='The Manager configuration file to use')
    parser.add_argument('--a', nargs='+', required=True,
                        help='First source(s) to pull data from')
    parser.add_argument('--b', nargs='+', required=True,
                        help='Second source(s) to pull data from')
    parser.add_argument('--zone', default=None, required=True,
                        help='Zone to compare')

    args = parser.parse_args()

    manager = Manager(args.config_file)
    changes = manager.compare(args.a, args.b, args.zone)
    pprint(changes)
示例#10
0
def main():
    parser = ArgumentParser(description=__doc__.split('\n')[1])

    parser.add_argument('--config-file', required=True,
                        help='The Manager configuration file to use')
    parser.add_argument('--zone', required=True, help='Zone to dump')
    parser.add_argument('--source', required=True, default=[], action='append',
                        help='Source(s) to pull data from')
    parser.add_argument('--num-workers', default=4,
                        help='Number of background workers')
    parser.add_argument('--timeout', default=1,
                        help='Number seconds to wait for an answer')
    parser.add_argument('server', nargs='+', help='Servers to query')

    args = parser.parse_args()

    manager = Manager(args.config_file)

    log = getLogger('report')

    try:
        sources = [manager.providers[source] for source in args.source]
    except KeyError as e:
        raise Exception('Unknown source: {}'.format(e.args[0]))

    zone = Zone(args.zone, manager.configured_sub_zones(args.zone))
    for source in sources:
        source.populate(zone)

    print('name,type,ttl,{},consistent'.format(','.join(args.server)))
    resolvers = []
    ip_addr_re = re.compile(r'^[\d\.]+$')
    for server in args.server:
        resolver = AsyncResolver(configure=False,
                                 num_workers=int(args.num_workers))
        if not ip_addr_re.match(server):
            server = text_type(query(server, 'A')[0])
        log.info('server=%s', server)
        resolver.nameservers = [server]
        resolver.lifetime = int(args.timeout)
        resolvers.append(resolver)

    queries = {}
    for record in sorted(zone.records):
        queries[record] = [r.query(record.fqdn, record._type)
                           for r in resolvers]

    for record, futures in sorted(queries.items(), key=lambda d: d[0]):
        stdout.write(record.fqdn)
        stdout.write(',')
        stdout.write(record._type)
        stdout.write(',')
        stdout.write(text_type(record.ttl))
        compare = {}
        for future in futures:
            stdout.write(',')
            try:
                answers = [text_type(r) for r in future.result()]
            except (NoAnswer, NoNameservers):
                answers = ['*no answer*']
            except NXDOMAIN:
                answers = ['*does not exist*']
            except Timeout:
                answers = ['*timeout*']
            stdout.write(' '.join(answers))
            # sorting to ignore order
            answers = '*:*'.join(sorted(answers)).lower()
            compare[answers] = True
        stdout.write(',True\n' if len(compare) == 1 else ',False\n')
示例#11
0
文件: sync.py 项目: yzguy/octodns
def main():
    parser = ArgumentParser(description=__doc__.split('\n')[1])

    parser.add_argument('--config-file', required=True,
                        help='The Manager configuration file to use')
    parser.add_argument('--doit', action='store_true', default=False,
                        help='Whether to take action or just show what would '
                        'change')
    parser.add_argument('--force', action='store_true', default=False,
                        help='Acknowledge that significant changes are being '
                        'made and do them')

    parser.add_argument('zone', nargs='*', default=[],
                        help='Limit sync to the specified zone(s)')

    parser.add_argument('--source', default=[], action='append',
                        help='Limit sync to zones with the specified '
                        'source(s) (all sources will be synchronized for the '
                        'selected zones)')
    parser.add_argument('--target', default=[], action='append',
                        help='Limit sync to the specified target(s)')

    args = parser.parse_args()

    manager = Manager(args.config_file)
    manager.sync(eligible_zones=args.zone, eligible_sources=args.source,
                 eligible_targets=args.target, dry_run=not args.doit,
                 force=args.force)
示例#12
0
def main():
    parser = ArgumentParser(description=__doc__.split('\n')[1])

    parser.add_argument(
        '--config-file',
        required=True,
        help='The Manager configuration file to use',
    )
    parser.add_argument(
        '--output-dir',
        required=True,
        help='The directory into which the results will be '
        'written (Note: will overwrite existing files)',
    )
    parser.add_argument(
        '--output-provider',
        required=False,
        help='The configured provider to use when dumping '
        'records. Must support copy() and directory',
    )
    parser.add_argument(
        '--lenient',
        action='store_true',
        default=False,
        help='Ignore record validations and do a best effort '
        'dump',
    )
    parser.add_argument(
        '--split',
        action='store_true',
        default=False,
        help='Split the dumped zone into a YAML file per '
        'record',
    )
    parser.add_argument('zone', help='Zone to dump')
    parser.add_argument('source',
                        nargs='+',
                        help='Source(s) to pull data from')

    args = parser.parse_args()

    manager = Manager(args.config_file)
    manager.dump(
        zone=args.zone,
        output_dir=args.output_dir,
        output_provider=args.output_provider,
        lenient=args.lenient,
        split=args.split,
        sources=args.source,
    )