[WIP] 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 in 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
6fe3d5d7f1
commit
05c29563cf
|
@ -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
|
||||
|
|
|
@ -627,7 +627,7 @@ class Connection(object):
|
|||
"""
|
||||
|
||||
@abc.abstractmethod
|
||||
def list_cluster_nodegroups(self, context, cluster_id, filters=None,
|
||||
def list_cluster_nodegroups(self, context, cluster_id=None, filters=None,
|
||||
limit=None, marker=None, sort_key=None,
|
||||
sort_dir=None):
|
||||
"""Get matching nodegroups in a given cluster.
|
||||
|
|
|
@ -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):
|
||||
|
@ -876,14 +880,16 @@ class Connection(api.Connection):
|
|||
except NoResultFound:
|
||||
raise exception.NodeGroupNotFound(nodegroup=nodegroup_name)
|
||||
|
||||
def list_cluster_nodegroups(self, context, cluster_id, filters=None,
|
||||
def list_cluster_nodegroups(self, context, cluster_id=None, filters=None,
|
||||
limit=None, marker=None, sort_key=None,
|
||||
sort_dir=None):
|
||||
query = model_query(models.NodeGroup)
|
||||
if not context.is_admin:
|
||||
query = query.filter_by(project_id=context.project_id)
|
||||
# FIXME: cluster_id can be None only if admin context
|
||||
if cluster_id:
|
||||
query = query.filter_by(cluster_id=cluster_id)
|
||||
query = self._add_nodegoup_filters(query, filters)
|
||||
query = query.filter_by(cluster_id=cluster_id)
|
||||
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=None, 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=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
|
||||
|
|
Loading…
Reference in New Issue