dynamic action description

Add a new table to save the mapping
Add logic to update the table when action loading
Add logic to show the action description

Change-Id: Ia008a8715bcc666ab0fefe444ef612394c775e91
Implements: blueprint dynamic-action-description
This commit is contained in:
licanwei
2017-07-15 02:25:43 -07:00
parent 0ddfa278ef
commit a24b7f0b61
15 changed files with 771 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
"""add action description table
Revision ID: d09a5945e4a0
Revises: d098df6021e2
Create Date: 2017-07-13 20:33:01.473711
"""
# revision identifiers, used by Alembic.
revision = 'd09a5945e4a0'
down_revision = 'd098df6021e2'
from alembic import op
import oslo_db
import sqlalchemy as sa
def upgrade():
op.create_table('action_descriptions',
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('deleted_at', sa.DateTime(), nullable=True),
sa.Column('deleted', oslo_db.sqlalchemy.types.SoftDeleteInteger(), nullable=True),
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('action_type', sa.String(length=255), nullable=False),
sa.Column('description', sa.String(length=255), nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('action_type', name='uniq_action_description0action_type')
)
def downgrade():
op.drop_table('action_descriptions')

View File

@@ -1127,3 +1127,74 @@ class Connection(api.BaseConnection):
return self._soft_delete(models.Service, service_id)
except exception.ResourceNotFound:
raise exception.ServiceNotFound(service=service_id)
# ### ACTION_DESCRIPTIONS ### #
def _add_action_descriptions_filters(self, query, filters):
if not filters:
filters = {}
plain_fields = ['id', 'action_type']
return self._add_filters(
query=query, model=models.ActionDescription, filters=filters,
plain_fields=plain_fields)
def get_action_description_list(self, context, filters=None, limit=None,
marker=None, sort_key=None,
sort_dir=None, eager=False):
query = model_query(models.ActionDescription)
if eager:
query = self._set_eager_options(models.ActionDescription, query)
query = self._add_action_descriptions_filters(query, filters)
if not context.show_deleted:
query = query.filter_by(deleted_at=None)
return _paginate_query(models.ActionDescription, limit, marker,
sort_key, sort_dir, query)
def create_action_description(self, values):
try:
action_description = self._create(models.ActionDescription, values)
except db_exc.DBDuplicateEntry:
raise exception.ActionDescriptionAlreadyExists(
action_type=values['action_type'])
return action_description
def _get_action_description(self, context, fieldname, value, eager):
try:
return self._get(context, model=models.ActionDescription,
fieldname=fieldname, value=value, eager=eager)
except exception.ResourceNotFound:
raise exception.ActionDescriptionNotFound(action_id=value)
def get_action_description_by_id(self, context,
action_id, eager=False):
return self._get_action_description(
context, fieldname="id", value=action_id, eager=eager)
def get_action_description_by_type(self, context,
action_type, eager=False):
return self._get_action_description(
context, fieldname="action_type", value=action_type, eager=eager)
def destroy_action_description(self, action_id):
try:
return self._destroy(models.ActionDescription, action_id)
except exception.ResourceNotFound:
raise exception.ActionDescriptionNotFound(
action_id=action_id)
def update_action_description(self, action_id, values):
try:
return self._update(models.ActionDescription,
action_id, values)
except exception.ResourceNotFound:
raise exception.ActionDescriptionNotFound(
action_id=action_id)
def soft_delete_action_description(self, action_id):
try:
return self._soft_delete(models.ActionDescription, action_id)
except exception.ResourceNotFound:
raise exception.ActionDescriptionNotFound(
action_id=action_id)

View File

@@ -278,3 +278,17 @@ class Service(Base):
name = Column(String(255), nullable=False)
host = Column(String(255), nullable=False)
last_seen_up = Column(DateTime, nullable=True)
class ActionDescription(Base):
"""Represents a action description"""
__tablename__ = 'action_descriptions'
__table_args__ = (
UniqueConstraint('action_type',
name="uniq_action_description0action_type"),
table_args()
)
id = Column(Integer, primary_key=True)
action_type = Column(String(255), nullable=False)
description = Column(String(255), nullable=False)