Example #1
0
def cli(env):
    """List all zones."""

    manager = SoftLayer.DNSManager(env.client)
    object_mask = "mask[id,name,serial,updateDate,resourceRecordCount]"
    zones = manager.list_zones(mask=object_mask)
    table = formatting.Table(['id', 'zone', 'serial', 'updated', 'records'])
    table.align = 'l'
    for zone in zones:
        zone_serial = str(zone.get('serial'))
        zone_date = zone.get('updateDate', None)
        if zone_date is None:
            # The serial is just YYYYMMDD##, and since there is no createDate, just format it like it was one.
            zone_date = "{}-{}-{}T00:00:00-06:00".format(zone_serial[0:4], zone_serial[4:6], zone_serial[6:8])
        table.add_row([
            zone['id'],
            zone['name'],
            zone_serial,
            clean_time(zone_date),
            zone.get('resourceRecordCount', 0)
        ])

    env.fout(table)
Example #2
0
    def on_put(self, req, resp, tenant_id, domain, entry):
        client = req.env['sl_client']
        mgr = SoftLayer.DNSManager(client)

        body = json.loads(req.stream.read().decode())
        ip = utils.lookup(body, 'dns_entry', 'ip')
        record_type = utils.lookup(body, 'dns_entry', 'type')
        if not record_type:
            record_type = 'A'

        domain = parse.unquote_plus(domain)
        zone_id = mgr._get_zone_id_from_name(domain)[0]
        mgr.create_record(zone_id=zone_id,
                          record=entry,
                          record_type=record_type,
                          data=ip)
        new_record = mgr.get_records(zone_id, host=entry)[0]
        result = get_dns_entry_dict(domain,
                                    entry,
                                    ip,
                                    record_type,
                                    entry_id=new_record['id'])

        resp.body = {'dns_entry': result}
Example #3
0
def cli(env, record, record_type, data, zone, ttl, priority, protocol, port,
        service, weight):
    """Add resource record.

    Each resource record contains a RECORD and DATA property, defining a resource's name and it's target data.
    Domains contain multiple types of resource records so it can take one of the following values: A, AAAA, CNAME,
    MX, SPF, SRV, and PTR.

    About reverse records (PTR), the RECORD value must to be the public Ip Address of device you would like to manage
    reverse DNS.

        slcli dns record-add 10.10.8.21 PTR myhost.com --ttl=900

    Examples:

        slcli dns record-add myhost.com A 192.168.1.10 --zone=foobar.com --ttl=900

        slcli dns record-add myhost.com AAAA 2001:DB8::1 --zone=foobar.com

        slcli dns record-add 192.168.1.2 MX 192.168.1.10 --zone=foobar.com --priority=11 --ttl=1800

        slcli dns record-add myhost.com TXT "txt-verification=rXOxyZounZs87oacJSKvbUSIQ" --zone=2223334

        slcli dns record-add myhost.com SPF "v=spf1 include:_spf.google.com ~all" --zone=2223334

        slcli dns record-add myhost.com SRV 192.168.1.10 --zone=2223334 --service=foobar --port=80 --protocol=TCP

    """

    manager = SoftLayer.DNSManager(env.client)
    record_type = record_type.upper()

    if zone and record_type != 'PTR':
        zone_id = helpers.resolve_id(manager.resolve_ids, zone, name='zone')

        if record_type == 'MX':
            manager.create_record_mx(zone_id,
                                     record,
                                     data,
                                     ttl=ttl,
                                     priority=priority)
        elif record_type == 'SRV':
            manager.create_record_srv(zone_id,
                                      record,
                                      data,
                                      protocol,
                                      port,
                                      service,
                                      ttl=ttl,
                                      priority=priority,
                                      weight=weight)
        else:
            manager.create_record(zone_id, record, record_type, data, ttl=ttl)

    elif record_type == 'PTR':
        manager.create_record_ptr(record, data, ttl=ttl)
    else:
        raise exceptions.CLIAbort(
            "%s isn't a valid record type or zone is missing" % record_type)

    click.secho("%s record added successfully" % record_type, fg='green')
Example #4
0
def cli(env, zone):
    """Create a zone."""

    manager = SoftLayer.DNSManager(env.client)
    manager.create_zone(zone)
