Пример #1
0
    def test_split_host_port(self):
        host_port = "abc:abc"
        host, port = utils.split_host_port(host_port)
        self.assertEqual((host, port), ("abc:abc", 53))

        host_port = "abc:25"
        host, port = utils.split_host_port(host_port)
        self.assertEqual((host, port), ("abc", 25))
Пример #2
0
    def test_split_host_port(self):
        host_port = "abc:abc"
        host, port = utils.split_host_port(host_port)
        self.assertEqual((host, port), ("abc:abc", 53))

        host_port = "abc:25"
        host, port = utils.split_host_port(host_port)
        self.assertEqual((host, port), ("abc", 25))
Пример #3
0
 def _parse_server(self, cfg_server):
     try:
         (host, port) = utils.split_host_port(cfg_server)
         port = int(port)
     except ValueError:
         host = str(cfg_server)
         port = DEFAULT_PORT
     return {'host': host, 'port': port}
Пример #4
0
 def _parse_server(self, cfg_server):
     try:
         (host, port) = utils.split_host_port(cfg_server)
         port = int(port)
     except ValueError:
         host = str(cfg_server)
         port = DEFAULT_PORT
     return {'host': host, 'port': port}
Пример #5
0
 def get_master_by_ip(self, host):
     """
     Utility to get the master by it's ip for this domain.
     """
     for srv in self.masters:
         srv_host, _ = utils.split_host_port(srv.to_data())
         if host == srv_host:
             return srv
     return False
Пример #6
0
 def get_master_by_ip(self, host):
     """
     Utility to get the master by it's ip for this domain.
     """
     for srv in self.masters:
         srv_host, _ = utils.split_host_port(srv)
         if host == srv_host:
             return srv
     return False
Пример #7
0
    def __init__(self):
        self.masters = []
        for server in CONF['service:agent'].masters:
            raw_server = utils.split_host_port(server)
            master = {'host': raw_server[0], 'port': int(raw_server[1])}
            self.masters.append(master)

        LOG.info("Agent masters: %(masters)s", {'masters': self.masters})

        self.allow_notify = CONF['service:agent'].allow_notify
        self.transfer_source = CONF['service:agent'].transfer_source
        backend_driver = cfg.CONF['service:agent'].backend_driver
        self.backend = agent_backend.get_backend(backend_driver, self)
Пример #8
0
    def __init__(self):
        self.masters = []
        for server in CONF['service:agent'].masters:
            raw_server = utils.split_host_port(server)
            master = {'host': raw_server[0], 'port': int(raw_server[1])}
            self.masters.append(master)

        LOG.info("Agent masters: %(masters)s", {'masters': self.masters})

        self.allow_notify = CONF['service:agent'].allow_notify
        self.transfer_source = CONF['service:agent'].transfer_source
        backend_driver = cfg.CONF['service:agent'].backend_driver
        self.backend = agent_backend.get_backend(backend_driver, self)
def upgrade(migrate_engine):
    meta.bind = migrate_engine
    zone_attibutes_table = Table('zone_attributes', meta, autoload=True)

    connection = migrate_engine.connect()

    transaction = connection.begin()
    try:

        zone_masters_table.create()

        masters = select([
            zone_attibutes_table.c.id, zone_attibutes_table.c.version,
            zone_attibutes_table.c.created_at,
            zone_attibutes_table.c.updated_at, zone_attibutes_table.c.value,
            zone_attibutes_table.c.zone_id
        ]).where(zone_attibutes_table.c.key == 'master').execute().fetchall()

        masters_input = []

        for master in masters:
            host, port = utils.split_host_port(
                master[zone_attibutes_table.c.value])
            masters_input.append({
                'id':
                master[zone_attibutes_table.c.id],
                'version':
                master[zone_attibutes_table.c.version],
                'created_at':
                master[zone_attibutes_table.c.created_at],
                'updated_at':
                master[zone_attibutes_table.c.updated_at],
                'zone_id':
                master[zone_attibutes_table.c.zone_id],
                'host':
                host,
                'port':
                port
            })

        zone_attibutes_table.insert(masters_input)

        zone_attibutes_table.delete().where(
            zone_attibutes_table.c.key == 'master')

        zone_attibutes_table.c.key.alter(type=String(50))
        transaction.commit()
    except Exception:
        transaction.rollback()
        raise
