/usr/lib/python2.7/dist-packages/gnocchi/indexer/alembic/versions/ffc7bbeec0b0_migrate_legacy_resources_to_db2.py is in python-gnocchi 3.0.4-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 | # Copyright 2016 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.
#
"""migrate_legacy_resources_to_db2
Revision ID: ffc7bbeec0b0
Revises: 8f376189b9eb
Create Date: 2016-04-14 15:57:13.072128
"""
import json
from alembic import op
import sqlalchemy as sa
from gnocchi.indexer import sqlalchemy_legacy_resources as legacy
# revision identifiers, used by Alembic.
revision = 'ffc7bbeec0b0'
down_revision = '8f376189b9eb'
branch_labels = None
depends_on = None
def upgrade():
bind = op.get_bind()
resource_type = sa.Table(
'resource_type', sa.MetaData(),
sa.Column('name', sa.String(255), nullable=False),
sa.Column('tablename', sa.String(18), nullable=False),
sa.Column('attributes', sa.Text, nullable=False)
)
# NOTE(gordc): fix for incorrect migration:
# 0735ed97e5b3_add_tablename_to_resource_type.py#L46
op.execute(resource_type.update().where(
resource_type.c.name == "instance_network_interface"
).values({'tablename': 'instance_net_int'}))
resource_type_names = [rt.name for rt in
list(bind.execute(resource_type.select()))]
for name, attributes in legacy.ceilometer_resources.items():
if name in resource_type_names:
continue
tablename = legacy.ceilometer_tablenames.get(name, name)
text_attributes = json.dumps(attributes)
op.execute(resource_type.insert().values({
resource_type.c.attributes: text_attributes,
resource_type.c.name: name,
resource_type.c.tablename: tablename,
}))
|