Example #5
0
 def __init__(self):
     self.cfg = params()
     self.client = SoftLayer.create_client_from_env(
         username=self.cfg['cis_username'], api_key=self.cfg['cis_apikey'])
     self.dns = SoftLayer.DNSManager(self.client)
Example #6
0
def cli(env, identifier, a_record, aaaa_record, ptr, ttl):
    """Sync DNS records."""

    items = [
        'id', 'globalIdentifier', 'fullyQualifiedDomainName', 'hostname',
        'domain', 'primaryBackendIpAddress', 'primaryIpAddress',
        '''primaryNetworkComponent[
                id, primaryIpAddress,
                primaryVersion6IpAddressRecord[ipAddress]
             ]'''
    ]
    mask = "mask[%s]" % ','.join(items)
    dns = SoftLayer.DNSManager(env.client)
    vsi = SoftLayer.VSManager(env.client)

    vs_id = helpers.resolve_id(vsi.resolve_ids, identifier, 'VS')
    instance = vsi.get_instance(vs_id, mask=mask)
    zone_id = helpers.resolve_id(dns.resolve_ids,
                                 instance['domain'],
                                 name='zone')

    def sync_a_record():
        """Sync A record."""
        records = dns.get_records(zone_id,
                                  host=instance['hostname'],
                                  record_type='a')
        if not records:
            # don't have a record, lets add one to the base zone
            dns.create_record(zone['id'],
                              instance['hostname'],
                              'a',
                              instance['primaryIpAddress'],
                              ttl=ttl)
        else:
            if len(records) != 1:
                raise exceptions.CLIAbort("Aborting A record sync, found "
                                          "%d A record exists!" % len(records))
            rec = records[0]
            rec['data'] = instance['primaryIpAddress']
            rec['ttl'] = ttl
            dns.edit_record(rec)

    def sync_aaaa_record():
        """Sync AAAA record."""
        records = dns.get_records(zone_id,
                                  host=instance['hostname'],
                                  record_type='aaaa')
        try:
            # done this way to stay within 80 character lines
            component = instance['primaryNetworkComponent']
            record = component['primaryVersion6IpAddressRecord']
            ip_address = record['ipAddress']
        except KeyError:
            raise exceptions.CLIAbort("%s does not have an ipv6 address" %
                                      instance['fullyQualifiedDomainName'])

        if not records:
            # don't have a record, lets add one to the base zone
            dns.create_record(zone['id'],
                              instance['hostname'],
                              'aaaa',
                              ip_address,
                              ttl=ttl)
        else:
            if len(records) != 1:
                raise exceptions.CLIAbort("Aborting A record sync, found "
                                          "%d A record exists!" % len(records))
            rec = records[0]
            rec['data'] = ip_address
            rec['ttl'] = ttl
            dns.edit_record(rec)

    def sync_ptr_record():
        """Sync PTR record."""
        host_rec = instance['primaryIpAddress'].split('.')[-1]
        ptr_domains = (env.client['Virtual_Guest'].getReverseDomainRecords(
            id=instance['id'])[0])
        edit_ptr = None
        for ptr in ptr_domains['resourceRecords']:
            if ptr['host'] == host_rec:
                ptr['ttl'] = ttl
                edit_ptr = ptr
                break

        if edit_ptr:
            edit_ptr['data'] = instance['fullyQualifiedDomainName']
            dns.edit_record(edit_ptr)
        else:
            dns.create_record(ptr_domains['id'],
                              host_rec,
                              'ptr',
                              instance['fullyQualifiedDomainName'],
                              ttl=ttl)

    if not instance['primaryIpAddress']:
        raise exceptions.CLIAbort('No primary IP address associated with '
                                  'this VS')

    zone = dns.get_zone(zone_id)

    go_for_it = env.skip_confirmations or formatting.confirm(
        "Attempt to update DNS records for %s" %
        instance['fullyQualifiedDomainName'])

    if not go_for_it:
        raise exceptions.CLIAbort("Aborting DNS sync")

    both = False
    if not ptr and not a_record and not aaaa_record:
        both = True

    if both or a_record:
        sync_a_record()

    if both or ptr:
        sync_ptr_record()

    if aaaa_record:
        sync_aaaa_record()
