1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
3
# Copyright 2011, Cisco Systems, 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: Rohit Agarwalla, Cisco Systems, Inc.
20
from sqlalchemy.orm import exc
22
import quantum.plugins.cisco.db.api as db
24
from quantum.plugins.cisco.common import cisco_exceptions as c_exc
25
from quantum.plugins.cisco.db import nexus_models
28
def get_all_nexusport_bindings():
29
"""Lists all the nexusport bindings"""
30
LOG.debug("get_all_nexusport_bindings() called")
31
session = db.get_session()
33
bindings = session.query(nexus_models.NexusPortBinding).all()
35
except exc.NoResultFound:
39
def get_nexusport_binding(vlan_id):
40
"""Lists a nexusport binding"""
41
LOG.debug("get_nexusport_binding() called")
42
session = db.get_session()
44
binding = (session.query(nexus_models.NexusPortBinding).
45
filter_by(vlan_id=vlan_id).all())
47
except exc.NoResultFound:
48
raise c_exc.NexusPortBindingNotFound(vlan_id=vlan_id)
51
def add_nexusport_binding(port_id, vlan_id):
52
"""Adds a nexusport binding"""
53
LOG.debug("add_nexusport_binding() called")
54
session = db.get_session()
55
binding = nexus_models.NexusPortBinding(port_id, vlan_id)
61
def remove_nexusport_binding(vlan_id):
62
"""Removes a nexusport binding"""
63
LOG.debug("remove_nexusport_binding() called")
64
session = db.get_session()
66
binding = (session.query(nexus_models.NexusPortBinding).
67
filter_by(vlan_id=vlan_id).all())
72
except exc.NoResultFound:
76
def update_nexusport_binding(port_id, new_vlan_id):
77
"""Updates nexusport binding"""
78
LOG.debug("update_nexusport_binding called")
79
session = db.get_session()
81
binding = (session.query(nexus_models.NexusPortBinding).
82
filter_by(port_id=port_id).one())
84
binding["vlan_id"] = new_vlan_id
85
session.merge(binding)
88
except exc.NoResultFound:
89
raise c_exc.NexusPortBindingNotFound()