~ubuntu-branches/ubuntu/vivid/neutron/vivid-updates

« back to all changes in this revision

Viewing changes to neutron/plugins/vmware/dbexts/lsn_db.py

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2015-03-30 11:17:19 UTC
  • mfrom: (1.1.21)
  • Revision ID: package-import@ubuntu.com-20150330111719-h0gx7233p4jkkgfh
Tags: 1:2015.1~b3-0ubuntu1
* New upstream milestone release:
  - d/control: Align version requirements with upstream.
  - d/control: Add new dependency on oslo-log.
  - d/p/*: Rebase.
  - d/control,d/neutron-plugin-hyperv*: Dropped, decomposed into
    separate project upstream.
  - d/control,d/neutron-plugin-openflow*: Dropped, decomposed into
    separate project upstream.
  - d/neutron-common.install: Add neutron-rootwrap-daemon and 
    neutron-keepalived-state-change binaries.
  - d/rules: Ignore neutron-hyperv-agent when installing; only for Windows.
  - d/neutron-plugin-cisco.install: Drop neutron-cisco-cfg-agent as
    decomposed into separate project upstream.
  - d/neutron-plugin-vmware.install: Drop neutron-check-nsx-config and
    neutron-nsx-manage as decomposed into separate project upstream.
  - d/control: Add dependency on python-neutron-fwaas to neutron-l3-agent.
* d/pydist-overrides: Add overrides for oslo packages.
* d/control: Fixup type in package description (LP: #1263539).
* d/p/fixup-driver-test-execution.patch: Cherry pick fix from upstream VCS
  to support unit test exection in out-of-tree vendor drivers.
* d/neutron-common.postinst: Allow general access to /etc/neutron but limit
  access to root/neutron to /etc/neutron/neutron.conf to support execution
  of unit tests in decomposed vendor drivers.
* d/control: Add dependency on python-neutron-fwaas to neutron-l3-agent
  package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2014 VMware, Inc.
2
 
#
3
 
# All Rights Reserved
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
 
#
17
 
 
18
 
from oslo.db import exception as d_exc
19
 
from sqlalchemy import orm
20
 
 
21
 
from neutron.openstack.common import log as logging
22
 
from neutron.plugins.vmware.common import exceptions as p_exc
23
 
from neutron.plugins.vmware.dbexts import nsx_models
24
 
 
25
 
 
26
 
LOG = logging.getLogger(__name__)
27
 
 
28
 
 
29
 
def lsn_add(context, network_id, lsn_id):
30
 
    """Add Logical Service Node information to persistent datastore."""
31
 
    with context.session.begin(subtransactions=True):
32
 
        lsn = nsx_models.Lsn(network_id, lsn_id)
33
 
        context.session.add(lsn)
34
 
 
35
 
 
36
 
def lsn_remove(context, lsn_id):
37
 
    """Remove Logical Service Node information from datastore given its id."""
38
 
    with context.session.begin(subtransactions=True):
39
 
        context.session.query(nsx_models.Lsn).filter_by(lsn_id=lsn_id).delete()
40
 
 
41
 
 
42
 
def lsn_remove_for_network(context, network_id):
43
 
    """Remove information about the Logical Service Node given its network."""
44
 
    with context.session.begin(subtransactions=True):
45
 
        context.session.query(nsx_models.Lsn).filter_by(
46
 
            net_id=network_id).delete()
47
 
 
48
 
 
49
 
def lsn_get_for_network(context, network_id, raise_on_err=True):
50
 
    """Retrieve LSN information given its network id."""
51
 
    query = context.session.query(nsx_models.Lsn)
52
 
    try:
53
 
        return query.filter_by(net_id=network_id).one()
54
 
    except (orm.exc.NoResultFound, d_exc.DBError):
55
 
        msg = _('Unable to find Logical Service Node for network %s')
56
 
        if raise_on_err:
57
 
            LOG.error(msg, network_id)
58
 
            raise p_exc.LsnNotFound(entity='network',
59
 
                                    entity_id=network_id)
60
 
        else:
61
 
            LOG.warn(msg, network_id)
62
 
 
63
 
 
64
 
def lsn_port_add_for_lsn(context, lsn_port_id, subnet_id, mac, lsn_id):
65
 
    """Add Logical Service Node Port information to persistent datastore."""
66
 
    with context.session.begin(subtransactions=True):
67
 
        lsn_port = nsx_models.LsnPort(lsn_port_id, subnet_id, mac, lsn_id)
68
 
        context.session.add(lsn_port)
69
 
 
70
 
 
71
 
def lsn_port_get_for_subnet(context, subnet_id, raise_on_err=True):
72
 
    """Return Logical Service Node Port information given its subnet id."""
73
 
    with context.session.begin(subtransactions=True):
74
 
        try:
75
 
            return (context.session.query(nsx_models.LsnPort).
76
 
                    filter_by(sub_id=subnet_id).one())
77
 
        except (orm.exc.NoResultFound, d_exc.DBError):
78
 
            if raise_on_err:
79
 
                raise p_exc.LsnPortNotFound(lsn_id=None,
80
 
                                            entity='subnet',
81
 
                                            entity_id=subnet_id)
82
 
 
83
 
 
84
 
def lsn_port_get_for_mac(context, mac_address, raise_on_err=True):
85
 
    """Return Logical Service Node Port information given its mac address."""
86
 
    with context.session.begin(subtransactions=True):
87
 
        try:
88
 
            return (context.session.query(nsx_models.LsnPort).
89
 
                    filter_by(mac_addr=mac_address).one())
90
 
        except (orm.exc.NoResultFound, d_exc.DBError):
91
 
            if raise_on_err:
92
 
                raise p_exc.LsnPortNotFound(lsn_id=None,
93
 
                                            entity='mac',
94
 
                                            entity_id=mac_address)
95
 
 
96
 
 
97
 
def lsn_port_remove(context, lsn_port_id):
98
 
    """Remove Logical Service Node port from the given Logical Service Node."""
99
 
    with context.session.begin(subtransactions=True):
100
 
        (context.session.query(nsx_models.LsnPort).
101
 
         filter_by(lsn_port_id=lsn_port_id).delete())