def _get_dns_records(zone_name):
    zone_id = _get_dns_zone_id(zone_name)
    mgr = SoftLayer.DNSManager(_client)
    return mgr.get_records(zone_id)
Example #8
0
 def set_up(self):
     self.dns_client = SoftLayer.DNSManager(self.client)
 def set_up(self):
     self.client = testing.FixtureClient()
     self.dns_client = SoftLayer.DNSManager(self.client)
Example #10
0
def cli(env, zone):
    """Print zone in BIND format."""

    manager = SoftLayer.DNSManager(env.client)
    zone_id = helpers.resolve_id(manager.resolve_ids, zone, name='zone')
    env.fout(manager.dump_zone(zone_id))
Example #11
0
    def dns_sync(self, args):
        """ Sync DNS records to match the FQDN of the virtual server """
        dns = SoftLayer.DNSManager(self.client)
        vsi = SoftLayer.VSManager(self.client)

        vs_id = helpers.resolve_id(vsi.resolve_ids,
                                   args.get('<identifier>'),
                                   'VS')
        instance = vsi.get_instance(vs_id)
        zone_id = helpers.resolve_id(dns.resolve_ids,
                                     instance['domain'],
                                     name='zone')

        def sync_a_record():
            """ Sync A record """
            records = dns.get_records(
                zone_id,
                host=instance['hostname'],
            )

            if not records:
                # don't have a record, lets add one to the base zone
                dns.create_record(
                    zone['id'],
                    instance['hostname'],
                    'a',
                    instance['primaryIpAddress'],
                    ttl=args['--ttl'])
            else:
                recs = [x for x in records if x['type'].lower() == 'a']
                if len(recs) != 1:
                    raise exceptions.CLIAbort("Aborting A record sync, found "
                                              "%d A record exists!"
                                              % len(recs))
                rec = recs[0]
                rec['data'] = instance['primaryIpAddress']
                rec['ttl'] = args['--ttl']
                dns.edit_record(rec)

        def sync_ptr_record():
            """ Sync PTR record """
            host_rec = instance['primaryIpAddress'].split('.')[-1]
            ptr_domains = (self.client['Virtual_Guest']
                           .getReverseDomainRecords(id=instance['id'])[0])
            edit_ptr = None
            for ptr in ptr_domains['resourceRecords']:
                if ptr['host'] == host_rec:
                    ptr['ttl'] = args['--ttl']
                    edit_ptr = ptr
                    break

            if edit_ptr:
                edit_ptr['data'] = instance['fullyQualifiedDomainName']
                dns.edit_record(edit_ptr)
            else:
                dns.create_record(
                    ptr_domains['id'],
                    host_rec,
                    'ptr',
                    instance['fullyQualifiedDomainName'],
                    ttl=args['--ttl'])

        if not instance['primaryIpAddress']:
            raise exceptions.CLIAbort('No primary IP address associated with '
                                      'this VS')

        zone = dns.get_zone(zone_id)

        go_for_it = args['--really'] or formatting.confirm(
            "Attempt to update DNS records for %s"
            % instance['fullyQualifiedDomainName'])

        if not go_for_it:
            raise exceptions.CLIAbort("Aborting DNS sync")

        both = False
        if not args['--ptr'] and not args['-a']:
            both = True

        if both or args['-a']:
            sync_a_record()

        if both or args['--ptr']:
            sync_ptr_record()
 def __init__(self):
     client = SoftLayer.create_client_from_env()
     self.dns = SoftLayer.DNSManager(client)
Example #13
0
 def execute(self, args):
     manager = SoftLayer.DNSManager(self.client)
     manager.create_zone(args['<zone>'])
Example #14
0
 def execute(self, args):
     manager = SoftLayer.DNSManager(self.client)
     zone_id = helpers.resolve_id(manager.resolve_ids,
                                  args['<zone>'],
                                  name='zone')
     return manager.dump_zone(zone_id)
Example #15
0
def cli(env, zone, record, type, data, ttl):
    """Add resource record."""

    manager = SoftLayer.DNSManager(env.client)
    zone_id = helpers.resolve_id(manager.resolve_ids, zone, name='zone')
    manager.create_record(zone_id, record, type, data, ttl=ttl)