ng-6: Add new fields to nodegroup objects
Since each nodegroup will be one independent stack, we have to add more fields to the table and object in order to track each stack contained in the cluster. This adds the stack_id, version, status, status_reason and version fields to the nodegroup object. Change-Id: I6d36b2d3bc6476efbef6a9f702ffc73cfa0fab8c
This commit is contained in:
parent
9c55bcba91
commit
cbe05aa97d
|
@ -77,6 +77,9 @@ class Handler(object):
|
|||
# Create cluster
|
||||
cluster_driver.create_cluster(context, cluster, create_timeout)
|
||||
cluster.save()
|
||||
for ng in cluster.nodegroups:
|
||||
ng.stack_id = cluster.stack_id
|
||||
ng.save()
|
||||
|
||||
except Exception as e:
|
||||
cluster.status = fields.ClusterStatus.CREATE_FAILED
|
||||
|
|
|
@ -634,7 +634,7 @@ class Connection(object):
|
|||
|
||||
:param context: The security context
|
||||
:param cluster_id: The uuid of the cluster where the nodegroup
|
||||
belongs to.
|
||||
belongs to.
|
||||
:param filters: Filters to apply. Defaults to None.
|
||||
|
||||
:param limit: Maximum number of nodegroups to return.
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
# Copyright (c) 2018 European Organization for Nuclear Research.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# 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.
|
||||
|
||||
"""nodegroups_v2
|
||||
|
||||
Revision ID: c04e925e65c2
|
||||
Revises: 47380964133d
|
||||
Create Date: 2019-06-14 09:29:58.288671
|
||||
|
||||
"""
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'c04e925e65c2'
|
||||
down_revision = '47380964133d'
|
||||
|
||||
from alembic import op
|
||||
|
||||
import sqlalchemy as sa
|
||||
|
||||
from oslo_db.sqlalchemy.types import String
|
||||
|
||||
|
||||
def upgrade():
|
||||
op.add_column('nodegroup', sa.Column('stack_id', String(255)))
|
||||
op.add_column('nodegroup', sa.Column('status', String(20)))
|
||||
op.add_column('nodegroup', sa.Column('status_reason', sa.Text()))
|
||||
op.add_column('nodegroup', sa.Column('version', String(20)))
|
||||
|
||||
# Populate existing nodegroups with the cluster stack_id
|
||||
connection = op.get_bind()
|
||||
|
||||
connection.execute(
|
||||
"UPDATE nodegroup "
|
||||
"INNER JOIN cluster ON nodegroup.cluster_id=cluster.uuid "
|
||||
"SET nodegroup.stack_id=cluster.stack_id, "
|
||||
"nodegroup.status=cluster.status, nodegroup.version=0 "
|
||||
"WHERE nodegroup.cluster_id=cluster.uuid"
|
||||
)
|
|
@ -795,6 +795,10 @@ class Connection(api.Connection):
|
|||
|
||||
query = query.filter_by(**filter_dict)
|
||||
|
||||
if 'status' in filters:
|
||||
query = query.filter(
|
||||
models.NodeGroup.status.in_(filters['status']))
|
||||
|
||||
return query
|
||||
|
||||
def create_nodegroup(self, values):
|
||||
|
@ -882,8 +886,8 @@ class Connection(api.Connection):
|
|||
query = model_query(models.NodeGroup)
|
||||
if not context.is_admin:
|
||||
query = query.filter_by(project_id=context.project_id)
|
||||
query = self._add_nodegoup_filters(query, filters)
|
||||
query = query.filter_by(cluster_id=cluster_id)
|
||||
query = self._add_nodegoup_filters(query, filters)
|
||||
return _paginate_query(models.NodeGroup, limit, marker,
|
||||
sort_key, sort_dir, query)
|
||||
|
||||
|
|
|
@ -289,3 +289,7 @@ class NodeGroup(Base):
|
|||
max_node_count = Column(Integer())
|
||||
min_node_count = Column(Integer())
|
||||
is_default = Column(Boolean, default=False)
|
||||
stack_id = Column(String(255))
|
||||
status = Column(String(20))
|
||||
status_reason = Column(Text)
|
||||
version = Column(String(20))
|
||||
|
|
|
@ -19,6 +19,7 @@ from oslo_versionedobjects import fields
|
|||
|
||||
from magnum.db import api as dbapi
|
||||
from magnum.objects import base
|
||||
from magnum.objects import fields as m_fields
|
||||
|
||||
|
||||
@base.MagnumObjectRegistry.register
|
||||
|
@ -45,7 +46,11 @@ class NodeGroup(base.MagnumPersistentObject, base.MagnumObject,
|
|||
'role': fields.StringField(),
|
||||
'max_node_count': fields.IntegerField(nullable=True),
|
||||
'min_node_count': fields.IntegerField(nullable=False, default=1),
|
||||
'is_default': fields.BooleanField(default=False)
|
||||
'is_default': fields.BooleanField(default=False),
|
||||
'stack_id': fields.StringField(nullable=True),
|
||||
'status': m_fields.ClusterStatusField(nullable=True),
|
||||
'status_reason': fields.StringField(nullable=True),
|
||||
'version': fields.StringField(nullable=True),
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
|
@ -129,7 +134,7 @@ class NodeGroup(base.MagnumPersistentObject, base.MagnumObject,
|
|||
return cls.dbapi.get_cluster_nodegroup_count(context, cluster_id)
|
||||
|
||||
@base.remotable_classmethod
|
||||
def list(cls, context, cluster, limit=None, marker=None,
|
||||
def list(cls, context, cluster_id, limit=None, marker=None,
|
||||
sort_key=None, sort_dir=None, filters=None):
|
||||
"""Return a list of NodeGroup objects.
|
||||
|
||||
|
@ -145,12 +150,9 @@ class NodeGroup(base.MagnumPersistentObject, base.MagnumObject,
|
|||
:returns: a list of :class:`NodeGroup` objects.
|
||||
|
||||
"""
|
||||
db_nodegroups = cls.dbapi.list_cluster_nodegroups(context, cluster,
|
||||
limit=limit,
|
||||
marker=marker,
|
||||
sort_key=sort_key,
|
||||
sort_dir=sort_dir,
|
||||
filters=filters)
|
||||
db_nodegroups = cls.dbapi.list_cluster_nodegroups(
|
||||
context, cluster_id, limit=limit, marker=marker, sort_key=sort_key,
|
||||
sort_dir=sort_dir, filters=filters)
|
||||
return NodeGroup._from_db_object_list(db_nodegroups, cls, context)
|
||||
|
||||
@base.remotable
|
||||
|
|
|
@ -299,7 +299,11 @@ def get_test_nodegroup(**kw):
|
|||
'min_node_count': kw.get('min_node_count', 1),
|
||||
'is_default': kw.get('is_default', True),
|
||||
'created_at': kw.get('created_at'),
|
||||
'updated_at': kw.get('updated_at')
|
||||
'updated_at': kw.get('updated_at'),
|
||||
'status': kw.get('status', 'CREATE_COMPLETE'),
|
||||
'status_reason': kw.get('status_reason', 'Completed successfully'),
|
||||
'version': kw.get('version', '1'),
|
||||
'stack_id': kw.get('stack_id', '047c6319-7abd-fake-a033-8c6af0173cd0'),
|
||||
}
|
||||
|
||||
|
||||
|
@ -327,7 +331,7 @@ def get_nodegroups_for_cluster(**kw):
|
|||
'5d12f6fd-a196-4bf0-ae4c-1f639a523a52'),
|
||||
project_id=kw.get('project_id', 'fake_project'),
|
||||
node_addresses=kw.get('node_addresses', ['172.17.2.4']),
|
||||
node_count=kw.get('node_count', 3)
|
||||
node_count=kw.get('node_count', 3),
|
||||
)
|
||||
|
||||
# get masters nodegroup
|
||||
|
|
|
@ -364,7 +364,7 @@ object_data = {
|
|||
'Stats': '1.0-73a1cd6e3c0294c932a66547faba216c',
|
||||
'Quota': '1.0-94e100aebfa88f7d8428e007f2049c18',
|
||||
'Federation': '1.0-166da281432b083f0e4b851336e12e20',
|
||||
'NodeGroup': '1.0-75e1378a800040312c59f89546a51d74'
|
||||
'NodeGroup': '1.0-8cb4544a28a49860d816158a7c3060b1'
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue