Add two new resources

This change adds instance_disk and instance_network_interface resources.

Change-Id: I592ad5c200770644248d3c36aa82111643569e20
This commit is contained in:
Mehdi Abaakouk
2015-08-27 11:12:48 +02:00
parent c18fa79dc8
commit d16b47d7e0
6 changed files with 129 additions and 3 deletions

View File

@@ -0,0 +1,90 @@
# 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.
#
"""create instance_disk and instance_net_int tables
Revision ID: 3901f5ea2b8e
Revises: 42ee7f3e25f8
Create Date: 2015-08-27 17:00:25.092891
"""
# revision identifiers, used by Alembic.
revision = '3901f5ea2b8e'
down_revision = '42ee7f3e25f8'
branch_labels = None
depends_on = None
from alembic import op
import sqlalchemy as sa
import sqlalchemy_utils
def upgrade():
for table in ["resource", "resource_history"]:
op.alter_column(table, "type",
type_=sa.Enum('generic', 'instance', 'swift_account',
'volume', 'ceph_account', 'network',
'identity', 'ipmi', 'stack', 'image',
'instance_network_interface',
'instance_disk',
name='resource_type_enum'),
nullable=False)
# NOTE(sileht): postgresql have a builtin ENUM type, so
# just altering the column won't works.
# https://bitbucket.org/zzzeek/alembic/issues/270/altering-enum-type
# Does it break offline migration because we use get_bind() ?
bind = op.get_bind()
if bind and bind.engine.name == "postgresql":
for value in ["instance_network_interface", "instance_disk"]:
op.execute("ALTER TYPE resource_type_enum ADD VALUE '%s'" % value)
for table in ['instance_disk', 'instance_net_int']:
op.create_table(
table,
sa.Column('id', sqlalchemy_utils.types.uuid.UUIDType(binary=True),
nullable=False),
sa.Column('instance_id',
sqlalchemy_utils.types.uuid.UUIDType(binary=True),
nullable=False),
sa.Column('name', sa.String(length=255), nullable=False),
sa.Index('ix_%s_id' % table, 'id', unique=False),
sa.ForeignKeyConstraint(['id'], ['resource.id'],
name="fk_%s_id_resource_id" % table,
ondelete='CASCADE'),
sa.PrimaryKeyConstraint('id'),
mysql_charset='utf8',
mysql_engine='InnoDB'
)
op.create_table(
'%s_history' % table,
sa.Column('instance_id',
sqlalchemy_utils.types.uuid.UUIDType(binary=True),
nullable=False),
sa.Column('name', sa.String(length=255), nullable=False),
sa.Column('revision', sa.Integer(), nullable=False),
sa.Index('ix_%s_history_revision' % table, 'revision',
unique=False),
sa.ForeignKeyConstraint(['revision'],
['resource_history.revision'],
name=("fk_%s_history_"
"resource_history_revision") % table,
ondelete='CASCADE'),
sa.PrimaryKeyConstraint('revision'),
mysql_charset='utf8',
mysql_engine='InnoDB'
)

View File

@@ -47,14 +47,15 @@ def get_resource_mappers(ext):
resource_ext = ext.plugin
resource_history_ext = ResourceHistory
else:
tablename = getattr(ext.plugin, '__tablename__', ext.name)
resource_ext = type(str(ext.name),
(ext.plugin, base.ResourceExtMixin, Resource),
{"__tablename__": ext.name})
{"__tablename__": tablename})
resource_history_ext = type(str("%s_history" % ext.name),
(ext.plugin, base.ResourceHistoryExtMixin,
ResourceHistory),
{"__tablename__": (
"%s_history" % ext.name)})
"%s_history" % tablename)})
return {'resource': resource_ext,
'history': resource_history_ext}

View File

@@ -216,7 +216,8 @@ class ResourceMixin(ResourceJsonifier):
'swift_account', 'volume',
'ceph_account', 'network',
'identity', 'ipmi', 'stack',
'image',
'image', 'instance_disk',
'instance_network_interface',
name="resource_type_enum"),
nullable=False, default='generic')
created_by_user_id = sqlalchemy.Column(

View File

@@ -15,6 +15,7 @@
from __future__ import absolute_import
import sqlalchemy
import sqlalchemy_utils
class Image(object):
@@ -32,5 +33,18 @@ class Instance(object):
server_group = sqlalchemy.Column(sqlalchemy.String(255))
class InstanceDisk(object):
name = sqlalchemy.Column(sqlalchemy.String(255), nullable=False)
instance_id = sqlalchemy.Column(sqlalchemy_utils.UUIDType(),
nullable=False)
class InstanceNetworkInterface(object):
__tablename__ = 'instance_net_int'
name = sqlalchemy.Column(sqlalchemy.String(255), nullable=False)
instance_id = sqlalchemy.Column(sqlalchemy_utils.UUIDType(),
nullable=False)
class Volume(object):
display_name = sqlalchemy.Column(sqlalchemy.String(255), nullable=False)

View File

@@ -883,6 +883,22 @@ class SwiftAccountResourceController(GenericResourceController):
_resource_type = 'swift_account'
class InstanceDisksResourceController(GenericResourceController):
_resource_type = 'instance_disk'
Resource = ResourceSchema({
"name": six.text_type,
"instance_id": UUID,
})
class InstanceNetworkInterfacesResourceController(GenericResourceController):
_resource_type = 'instance_network_interface'
Resource = ResourceSchema({
"name": six.text_type,
"instance_id": UUID,
})
class InstanceResourceController(GenericResourceController):
_resource_type = 'instance'

View File

@@ -31,6 +31,8 @@ packages =
gnocchi.indexer.resources =
generic = gnocchi.indexer.sqlalchemy_base:Resource
instance = gnocchi.indexer.sqlalchemy_extension:Instance
instance_disk = gnocchi.indexer.sqlalchemy_extension:InstanceDisk
instance_network_interface = gnocchi.indexer.sqlalchemy_extension:InstanceNetworkInterface
swift_account = gnocchi.indexer.sqlalchemy_base:ResourceExt
volume = gnocchi.indexer.sqlalchemy_extension:Volume
ceph_account = gnocchi.indexer.sqlalchemy_base:ResourceExt
@@ -43,6 +45,8 @@ gnocchi.indexer.resources =
gnocchi.controller.resources =
generic = gnocchi.rest:GenericResourcesController
instance = gnocchi.rest:InstancesResourcesController
instance_disk = gnocchi.rest:InstanceDisksResourcesController
instance_network_interface = gnocchi.rest:InstanceNetworkInterfacesResourcesController
swift_account = gnocchi.rest:SwiftAccountsResourcesController
volume = gnocchi.rest:VolumesResourcesController
ceph_account = gnocchi.rest:CephAccountsResourcesController