Files
distcloud/distributedcloud/dcmanager/db/sqlalchemy/models.py
John Kung 1012dd2896 Implement the state for Simplex Upgrade
The Simplex Upgrade step upgrades the simplex subcloud to the load
imported in dc-vault corresponding to the target software release.

Required static data is captured at subcloud add and referenced for
the simplex upgrade.

Dynamic data is retrieved from the online subcloud; including the
bmc credentials which are obtained via a synchronized service within
project allowing for access to the bmc credentials.

BMC password retrieval endpoint_cache integration
with https://review.opendev.org/#/c/736004/

Tests Performed:
- Subcloud upgrade (install) with load corresponding
  to System Controller
- Subcloud add persists install data
- Simplex upgrade persists dynamic upgrade data from start of
  upgrade simplex
- Obtain bmc password from online subcloud
- Obtain bmc password from install data, in case the
  bmc is not configured

Pending for subsequent commit:
- tox unit tests

Change-Id: Ie047139280a5780bfe47b9f9959f4c6781d6f3fa
Story: 2007403
Task: 40024
Signed-off-by: John Kung <john.kung@windriver.com>
2020-06-19 17:09:07 -04:00

205 lines
6.8 KiB
Python

# Copyright (c) 2015 Ericsson AB
# 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.
#
# Copyright (c) 2017-2020 Wind River Systems, Inc.
#
# The right to copy, distribute, modify, or otherwise make use
# of this software may be licensed only pursuant to the terms
# of an applicable Wind River license agreement.
#
"""
SQLAlchemy models for dcmanager data.
"""
from oslo_db.sqlalchemy import models
from sqlalchemy.orm import backref, relationship
from sqlalchemy.orm import session as orm_session
from sqlalchemy import (Column, Integer, String, Boolean, DateTime)
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import ForeignKey
# from dcmanager.common import consts
BASE = declarative_base()
def get_session():
from dcmanager.db.sqlalchemy import api as db_api
return db_api.get_session()
class DCManagerBase(models.ModelBase,
models.SoftDeleteMixin,
models.TimestampMixin):
"""Base class for DC Manager Models."""
# __table_args__ = {'mysql_engine': 'InnoDB'}
def expire(self, session=None, attrs=None):
if not session:
session = orm_session.Session.object_session(self)
if not session:
session = get_session()
session.expire(self, attrs)
def refresh(self, session=None, attrs=None):
"""Refresh this object."""
if not session:
session = orm_session.Session.object_session(self)
if not session:
session = get_session()
session.refresh(self, attrs)
def delete(self, session=None):
"""Delete this object."""
if not session:
session = orm_session.Session.object_session(self)
if not session:
session = get_session()
session.begin()
session.delete(self)
session.commit()
class SubcloudGroup(BASE, DCManagerBase):
"""Represents a subcloud group"""
__tablename__ = 'subcloud_group'
id = Column(Integer, primary_key=True, autoincrement=True, nullable=False)
name = Column(String(255), unique=True)
description = Column(String(255))
update_apply_type = Column(String(255))
max_parallel_subclouds = Column(Integer)
class Subcloud(BASE, DCManagerBase):
"""Represents a subcloud"""
__tablename__ = 'subclouds'
id = Column(Integer, primary_key=True, nullable=False)
name = Column(String(255), unique=True)
description = Column(String(255))
location = Column(String(255))
software_version = Column(String(255))
management_state = Column(String(255))
availability_status = Column(String(255))
data_install = Column(String())
deploy_status = Column(String(255))
data_upgrade = Column(String())
management_subnet = Column(String(255))
management_gateway_ip = Column(String(255))
management_start_ip = Column(String(255), unique=True)
management_end_ip = Column(String(255), unique=True)
openstack_installed = Column(Boolean, nullable=False, default=False)
systemcontroller_gateway_ip = Column(String(255))
audit_fail_count = Column(Integer)
# multiple subclouds can be in a particular group
group_id = Column(Integer,
ForeignKey('subcloud_group.id'))
group = relationship(SubcloudGroup,
backref=backref('subcloud'))
class SubcloudStatus(BASE, DCManagerBase):
"""Represents the status of an endpoint in a subcloud"""
__tablename__ = "subcloud_status"
id = Column(Integer, primary_key=True, nullable=False)
subcloud_id = Column(Integer,
ForeignKey('subclouds.id', ondelete='CASCADE'))
endpoint_type = Column(String(255))
sync_status = Column(String(255))
class SwUpdateStrategy(BASE, DCManagerBase):
"""Represents a software update for subclouds"""
__tablename__ = "sw_update_strategy"
id = Column(Integer, primary_key=True, nullable=False)
type = Column(String(255), unique=True)
subcloud_apply_type = Column(String(255))
max_parallel_subclouds = Column(Integer)
stop_on_failure = Column(Boolean)
state = Column(String(255))
class SwUpdateOpts(BASE, DCManagerBase):
"""Represents software update options for a subcloud"""
__tablename__ = "sw_update_opts"
id = Column(Integer, primary_key=True, nullable=False)
subcloud_id = Column(Integer,
ForeignKey('subclouds.id', ondelete='CASCADE'))
storage_apply_type = Column(String(255))
worker_apply_type = Column(String(255))
max_parallel_workers = Column(Integer)
alarm_restriction_type = Column(String(255))
default_instance_action = Column(String(255))
class SwUpdateOptsDefault(BASE, DCManagerBase):
"""Represents default software update options for subclouds"""
__tablename__ = "sw_update_opts_default"
id = Column(Integer, primary_key=True, nullable=False)
subcloud_id = Column(Integer)
storage_apply_type = Column(String(255))
worker_apply_type = Column(String(255))
max_parallel_workers = Column(Integer)
alarm_restriction_type = Column(String(255))
default_instance_action = Column(String(255))
class StrategyStep(BASE, DCManagerBase):
"""Represents a step for patching or upgrading subclouds"""
__tablename__ = "strategy_steps"
id = Column(Integer, primary_key=True, nullable=False)
subcloud_id = Column(Integer,
ForeignKey('subclouds.id', ondelete='CASCADE'),
unique=True)
stage = Column(Integer)
state = Column(String(255))
details = Column(String(255))
started_at = Column(DateTime)
finished_at = Column(DateTime)
subcloud = relationship('Subcloud', backref=backref("strategy_steps",
cascade="all,delete"))
class SubcloudAlarmSummary(BASE, DCManagerBase):
"""Represents a Distributed Cloud subcloud alarm aggregate"""
__tablename__ = 'subcloud_alarms'
id = Column(Integer, primary_key=True, nullable=False, autoincrement=True)
uuid = Column(String(36), unique=True)
name = Column('name', String(255), unique=True)
critical_alarms = Column('critical_alarms', Integer)
major_alarms = Column('major_alarms', Integer)
minor_alarms = Column('minor_alarms', Integer)
warnings = Column('warnings', Integer)
cloud_status = Column('cloud_status', String(64))