def _update_db_port(self, context, db_port, new_port, network_id, new_mac): # Remove all attributes in new_port which are not in the port DB model # and then update the port try: db_port.update( self._filter_non_model_columns(new_port, models_v2.Port)) context.session.flush() except db_exc.DBDuplicateEntry: raise n_exc.MacAddressInUse(net_id=network_id, mac=new_mac)
def _create_port_with_mac(self, context, network_id, port_data, mac_address): try: # since this method could either be used within or outside the # transaction, use convenience method to avoid passing a flag with db_api.autonested_transaction(context.session): db_port = models_v2.Port(mac_address=mac_address, **port_data) context.session.add(db_port) return db_port except db_exc.DBDuplicateEntry: raise n_exc.MacAddressInUse(net_id=network_id, mac=mac_address)