1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
# Copyright 2011 Nicira Networks, Inc.
5
# Licensed under the Apache License, Version 2.0 (the "License"); you may
6
# not use this file except in compliance with the License. You may obtain
7
# a copy of the License at
9
# http://www.apache.org/licenses/LICENSE-2.0
11
# Unless required by applicable law or agreed to in writing, software
12
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
# License for the specific language governing permissions and limitations
16
# @author: Somik Behera, Nicira Networks, Inc.
17
# @author: Brad Hall, Nicira Networks, Inc.
18
# @author: Dan Wendlandt, Nicira Networks, Inc.
21
from sqlalchemy.orm import exc
23
import quantum.db.api as db
24
import quantum.db.models as models
29
session = db.get_session()
31
bindings = session.query(ovs_models.VlanBinding).\
33
except exc.NoResultFound:
37
res.append((x.vlan_id, x.network_id))
41
def add_vlan_binding(vlanid, netid):
42
session = db.get_session()
43
binding = ovs_models.VlanBinding(vlanid, netid)
46
return binding.vlan_id
49
def remove_vlan_binding(netid):
50
session = db.get_session()
52
binding = session.query(ovs_models.VlanBinding).\
53
filter_by(network_id=netid).\
55
session.delete(binding)
56
except exc.NoResultFound:
61
def update_network_binding(netid, ifaceid):
62
session = db.get_session()
63
# Add to or delete from the bindings table
66
binding = session.query(ovs_models.NetworkBinding).\
67
filter_by(network_id=netid).\
69
session.delete(binding)
70
except exc.NoResultFound:
71
raise Exception("No binding found with network_id = %s" % netid)
73
binding = ovs_models.NetworkBinding(netid, ifaceid)