~ubuntu-branches/ubuntu/saucy/quantum/saucy

« back to all changes in this revision

Viewing changes to quantum/plugins/nicira/nicira_nvp_plugin/nicira_db.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2013-05-31 09:37:25 UTC
  • mfrom: (2.1.22)
  • Revision ID: package-import@ubuntu.com-20130531093725-bf9jom93l7jm57iv
Tags: 1:2013.2~b1-0ubuntu1
* New upstream release.
* debian/patches/fix-quantum-configuration.patch: Refreshed
* debian/control: Add testrepository.
* debian/control: Add subunit.
* debian/control: Add python-d21o1 and python-pbr as build-depends.
* debian/control: Add python-stevedore.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
 
 
3
 
# Copyright 2012 Nicira, Inc.
4
 
# All Rights Reserved.
5
 
#
6
 
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
7
 
#    not use this file except in compliance with the License. You may obtain
8
 
#    a copy of the License at
9
 
#
10
 
#         http://www.apache.org/licenses/LICENSE-2.0
11
 
#
12
 
#    Unless required by applicable law or agreed to in writing, software
13
 
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14
 
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15
 
#    License for the specific language governing permissions and limitations
16
 
#    under the License.
17
 
 
18
 
from sqlalchemy.orm import exc
19
 
 
20
 
import quantum.db.api as db
21
 
from quantum.openstack.common import log as logging
22
 
from quantum.plugins.nicira.nicira_nvp_plugin import nicira_models
23
 
from quantum.plugins.nicira.nicira_nvp_plugin import nicira_networkgw_db
24
 
 
25
 
LOG = logging.getLogger(__name__)
26
 
 
27
 
 
28
 
def get_network_binding(session, network_id):
29
 
    session = session or db.get_session()
30
 
    try:
31
 
        binding = (session.query(nicira_models.NvpNetworkBinding).
32
 
                   filter_by(network_id=network_id).
33
 
                   one())
34
 
        return binding
35
 
    except exc.NoResultFound:
36
 
        return
37
 
 
38
 
 
39
 
def get_network_binding_by_vlanid(session, vlan_id):
40
 
    session = session or db.get_session()
41
 
    try:
42
 
        binding = (session.query(nicira_models.NvpNetworkBinding).
43
 
                   filter_by(vlan_id=vlan_id).
44
 
                   one())
45
 
        return binding
46
 
    except exc.NoResultFound:
47
 
        return
48
 
 
49
 
 
50
 
def get_network_binding_by_vlanid_and_phynet(session, vlan_id,
51
 
                                             physical_network):
52
 
    session = session or db.get_session()
53
 
    try:
54
 
        binding = (session.query(nicira_models.NvpNetworkBinding).
55
 
                   filter_by(vlan_id=vlan_id, phy_uuid=physical_network).
56
 
                   one())
57
 
        return binding
58
 
    except exc.NoResultFound:
59
 
        return
60
 
 
61
 
 
62
 
def add_network_binding(session, network_id, binding_type, phy_uuid, vlan_id):
63
 
    with session.begin(subtransactions=True):
64
 
        binding = nicira_models.NvpNetworkBinding(network_id, binding_type,
65
 
                                                  phy_uuid, vlan_id)
66
 
        session.add(binding)
67
 
    return binding
68
 
 
69
 
 
70
 
def add_quantum_nvp_port_mapping(session, quantum_id, nvp_id):
71
 
    with session.begin(subtransactions=True):
72
 
        mapping = nicira_models.QuantumNvpPortMapping(quantum_id, nvp_id)
73
 
        session.add(mapping)
74
 
        return mapping
75
 
 
76
 
 
77
 
def get_nvp_port_id(session, quantum_id):
78
 
    try:
79
 
        mapping = (session.query(nicira_models.QuantumNvpPortMapping).
80
 
                   filter_by(quantum_id=quantum_id).
81
 
                   one())
82
 
        return mapping['nvp_id']
83
 
    except exc.NoResultFound:
84
 
        return
85
 
 
86
 
 
87
 
def unset_default_network_gateways(session):
88
 
    with session.begin(subtransactions=True):
89
 
        session.query(nicira_networkgw_db.NetworkGateway).update(
90
 
            {nicira_networkgw_db.NetworkGateway.default: False})
91
 
 
92
 
 
93
 
def set_default_network_gateway(session, gw_id):
94
 
    with session.begin(subtransactions=True):
95
 
        gw = (session.query(nicira_networkgw_db.NetworkGateway).
96
 
              filter_by(id=gw_id).one())
97
 
        gw['default'] = True