示例#1
0
    def create(self):
        fields = self._get_changed_persistent_fields()
        with db_api.autonested_transaction(self.obj_context.session):
            try:
                db_obj = obj_db_api.create_object(
                    self.obj_context, self.db_model,
                    self.modify_fields_to_db(fields))
            except obj_exc.DBDuplicateEntry as db_exc:
                raise o_exc.NeutronDbObjectDuplicateEntry(
                    object_class=self.__class__, db_exception=db_exc)

            self.from_db_object(db_obj)
示例#2
0
    def add(self, model_obj):
        if model_obj.__tablename__ not in self.resource_store.store_map:
            return
        model_dict = DotDict(model_obj._as_dict())
        if 'project_id' in model_dict:
            model_dict['tenant_id'] = model_dict['project_id']

        if model_obj.__tablename__ == 'networks':
            model_dict['subnets'] = []
        if model_obj.__tablename__ == 'ports':
            model_dict['dhcp_opts'] = []
            model_dict['security_groups'] = []
            model_dict['fixed_ips'] = []

        link_models(model_obj, model_dict, 'subnetpoolprefixes',
                    'subnetpool_id', 'subnetpools', 'id', 'prefixes')
        link_models(model_obj, model_dict, 'ipallocations', 'port_id', 'ports',
                    'id', 'fixed_ips')
        link_models(model_obj, model_dict, 'subnets', 'network_id', 'networks',
                    'id', 'subnets')
        link_models(model_obj, model_dict, 'securitygrouprules',
                    'security_group_id', 'securitygroups', 'id',
                    'security_group_rules')

        if model_obj.__tablename__ == 'routerports':
            for port in self.resource_store.TOP_PORTS:
                if port['id'] == model_dict['port_id']:
                    model_dict['port'] = port
                    port.update(model_dict)
                    break
        if model_obj.__tablename__ == 'externalnetworks':
            for net in self.resource_store.TOP_NETWORKS:
                if net['id'] == model_dict['network_id']:
                    net['external'] = True
                    net['router:external'] = True
                    break
        if model_obj.__tablename__ == 'networkrbacs':
            if (model_dict['action'] == 'access_as_shared'
                    and model_dict['target_tenant'] == '*'):
                for net in self.resource_store.TOP_NETWORKS:
                    if net['id'] == model_dict['object']:
                        net['shared'] = True
                        break

        link_models(model_obj, model_dict, 'routerports', 'router_id',
                    'routers', 'id', 'attached_ports')

        if model_obj.__tablename__ == 'subnetroutes':
            for subnet in self.resource_store.TOP_SUBNETS:
                if subnet['id'] != model_dict['subnet_id']:
                    continue
                host_route = {
                    'nexthop': model_dict['nexthop'],
                    'destination': model_dict['destination']
                }
                subnet['host_routes'].append(host_route)
                break

        if model_obj.__tablename__ == 'dnsnameservers':
            for subnet in self.resource_store.TOP_SUBNETS:
                if subnet['id'] != model_dict['subnet_id']:
                    continue
                dnsnameservers = model_dict['address']
                subnet['dns_nameservers'].append(dnsnameservers)
                break

        if model_obj.__tablename__ == 'ml2_flat_allocations':
            for alloc in self.resource_store.TOP_ML2_FLAT_ALLOCATIONS:
                if alloc['physical_network'] == model_dict['physical_network']:
                    raise q_obj_exceptions.NeutronDbObjectDuplicateEntry(
                        model_obj.__class__,
                        DotDict({
                            'columns': '',
                            'value': ''
                        }))

        self._extend_standard_attr(model_dict)

        self.add_hook(model_obj, model_dict)
        self.resource_store.store_map[model_obj.__tablename__].append(
            model_dict)