bd05f693f2
In the config project,"/sysinv/sysinv/sysinv/sysinv/objects/" directory has many files imported into the "log" but not used. At the same time,I built a system of simplex with the latest ISO of the community. When the system was built,the code was changed. The system worked well and the other functional modules were not affected.So I agree we should delete them. Change-Id: I35f35ffdf1b9b00a97c259b47420dee3f1e4d939 Partial-Bug: #1844095 Signed-off-by: Hang Li <lihang0166@fiberhome.com>
106 lines
2.6 KiB
Python
106 lines
2.6 KiB
Python
#
|
|
# Copyright (c) 2017 Wind River Systems, Inc.
|
|
#
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
#
|
|
|
|
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
|
# coding=utf-8
|
|
#
|
|
|
|
from sqlalchemy.orm import exc
|
|
|
|
from sysinv.db import api as db_api
|
|
from sysinv.objects import base
|
|
from sysinv.objects import utils
|
|
|
|
|
|
def get_backend_uuid(field, db_object):
|
|
"""Retrieves backend uuid."""
|
|
|
|
if hasattr(db_object, 'backend_uuid'):
|
|
return db_object['backend_uuid']
|
|
|
|
backend_uuid = None
|
|
try:
|
|
backend = getattr(db_object, 'stor_backend')
|
|
if backend:
|
|
backend_uuid = backend.uuid
|
|
except exc.DetachedInstanceError:
|
|
# No backend associated with the tier
|
|
pass
|
|
|
|
return backend_uuid
|
|
|
|
|
|
def get_cluster_uuid(field, db_object):
|
|
"""Retrieves cluster uuid."""
|
|
|
|
if hasattr(db_object, 'cluster_uuid'):
|
|
return db_object['cluster_uuid']
|
|
|
|
cluster_uuid = None
|
|
try:
|
|
cluster = getattr(db_object, 'cluster')
|
|
if cluster:
|
|
cluster_uuid = cluster.uuid
|
|
except exc.DetachedInstanceError:
|
|
# No cluster associated with the tier
|
|
pass
|
|
|
|
return cluster_uuid
|
|
|
|
|
|
def get_stor_ids(field, db_object):
|
|
"""Retrieves the list of stors associated with the tier."""
|
|
stors = []
|
|
try:
|
|
for entry in getattr(db_object, 'stors', []):
|
|
# Exclude profile OSDs as they don't have and ID and are not active
|
|
# on the tier
|
|
if entry.osdid is not None:
|
|
stors.append(entry.osdid)
|
|
except exc.DetachedInstanceError:
|
|
# No istor assigned to the tier
|
|
pass
|
|
|
|
return stors
|
|
|
|
|
|
class StorageTier(base.SysinvObject):
|
|
# VERSION 1.0: Initial version
|
|
VERSION = '1.0'
|
|
|
|
dbapi = db_api.get_instance()
|
|
|
|
fields = {
|
|
'id': int,
|
|
'uuid': utils.str_or_none,
|
|
|
|
'name': utils.str_or_none,
|
|
'type': utils.str_or_none,
|
|
'status': utils.str_or_none,
|
|
'capabilities': utils.dict_or_none,
|
|
|
|
'forbackendid': utils.int_or_none,
|
|
'backend_uuid': utils.str_or_none,
|
|
|
|
'forclusterid': utils.int_or_none,
|
|
'cluster_uuid': utils.str_or_none,
|
|
'stors': list,
|
|
}
|
|
|
|
_foreign_fields = {
|
|
'backend_uuid': get_backend_uuid,
|
|
'cluster_uuid': get_cluster_uuid,
|
|
'stors': get_stor_ids
|
|
}
|
|
|
|
@base.remotable_classmethod
|
|
def get_by_uuid(cls, context, uuid):
|
|
return cls.dbapi.storage_tier_get(uuid)
|
|
|
|
def save_changes(self, context, updates):
|
|
self.dbapi.storage_tier_update(self.uuid, # pylint: disable=no-member
|
|
updates)
|