summaryrefslogtreecommitdiff
path: root/ironic/db
diff options
context:
space:
mode:
authorKaifeng Wang <kaifeng.w@gmail.com>2019-01-23 17:07:03 +0800
committerKaifeng Wang <kaifeng.w@gmail.com>2019-02-01 10:25:58 +0800
commitd30d8149564260bfe219fbefb6b13d2817ea592f (patch)
tree60d635529a260ddf20be2411fd124d5e3360f8a7 /ironic/db
parent680e5b5687881589a79e7238d3f0281d4c9d1a13 (diff)
downloadironic-d30d8149564260bfe219fbefb6b13d2817ea592f.tar.gz
Add description field to node
This patch implements the feature of storing informational free-form text into ironic node, via the "description" field. Operators can do simple queries on the context of description. Change-Id: I787fb0df34566aff30dea4c4a3ba0e1ec820d044 Story: 2003089 Task: 23178
Diffstat (limited to 'ironic/db')
-rw-r--r--ironic/db/sqlalchemy/alembic/versions/28c44432c9c3_add_node_description.py31
-rw-r--r--ironic/db/sqlalchemy/api.py15
-rw-r--r--ironic/db/sqlalchemy/models.py1
3 files changed, 44 insertions, 3 deletions
diff --git a/ironic/db/sqlalchemy/alembic/versions/28c44432c9c3_add_node_description.py b/ironic/db/sqlalchemy/alembic/versions/28c44432c9c3_add_node_description.py
new file mode 100644
index 000000000..3f3b53697
--- /dev/null
+++ b/ironic/db/sqlalchemy/alembic/versions/28c44432c9c3_add_node_description.py
@@ -0,0 +1,31 @@
+# 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.
+
+"""add node description
+
+Revision ID: 28c44432c9c3
+Revises: dd67b91a1981
+Create Date: 2019-01-23 13:54:08.850421
+
+"""
+
+from alembic import op
+import sqlalchemy as sa
+
+# revision identifiers, used by Alembic.
+revision = '28c44432c9c3'
+down_revision = '9cbeefa3763f'
+
+
+def upgrade():
+ op.add_column('nodes', sa.Column('description', sa.Text(),
+ nullable=True))
diff --git a/ironic/db/sqlalchemy/api.py b/ironic/db/sqlalchemy/api.py
index ff2b97668..b134325f5 100644
--- a/ironic/db/sqlalchemy/api.py
+++ b/ironic/db/sqlalchemy/api.py
@@ -225,7 +225,7 @@ class Connection(api.Connection):
def __init__(self):
pass
- def _add_nodes_filters(self, query, filters):
+ def _validate_nodes_filters(self, filters):
if filters is None:
filters = dict()
supported_filters = {'console_enabled', 'maintenance', 'driver',
@@ -233,13 +233,17 @@ class Connection(api.Connection):
'chassis_uuid', 'associated', 'reserved',
'reserved_by_any_of', 'provisioned_before',
'inspection_started_before', 'fault',
- 'conductor_group', 'owner',
- 'uuid_in', 'with_power_state'}
+ 'conductor_group', 'owner', 'uuid_in',
+ 'with_power_state', 'description_contains'}
unsupported_filters = set(filters).difference(supported_filters)
if unsupported_filters:
msg = _("SqlAlchemy API does not support "
"filtering by %s") % ', '.join(unsupported_filters)
raise ValueError(msg)
+ return filters
+
+ def _add_nodes_filters(self, query, filters):
+ filters = self._validate_nodes_filters(filters)
for field in ['console_enabled', 'maintenance', 'driver',
'resource_class', 'provision_state', 'uuid', 'id',
'fault', 'conductor_group', 'owner']:
@@ -280,6 +284,11 @@ class Connection(api.Connection):
query = query.filter(models.Node.power_state != sql.null())
else:
query = query.filter(models.Node.power_state == sql.null())
+ if 'description_contains' in filters:
+ keyword = filters['description_contains']
+ if keyword is not None:
+ query = query.filter(
+ models.Node.description.like(r'%{}%'.format(keyword)))
return query
diff --git a/ironic/db/sqlalchemy/models.py b/ironic/db/sqlalchemy/models.py
index ddd300a83..e70fefcc6 100644
--- a/ironic/db/sqlalchemy/models.py
+++ b/ironic/db/sqlalchemy/models.py
@@ -182,6 +182,7 @@ class Node(Base):
owner = Column(String(255), nullable=True)
allocation_id = Column(Integer, ForeignKey('allocations.id'),
nullable=True)
+ description = Column(Text, nullable=True)
bios_interface = Column(String(255), nullable=True)
boot_interface = Column(String(255), nullable=True)