Merge "Create runtime_config table"
This commit is contained in:
commit
1d6ef90409
|
@ -2409,3 +2409,10 @@ CSTATE_PATH = "/sys/devices/system/cpu/cpu0/cpuidle"
|
|||
|
||||
# Auto-recovery limits for kube upgrade abort
|
||||
AUTO_RECOVERY_COUNT = 3
|
||||
|
||||
# Puppet Runtime Manifest constants
|
||||
RUNTIME_CONFIG_APPLY_TIMEOUT_IN_SECS = 600
|
||||
RUNTIME_CONFIG_STATE_PENDING = "pending"
|
||||
RUNTIME_CONFIG_STATE_APPLIED = "applied"
|
||||
RUNTIME_CONFIG_STATE_FAILED = "failed"
|
||||
RUNTIME_CONFIG_STATE_RETRIED = "retried"
|
||||
|
|
|
@ -5054,3 +5054,48 @@ class Connection(object):
|
|||
|
||||
:param networktype: network type
|
||||
"""
|
||||
|
||||
@abc.abstractmethod
|
||||
def runtime_config_create(self, values):
|
||||
"""Create a runtime_config entry
|
||||
|
||||
:param values: runtime_config entry relevant information
|
||||
"""
|
||||
@abc.abstractmethod
|
||||
def runtime_config_destroy(self, id):
|
||||
"""Destroy a runtime_config entry
|
||||
|
||||
:param id: runtime_config id or uuid
|
||||
"""
|
||||
|
||||
@abc.abstractmethod
|
||||
def runtime_config_prune(self, older_than):
|
||||
"""Prune records older than a given date
|
||||
|
||||
:param older_than: date to filter entries older than it
|
||||
"""
|
||||
|
||||
@abc.abstractmethod
|
||||
def runtime_config_update(self, id, values):
|
||||
"""Update a runtime_config entry
|
||||
|
||||
:param id: runtime_config id or uuid
|
||||
:param values: dictionary containing fields to be updated
|
||||
"""
|
||||
|
||||
@abc.abstractmethod
|
||||
def runtime_config_get(self, id, host_id=None):
|
||||
"""Returns a list of runtime_config entries for a given uuid
|
||||
|
||||
:param id: runtime config id or uuid
|
||||
:param host_id: host id
|
||||
"""
|
||||
|
||||
@abc.abstractmethod
|
||||
def runtime_config_get_all(self, config_uuid=None, state=None, older_than=None):
|
||||
"""Returns a list of runtime_config entries with a given filter
|
||||
|
||||
:param config_uuid: runtime_config uuid
|
||||
:param state: runtime_config state
|
||||
:param older_than: date to filter entries older than it
|
||||
"""
|
||||
|
|
|
@ -9348,3 +9348,75 @@ class Connection(api.Connection):
|
|||
if count != 1:
|
||||
raise exception.NotFound()
|
||||
return query.one()
|
||||
|
||||
@db_objects.objectify(objects.runtime_config)
|
||||
def runtime_config_create(self, values):
|
||||
runtime_config = models.RuntimeConfig()
|
||||
runtime_config.update(values)
|
||||
with _session_for_write() as session:
|
||||
try:
|
||||
session.add(runtime_config)
|
||||
session.flush()
|
||||
except db_exc.DBDuplicateEntry:
|
||||
LOG.error('Entry for runtime_config (config_uuid=%s, host_id=%s) already exists.' % (
|
||||
values['config_uuid'], values['forihostid']))
|
||||
return runtime_config
|
||||
|
||||
@db_objects.objectify(objects.runtime_config)
|
||||
def runtime_config_destroy(self, id):
|
||||
with _session_for_write() as session:
|
||||
query = model_query(models.RuntimeConfig, session=session)
|
||||
if utils.is_uuid_like(id):
|
||||
query = query.filter_by(config_uuid=id)
|
||||
else:
|
||||
query = query.filter_by(id=id)
|
||||
query.delete()
|
||||
|
||||
@db_objects.objectify(objects.runtime_config)
|
||||
def runtime_config_prune(self, older_than):
|
||||
with _session_for_write() as session:
|
||||
query = model_query(models.RuntimeConfig, session=session)
|
||||
query = query.filter(models.RuntimeConfig.created_at < older_than)
|
||||
result = query.all()
|
||||
query.delete()
|
||||
return result
|
||||
|
||||
@db_objects.objectify(objects.runtime_config)
|
||||
def runtime_config_update(self, id, values):
|
||||
with _session_for_write() as session:
|
||||
query = model_query(models.RuntimeConfig, session=session)
|
||||
query = query.filter_by(id=id)
|
||||
count = query.update(values)
|
||||
if count != 1:
|
||||
raise exception.NotFound()
|
||||
return query.one()
|
||||
|
||||
@db_objects.objectify(objects.runtime_config)
|
||||
def runtime_config_get(self, id, host_id=None):
|
||||
query = model_query(models.RuntimeConfig)
|
||||
|
||||
if utils.is_uuid_like(id):
|
||||
query = query.filter_by(config_uuid=id)
|
||||
if host_id:
|
||||
query = query.filter_by(forihostid=host_id)
|
||||
else:
|
||||
query = query.filter_by(id=id)
|
||||
|
||||
try:
|
||||
result = query.one()
|
||||
except NoResultFound:
|
||||
raise exception.NotFound()
|
||||
except MultipleResultsFound:
|
||||
raise exception.MultipleResults()
|
||||
return result
|
||||
|
||||
@db_objects.objectify(objects.runtime_config)
|
||||
def runtime_config_get_all(self, config_uuid=None, state=None, older_than=None):
|
||||
query = model_query(models.RuntimeConfig)
|
||||
if config_uuid:
|
||||
query = query.filter_by(config_uuid=config_uuid)
|
||||
if state:
|
||||
query = query.filter_by(state=state)
|
||||
if older_than:
|
||||
query = query.filter(models.RuntimeConfig.created_at < older_than)
|
||||
return query.all()
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
########################################################################
|
||||
#
|
||||
# Copyright (c) 2023 Wind River Systems, Inc.
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
########################################################################
|
||||
|
||||
from migrate.changeset import UniqueConstraint
|
||||
from sqlalchemy import Integer, String, DateTime
|
||||
from sqlalchemy import Column, MetaData, Table, ForeignKey
|
||||
|
||||
from sysinv.db.sqlalchemy.models import UUID_LENGTH
|
||||
|
||||
ENGINE = 'InnoDB'
|
||||
CHARSET = 'utf8'
|
||||
|
||||
|
||||
def upgrade(migrate_engine):
|
||||
meta = MetaData()
|
||||
meta.bind = migrate_engine
|
||||
|
||||
Table('i_host', meta, autoload=True)
|
||||
|
||||
runtime_config = Table(
|
||||
'runtime_config',
|
||||
meta,
|
||||
Column('created_at', DateTime),
|
||||
Column('updated_at', DateTime),
|
||||
Column('deleted_at', DateTime),
|
||||
Column('id', Integer, primary_key=True, nullable=False),
|
||||
Column('config_uuid', String(UUID_LENGTH), nullable=False),
|
||||
Column('config_dict', String(767)),
|
||||
Column('state', String(255)),
|
||||
Column('forihostid', Integer,
|
||||
ForeignKey('i_host.id', ondelete='CASCADE'), nullable=False),
|
||||
Column('reserved_1', String(255)),
|
||||
UniqueConstraint('config_uuid', 'forihostid', name='u_config_uuid_forihostid'),
|
||||
mysql_engine=ENGINE,
|
||||
mysql_charset=CHARSET,
|
||||
)
|
||||
runtime_config.create()
|
||||
|
||||
|
||||
def downgrade(migrate_engine):
|
||||
meta = MetaData()
|
||||
meta.bind = migrate_engine
|
||||
|
||||
runtime_config = Table('runtime_config', meta, autoload=True)
|
||||
runtime_config.drop()
|
|
@ -2170,3 +2170,24 @@ class KubeCmdVersions(Base):
|
|||
kubelet_version = Column(String(255), nullable=False)
|
||||
UniqueConstraint('kubeadm_version', 'kubelet_version',
|
||||
name='u_kubeadm_version_kubelet_version')
|
||||
|
||||
|
||||
class RuntimeConfig(Base):
|
||||
runtimeConfigStateEnum = Enum(
|
||||
constants.RUNTIME_CONFIG_STATE_PENDING,
|
||||
constants.RUNTIME_CONFIG_STATE_APPLIED,
|
||||
constants.RUNTIME_CONFIG_STATE_FAILED,
|
||||
constants.RUNTIME_CONFIG_STATE_RETRIED,
|
||||
name="runtimeConfigStateEnum"
|
||||
)
|
||||
|
||||
__tablename__ = 'runtime_config'
|
||||
|
||||
id = Column(Integer, primary_key=True)
|
||||
config_uuid = Column(String(UUID_LENGTH), nullable=False)
|
||||
config_dict = Column(String(767), nullable=False)
|
||||
state = Column(runtimeConfigStateEnum, default=constants.RUNTIME_CONFIG_STATE_PENDING)
|
||||
forihostid = Column(Integer, ForeignKey('i_host.id', ondelete='CASCADE'))
|
||||
reserved_1 = Column(String(255))
|
||||
UniqueConstraint('config_uuid', 'forihostid',
|
||||
name='u_config_uuid_forihostid')
|
||||
|
|
|
@ -104,6 +104,7 @@ from sysinv.objects import host_fs
|
|||
from sysinv.objects import restore
|
||||
from sysinv.objects import kube_rootca_update
|
||||
from sysinv.objects import kube_rootca_host_update
|
||||
from sysinv.objects import runtime_config
|
||||
|
||||
|
||||
# alias objects for RPC compatibility
|
||||
|
@ -199,6 +200,7 @@ fpga_device = fpga_device.FPGADevice
|
|||
restore = restore.Restore
|
||||
kube_rootca_host_update = kube_rootca_host_update.KubeRootCAHostUpdate
|
||||
kube_rootca_update = kube_rootca_update.KubeRootCAUpdate
|
||||
runtime_config = runtime_config.RuntimeConfig
|
||||
|
||||
__all__ = ("system",
|
||||
"cluster",
|
||||
|
@ -284,6 +286,7 @@ __all__ = ("system",
|
|||
"restore",
|
||||
"kube_rootca_host_update",
|
||||
"kube_rootca_update",
|
||||
"runtime_config",
|
||||
# alias objects for RPC compatibility
|
||||
"ihost",
|
||||
"ilvg")
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
#
|
||||
# Copyright (c) 2023 Wind River Systems, Inc.
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
# coding=utf-8
|
||||
#
|
||||
|
||||
from sysinv.db import api as db_api
|
||||
from sysinv.objects import base
|
||||
from sysinv.objects import utils
|
||||
|
||||
|
||||
class RuntimeConfig(base.SysinvObject):
|
||||
|
||||
dbapi = db_api.get_instance()
|
||||
|
||||
fields = {
|
||||
'id': int,
|
||||
'config_uuid': utils.str_or_none,
|
||||
'config_dict': utils.str_or_none,
|
||||
'state': utils.str_or_none,
|
||||
'forihostid': utils.int_or_none,
|
||||
'reserved_1': utils.str_or_none,
|
||||
}
|
Loading…
Reference in New Issue