Пример #10
0
def expand_servers(servers):
    """
    Expands list of server:port into a list of dicts.

    Example: [{"host": ..., "port": 53}]
    """
    data = []
    for srv in servers:
        if isinstance(srv, basestring):
            host, port = utils.split_host_port(srv, 53)
        srv = {"ip": host, "port": port}
        data.append(srv)

    return data
Пример #11
0
def expand_servers(servers):
    """
    Expands list of server:port into a list of dicts.

    Example: [{"host": ..., "port": 53}]
    """
    data = []
    for srv in servers:
        if isinstance(srv, basestring):
            host, port = utils.split_host_port(srv, 53)
        srv = {"ip": host, "port": port}
        data.append(srv)

    return data
def upgrade(migrate_engine):
    meta.bind = migrate_engine
    zone_attibutes_table = Table('zone_attributes', meta, autoload=True)

    connection = migrate_engine.connect()

    transaction = connection.begin()
    try:

        zone_masters_table.create()

        masters = select(
            [
                zone_attibutes_table.c.id,
                zone_attibutes_table.c.version,
                zone_attibutes_table.c.created_at,
                zone_attibutes_table.c.updated_at,
                zone_attibutes_table.c.value,
                zone_attibutes_table.c.zone_id
            ]
        ).where(
            zone_attibutes_table.c.key == 'master'
        ).execute().fetchall()

        masters_input = []

        for master in masters:
            host, port = utils.split_host_port(
                master[zone_attibutes_table.c.value])
            masters_input.append({
                'id': master[zone_attibutes_table.c.id],
                'version': master[zone_attibutes_table.c.version],
                'created_at': master[zone_attibutes_table.c.created_at],
                'updated_at': master[zone_attibutes_table.c.updated_at],
                'zone_id': master[zone_attibutes_table.c.zone_id],
                'host': host,
                'port': port
            })

        zone_attibutes_table.insert(masters_input)

        zone_attibutes_table.delete().where(
            zone_attibutes_table.c.key == 'master')

        zone_attibutes_table.c.key.alter(type=String(50))
        transaction.commit()
    except Exception:
        transaction.rollback()
        raise
Пример #13
0
 def _parse_master(master):
     try:
         (ip_address, port) = utils.split_host_port(master)
     except ValueError:
         ip_address = str(master)
         port = DEFAULT_MASTER_PORT
     try:
         port = int(port)
     except ValueError:
         raise exceptions.ConfigurationError(
             'Invalid port "%s" in masters option.' % port)
     if port < 0 or port > 65535:
         raise exceptions.ConfigurationError(
             'Port "%s" is not between 0 and 65535 in masters option.' %
             port)
     try:
         socket.inet_pton(socket.AF_INET, ip_address)
     except socket.error:
         raise exceptions.ConfigurationError(
             'Invalid IP address "%s" in masters option.' % ip_address)
     return {'ip-address': ip_address, 'port': port}
