Esempio n. 1
0
class TestObject(objects.DesignateObject):
    fields = {
        'id': fields.AnyField(nullable=True),
        'name': fields.AnyField(nullable=True),
        'nested': fields.ObjectFields('TestObject', nullable=True),
        'nested_list': fields.ObjectFields('TestObjectList', nullable=True),
    }
Esempio n. 2
0
class PoolTarget(base.DictObjectMixin, base.PersistentObjectMixin,
                 base.DesignateObject):
    fields = {
        'pool_id': fields.UUIDFields(nullable=True),
        'type': fields.AnyField(nullable=True),
        'tsigkey_id': fields.UUIDFields(nullable=True),
        'description': fields.StringFields(maxLength=160, nullable=True),
        'masters': fields.ObjectFields('PoolTargetMasterList'),
        'options': fields.ObjectFields('PoolTargetOptionList'),
        'backend': fields.AnyField(nullable=True),
    }

    STRING_KEYS = ['id', 'type', 'pool_id']
Esempio n. 3
0
class TestValidatableObject(objects.DesignateObject):
    fields = {
        'id': fields.UUIDFields(),
        'nested': fields.ObjectFields('TestValidatableObject', nullable=True),
    }
Esempio n. 4
0
class Pool(base.DictObjectMixin, base.PersistentObjectMixin,
           base.DesignateObject):
    fields = {
        'name': fields.StringFields(maxLength=50),
        'description': fields.StringFields(nullable=True, maxLength=160),
        'tenant_id': fields.StringFields(maxLength=36, nullable=True),
        'provisioner': fields.StringFields(nullable=True, maxLength=160),
        'attributes': fields.ObjectFields('PoolAttributeList', nullable=True),
        'ns_records': fields.ObjectFields('PoolNsRecordList', nullable=True),
        'nameservers': fields.ObjectFields('PoolNameserverList',
                                           nullable=True),
        'targets': fields.ObjectFields('PoolTargetList', nullable=True),
        'also_notifies': fields.ObjectFields('PoolAlsoNotifyList',
                                             nullable=True),
    }

    @classmethod
    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)

    STRING_KEYS = [
        'id', 'name'
    ]