<s> from oslo_db import exception as oslo_db_exception <EOL> from sqlalchemy . orm import exc as orm_exc <EOL> from neutron . common import exceptions as n_exc <EOL> from neutron . db import common_db_mixin as db <EOL> from neutron . db . qos import models <EOL> def create_policy_network_binding ( context , policy_id , network_id ) : <EOL> try : <EOL> with context . session . begin ( subtransactions = True ) : <EOL> db_obj = models . QosNetworkPolicyBinding ( policy_id = policy_id , <EOL> network_id = network_id ) <EOL> context . session . add ( db_obj ) <EOL> except oslo_db_exception . DBReferenceError : <EOL> raise n_exc . NetworkQosBindingNotFound ( net_id = network_id , <EOL> policy_id = policy_id ) <EOL> def delete_policy_network_binding ( context , policy_id , network_id ) : <EOL> try : <EOL> with context . session . begin ( subtransactions = True ) : <EOL> db_object = ( db . model_query ( context , <EOL> models . QosNetworkPolicyBinding ) <EOL> . filter_by ( policy_id = policy_id , <EOL> network_id = network_id ) . one ( ) ) <EOL> context . session . delete ( db_object ) <EOL> except orm_exc . NoResultFound : <EOL> raise n_exc . NetworkQosBindingNotFound ( net_id = network_id , <EOL> policy_id = policy_id ) <EOL> def get_network_ids_by_network_policy_binding ( context , policy_id ) : <EOL> query = ( db . model_query ( context , models . QosNetworkPolicyBinding ) <EOL> . filter_by ( policy_id = policy_id ) . all ( ) ) <EOL> return [ entry . network_id for entry in query ] <EOL> def create_policy_port_binding ( context , policy_id , port_id ) : <EOL> try : <EOL> with context . session . begin ( subtransactions = True ) : <EOL> db_obj = models . QosPortPolicyBinding ( policy_id = policy_id , <EOL> port_id = port_id ) <EOL> context . session . add ( db_obj ) <EOL> except oslo_db_exception . DBReferenceError : <EOL> raise n_exc . PortQosBindingNotFound ( port_id = port_id , <EOL> policy_id = policy_id ) <EOL> def delete_policy_port_binding ( context , policy_id , port_id ) : <EOL> try : <EOL> with context . session . begin ( subtransactions = True ) : <EOL> db_object = ( db . model_query ( context , models . QosPortPolicyBinding ) <EOL> . filter_by ( policy_id = policy_id , <EOL> port_id = port_id ) . one ( ) ) <EOL> context . session . delete ( db_object ) <EOL> except orm_exc . NoResultFound : <EOL> raise n_exc . PortQosBindingNotFound ( port_id = port_id , <EOL> policy_id = policy_id ) <EOL> def get_port_ids_by_port_policy_binding ( context , policy_id ) : <EOL> query = ( db . model_query ( context , models . QosPortPolicyBinding ) <EOL> . filter_by ( policy_id = policy_id ) . all ( ) ) <EOL> return [ entry . port_id for entry in query ] </s>