Пример #14
0
    def __init__(self, *a, **kw):
        """Configure the backend"""
        super(DjbdnsBackend, self).__init__(*a, **kw)
        conf = cfg.CONF[CFG_GROUP_NAME]

        self._resolver = dns.resolver.Resolver(configure=False)
        self._resolver.timeout = SOA_QUERY_TIMEOUT
        self._resolver.lifetime = SOA_QUERY_TIMEOUT
        self._resolver.nameservers = [conf.query_destination]
        self._masters = [
            utils.split_host_port(ns)
            for ns in cfg.CONF['service:agent'].masters
        ]
        LOG.info("Resolvers: %r", self._resolver.nameservers)
        LOG.info("AXFR masters: %r", self._masters)
        if not self._masters:
            raise exceptions.Backend("Missing agent AXFR masters")

        self._tcpclient_cmd_name = conf.tcpclient_cmd_name
        self._axfr_get_cmd_name = conf.axfr_get_cmd_name

        # Directory where data.cdb lives, usually /var/lib/djbdns/root
        tinydns_root_dir = os.path.join(conf.tinydns_datadir, 'root')

        # Usually /var/lib/djbdns/root/data.cdb
        self._tinydns_cdb_filename = os.path.join(tinydns_root_dir, 'data.cdb')
        LOG.info("data.cdb path: %r", self._tinydns_cdb_filename)

        # Where the agent puts the zone datafiles,
        # usually /var/lib/djbdns/datafiles
        self._datafiles_dir = datafiles_dir = os.path.join(
            conf.tinydns_datadir, 'datafiles')
        self._datafiles_tmp_path_tpl = os.path.join(datafiles_dir, "%s.ztmp")
        self._datafiles_path_tpl = os.path.join(datafiles_dir, "%s.zonedata")
        self._datafiles_path_glob = self._datafiles_path_tpl % '*'

        self._check_dirs(tinydns_root_dir, datafiles_dir)
Пример #15
0
    def __init__(self, *a, **kw):
        """Configure the backend"""
        super(DjbdnsBackend, self).__init__(*a, **kw)

        self._resolver = dns.resolver.Resolver(configure=False)
        self._resolver.timeout = SOA_QUERY_TIMEOUT
        self._resolver.lifetime = SOA_QUERY_TIMEOUT
        self._resolver.nameservers = [cfg.CONF[CFG_GROUP].query_destination]
        self._masters = [utils.split_host_port(ns)
                         for ns in cfg.CONF['service:agent'].masters]
        LOG.info("Resolvers: %r", self._resolver.nameservers)
        LOG.info("AXFR masters: %r", self._masters)
        if not self._masters:
            raise exceptions.Backend("Missing agent AXFR masters")

        self._tcpclient_cmd_name = cfg.CONF[CFG_GROUP].tcpclient_cmd_name
        self._axfr_get_cmd_name = cfg.CONF[CFG_GROUP].axfr_get_cmd_name

        # Directory where data.cdb lives, usually /var/lib/djbdns/root
        tinydns_root_dir = os.path.join(cfg.CONF[CFG_GROUP].tinydns_datadir,
                                        'root')

        # Usually /var/lib/djbdns/root/data.cdb
        self._tinydns_cdb_filename = os.path.join(tinydns_root_dir, 'data.cdb')
        LOG.info("data.cdb path: %r", self._tinydns_cdb_filename)

        # Where the agent puts the zone datafiles,
        # usually /var/lib/djbdns/datafiles
        self._datafiles_dir = datafiles_dir = os.path.join(
            cfg.CONF[CFG_GROUP].tinydns_datadir,
            'datafiles')
        self._datafiles_tmp_path_tpl = os.path.join(datafiles_dir, "%s.ztmp")
        self._datafiles_path_tpl = os.path.join(datafiles_dir, "%s.zonedata")
        self._datafiles_path_glob = self._datafiles_path_tpl % '*'

        self._check_dirs(tinydns_root_dir, datafiles_dir)
Пример #16
0
 def test_split_host_port_with_invalid_port(self):
     host, port = utils.split_host_port('abc:abc')
     self.assertEqual(('abc:abc', 53), (host, port))
Пример #17
0
 def test_split_host_port(self):
     host, port = utils.split_host_port('abc:25')
     self.assertEqual(('abc', 25), (host, port))
