~zulcss/ubuntu/precise/quantum/trunk

« back to all changes in this revision

Viewing changes to quantum/plugins/cisco/db/nexus_db.py

  • Committer: Chuck Short
  • Date: 2012-11-26 19:51:11 UTC
  • mfrom: (26.1.1 raring-proposed)
  • Revision ID: zulcss@ubuntu.com-20121126195111-jnz2cr4xi6whemw2
* New upstream release for the Ubuntu Cloud Archive.
* debian/patches/*: Refreshed for opening of Grizzly.
* New upstream release.
* debian/rules: FTFBS if there is missing binaries.
* debian/quantum-server.install: Add quantum-debug.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
 
 
3
 
# Copyright 2011, Cisco Systems, Inc.
4
 
#
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
8
 
#
9
 
#         http://www.apache.org/licenses/LICENSE-2.0
10
 
#
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
15
 
#    under the License.
16
 
# @author: Rohit Agarwalla, Cisco Systems, Inc.
17
 
 
18
 
import logging as LOG
19
 
 
20
 
from sqlalchemy.orm import exc
21
 
 
22
 
import quantum.plugins.cisco.db.api as db
23
 
 
24
 
from quantum.plugins.cisco.common import cisco_exceptions as c_exc
25
 
from quantum.plugins.cisco.db import nexus_models
26
 
 
27
 
 
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()
32
 
    try:
33
 
        bindings = session.query(nexus_models.NexusPortBinding).all()
34
 
        return bindings
35
 
    except exc.NoResultFound:
36
 
        return []
37
 
 
38
 
 
39
 
def get_nexusport_binding(vlan_id):
40
 
    """Lists a nexusport binding"""
41
 
    LOG.debug("get_nexusport_binding() called")
42
 
    session = db.get_session()
43
 
    try:
44
 
        binding = (session.query(nexus_models.NexusPortBinding).
45
 
                   filter_by(vlan_id=vlan_id).all())
46
 
        return binding
47
 
    except exc.NoResultFound:
48
 
        raise c_exc.NexusPortBindingNotFound(vlan_id=vlan_id)
49
 
 
50
 
 
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)
56
 
    session.add(binding)
57
 
    session.flush()
58
 
    return binding
59
 
 
60
 
 
61
 
def remove_nexusport_binding(vlan_id):
62
 
    """Removes a nexusport binding"""
63
 
    LOG.debug("remove_nexusport_binding() called")
64
 
    session = db.get_session()
65
 
    try:
66
 
        binding = (session.query(nexus_models.NexusPortBinding).
67
 
                   filter_by(vlan_id=vlan_id).all())
68
 
        for bind in binding:
69
 
            session.delete(bind)
70
 
        session.flush()
71
 
        return binding
72
 
    except exc.NoResultFound:
73
 
        pass
74
 
 
75
 
 
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()
80
 
    try:
81
 
        binding = (session.query(nexus_models.NexusPortBinding).
82
 
                   filter_by(port_id=port_id).one())
83
 
        if new_vlan_id:
84
 
            binding["vlan_id"] = new_vlan_id
85
 
        session.merge(binding)
86
 
        session.flush()
87
 
        return binding
88
 
    except exc.NoResultFound:
89
 
        raise c_exc.NexusPortBindingNotFound()