This file is indexed.

/usr/lib/python2.7/dist-packages/neutron_vpnaas/db/migration/alembic_migrations/versions/liberty/contract/333dfd6afaa2_populate_vpn_service_table_fields.py is in python-neutron-vpnaas 2:9.0.0-3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# Copyright 2015 OpenStack Foundation
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.
#

"""Populate VPN service table fields

Revision ID: 333dfd6afaa2
Revises: 56893333aa52
Create Date: 2015-07-27 16:43:59.123456

"""

# revision identifiers, used by Alembic.
revision = '333dfd6afaa2'
down_revision = '56893333aa52'
depends_on = '24f28869838b'


from alembic import op
import netaddr
import sqlalchemy as sa


VPNService = sa.Table('vpnservices', sa.MetaData(),
                      sa.Column('router_id', sa.String(36), nullable=False),
                      sa.Column('external_v4_ip', sa.String(16)),
                      sa.Column('external_v6_ip', sa.String(64)),
                      sa.Column('id', sa.String(36), nullable=False,
                                primary_key=True))
Router = sa.Table('routers', sa.MetaData(),
                  sa.Column('gw_port_id', sa.String(36)),
                  sa.Column('id', sa.String(36), nullable=False,
                            primary_key=True))
Port = sa.Table('ports', sa.MetaData(),
                sa.Column('id', sa.String(36), nullable=False,
                          primary_key=True))
IPAllocation = sa.Table('ipallocations', sa.MetaData(),
                        sa.Column('ip_address', sa.String(64),
                                  nullable=False, primary_key=True),
                        sa.Column('port_id', sa.String(36)))


def _migrate_external_ips(engine):
    """Use router external IPs to populate external_v*_ip entries.

    For each service, look through the associated router's
    gw_port['fixed_ips'] list and store any IPv4 and/or IPv6
    addresses into the new fields. If there are multiple
    addresses for an IP version, then only the first one will
    be stored (the same as the reference driver does).
    """
    session = sa.orm.Session(bind=engine.connect())
    services = session.query(VPNService).all()
    for service in services:
        addresses = session.query(IPAllocation.c.ip_address).filter(
            service.router_id == Router.c.id,
            Router.c.gw_port_id == Port.c.id,
            Port.c.id == IPAllocation.c.port_id).all()
        have_version = []
        for address in addresses:
            version = netaddr.IPAddress(address[0]).version
            if version in have_version:
                continue
            have_version.append(version)
            update = {'external_v%s_ip' % version: address[0]}
            op.execute(VPNService.update().where(
                VPNService.c.id == service.id).values(update))
    session.commit()


def upgrade():
    # Use the router to populate the fields
    for_engine = op.get_bind()
    _migrate_external_ips(for_engine)