Пример #18
0
    def from_config(cls, CONF, pool_id):
        pool_target_ids = CONF['pool:%s' % pool_id].targets
        pool_nameserver_ids = CONF['pool:%s' % pool_id].nameservers
        pool_also_notifies = CONF['pool:%s' % pool_id].also_notifies

        # Build Base Pool
        pool = {
            'id': pool_id,
            'description': 'Pool built from configuration on %s' % CONF.host,
            'targets': [],
            'nameservers': [],
            'also_notifies': [],
        }

        # Build Pool Also Notifies
        for pool_also_notify in pool_also_notifies:
            host, port = utils.split_host_port(pool_also_notify)
            pool['also_notifies'].append({
                'host': host,
                'port': port,
            })

        # Build Pool Targets
        for pool_target_id in pool_target_ids:
            pool_target_group = 'pool_target:%s' % pool_target_id

            pool_target = {
                'id': pool_target_id,
                'type': CONF[pool_target_group].type,
                'masters': [],
                'options': [],
            }

            # Build Pool Target Masters
            for pool_target_master in CONF[pool_target_group].masters:
                host, port = utils.split_host_port(pool_target_master)
                pool_target['masters'].append({
                    'host': host,
                    'port': port,
                })

            # Build Pool Target Options
            for k, v in CONF[pool_target_group].options.items():
                pool_target['options'].append({
                    'key': k,
                    'value': v,
                })

            pool['targets'].append(pool_target)

        # Build Pool Nameservers
        for pool_nameserver_id in pool_nameserver_ids:
            pool_nameserver_group = 'pool_nameserver:%s' % pool_nameserver_id

            pool_nameserver = {
                'id': pool_nameserver_id,
                'host': CONF[pool_nameserver_group].host,
                'port': CONF[pool_nameserver_group].port,
            }

            pool['nameservers'].append(pool_nameserver)

        return cls.from_dict(pool)
Пример #19
0
    def from_config(cls, CONF, pool_id):
        pool_target_ids = CONF['pool:%s' % pool_id].targets
        pool_nameserver_ids = CONF['pool:%s' % pool_id].nameservers
        pool_also_notifies = CONF['pool:%s' % pool_id].also_notifies

        # Build Base Pool
        pool = {
            'id': pool_id,
            'description': 'Pool built from configuration on %s' % CONF.host,
            'targets': [],
            'nameservers': [],
            'also_notifies': [],
        }

        # Build Pool Also Notifies
        for pool_also_notify in pool_also_notifies:
            host, port = utils.split_host_port(pool_also_notify)
            pool['also_notifies'].append({
                'host': host,
                'port': port,
            })

        # Build Pool Targets
        for pool_target_id in pool_target_ids:
            pool_target_group = 'pool_target:%s' % pool_target_id

            pool_target = {
                'id': pool_target_id,
                'type': CONF[pool_target_group].type,
                'masters': [],
                'options': [],
            }

            # Build Pool Target Masters
            for pool_target_master in CONF[pool_target_group].masters:
                host, port = utils.split_host_port(pool_target_master)
                pool_target['masters'].append({
                    'host': host,
                    'port': port,
                })

            # Build Pool Target Options
            for k, v in CONF[pool_target_group].options.items():
                pool_target['options'].append({
                    'key': k,
                    'value': v,
                })

            pool['targets'].append(pool_target)

        # Build Pool Nameservers
        for pool_nameserver_id in pool_nameserver_ids:
            pool_nameserver_group = 'pool_nameserver:%s' % pool_nameserver_id

            pool_nameserver = {
                'id': pool_nameserver_id,
                'host': CONF[pool_nameserver_group].host,
                'port': CONF[pool_nameserver_group].port,
            }

            pool['nameservers'].append(pool_nameserver)

        return cls.from_dict(pool)
Пример #20
0
 def from_data(cls, data):
     host, port = utils.split_host_port(data)
     dict_data = {"host": host, "port": port}
     return cls(**dict_data)
Пример #21
0
 def _parse_object(cls, value, object, *args, **kwargs):
     object.host, object.port = utils.split_host_port(value)
     return object
Пример #22
0
 def from_data(cls, data):
     host, port = utils.split_host_port(data)
     dict_data = {"host": host, "port": port}
     return cls(**dict_data)
Пример #23
0
 def from_data(cls, data):
     host, port = utils.split_host_port(data)
     return cls.from_dict({"host": host, "port": port})