Exemplo n.º 1
0
    def create_subnetpool(self, context, subnetpool):
        """Create a subnetpool"""

        sp = subnetpool['subnetpool']
        sp_reader = subnet_alloc.SubnetPoolReader(sp)
        tenant_id = self._get_tenant_id_for_create(context, sp)
        with context.session.begin(subtransactions=True):
            pool_args = {'tenant_id': tenant_id,
                         'id': sp_reader.id,
                         'name': sp_reader.name,
                         'ip_version': sp_reader.ip_version,
                         'default_prefixlen':
                         sp_reader.default_prefixlen,
                         'min_prefixlen': sp_reader.min_prefixlen,
                         'max_prefixlen': sp_reader.max_prefixlen,
                         'shared': sp_reader.shared,
                         'default_quota': sp_reader.default_quota}
            subnetpool = models_v2.SubnetPool(**pool_args)
            context.session.add(subnetpool)
            for prefix in sp_reader.prefixes:
                self._create_subnetpool_prefix(context,
                                               prefix,
                                               subnetpool.id)

        return self._make_subnetpool_dict(subnetpool)
Exemplo n.º 2
0
    def update_subnetpool(self, context, id, subnetpool):
        """Update a subnetpool"""
        new_sp = subnetpool['subnetpool']

        with context.session.begin(subtransactions=True):
            orig_sp = self._get_subnetpool(context, id)
            updated = self._updated_subnetpool_dict(orig_sp, new_sp)
            updated['tenant_id'] = orig_sp.tenant_id
            reader = subnet_alloc.SubnetPoolReader(updated)
            orig_sp.update(
                self._filter_non_model_columns(reader.subnetpool,
                                               models_v2.SubnetPool))
            self._update_subnetpool_prefixes(context, reader.prefixes, id)
        for key in ['min_prefixlen', 'max_prefixlen', 'default_prefixlen']:
            updated['key'] = str(updated[key])

        return updated