Tao Liu 7f3827f24d Keystone token and resource caching
Add the following misc. changes to dcorch and dcmanager components:
- Cache the master resource in dcorch audit
- Consolidate the openstack drivers to common module, combine the
  dcmanager and dcorch sysinv client. (Note: the sdk driver that
  used by nova, neutron and cinder will be cleaned as part of
  story 2006588).
- Update the common sdk driver:
  . in order to avoid creating new keystone client multiple times
  . to add a option for caching region clients, in addition to the
    keystone client
  . finally, to randomize the token early renewal duration
- Change subcloud audit manager, patch audit manager,
  and sw update manager to:
  utilize the sdk driver which caches the keystone client and token

Test cases:
1. Manage/unmanage subclouds
2. Platform resources sync and audit
3. Verify the keystone token is cached until the token is
   expired
4. Add/delete subclouds
5. Managed subcloud goes offline/online (power off/on)
6. Managed subcloud goes offline/online (delete/add a static route)
7. Apply a patch to all subclouds via patch Orchestration

Story: 2007267
Task: 38865

Change-Id: I75e0cf66a797a65faf75e7c64dafb07f54c2df06
Signed-off-by: Tao Liu <tao.liu@windriver.com>
2020-03-23 21:31:04 -04:00

159 lines
5.1 KiB
Python

# Copyright 2016 Ericsson AB
# 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.
#
from oslo_log import log
from nfv_client.openstack import sw_update
from dccommon import consts
from dccommon.drivers import base
from dccommon import exceptions
LOG = log.getLogger(__name__)
STRATEGY_NAME_SW_PATCH = 'sw-patch'
STRATEGY_NAME_SW_UPGRADE = 'sw-upgrade'
APPLY_TYPE_SERIAL = 'serial'
APPLY_TYPE_PARALLEL = 'parallel'
APPLY_TYPE_IGNORE = 'ignore'
INSTANCE_ACTION_MIGRATE = 'migrate'
INSTANCE_ACTION_STOP_START = 'stop-start'
ALARM_RESTRICTIONS_STRICT = 'strict'
ALARM_RESTRICTIONS_RELAXED = 'relaxed'
SW_UPDATE_OPTS_CONST_DEFAULT = {
"name": consts.SW_UPDATE_DEFAULT_TITLE,
"storage-apply-type": APPLY_TYPE_PARALLEL,
"worker-apply-type": APPLY_TYPE_PARALLEL,
"max-parallel-workers": 10,
"default-instance-action": INSTANCE_ACTION_MIGRATE,
"alarm-restriction-type": ALARM_RESTRICTIONS_RELAXED,
"created-at": None,
"updated-at": None}
STATE_INITIAL = 'initial'
STATE_BUILDING = 'building'
STATE_BUILD_FAILED = 'build-failed'
STATE_BUILD_TIMEOUT = 'build-timeout'
STATE_READY_TO_APPLY = 'ready-to-apply'
STATE_APPLYING = 'applying'
STATE_APPLY_FAILED = 'apply-failed'
STATE_APPLY_TIMEOUT = 'apply-timeout'
STATE_APPLIED = 'applied'
STATE_ABORTING = 'aborting'
STATE_ABORT_FAILED = 'abort-failed'
STATE_ABORT_TIMEOUT = 'abort-timeout'
STATE_ABORTED = 'aborted'
class VimClient(base.DriverBase):
"""VIM driver."""
def __init__(self, region, session):
try:
# The nfv_client doesn't support a session, so we need to
# get an endpoint and token.
self.endpoint = session.get_endpoint(service_type='nfv',
region_name=region,
interface='internal')
self.token = session.get_token()
except exceptions.ServiceUnavailable:
raise
def create_strategy(self, strategy_name, storage_apply_type,
worker_apply_type, max_parallel_worker_hosts,
default_instance_action, alarm_restrictions):
"""Create orchestration strategy"""
url = self.endpoint
strategy = sw_update.create_strategy(
self.token, url,
strategy_name=strategy_name,
controller_apply_type=APPLY_TYPE_SERIAL,
storage_apply_type=storage_apply_type,
swift_apply_type=APPLY_TYPE_IGNORE,
worker_apply_type=worker_apply_type,
max_parallel_worker_hosts=max_parallel_worker_hosts,
default_instance_action=default_instance_action,
alarm_restrictions=alarm_restrictions)
if not strategy:
raise Exception("Strategy creation failed")
LOG.debug("Strategy created: %s" % strategy)
return strategy
def get_strategy(self, strategy_name):
"""Get the current orchestration strategy"""
url = self.endpoint
strategy = sw_update.get_strategies(
self.token, url,
strategy_name=strategy_name)
if not strategy:
raise Exception("Get strategy failed")
LOG.debug("Strategy: %s" % strategy)
return strategy
def delete_strategy(self, strategy_name):
"""Delete the current orchestration strategy"""
url = self.endpoint
success = sw_update.delete_strategy(
self.token, url,
strategy_name=strategy_name)
if not success:
raise Exception("Delete strategy failed")
LOG.debug("Strategy deleted")
def apply_strategy(self, strategy_name):
"""Apply the current orchestration strategy"""
url = self.endpoint
strategy = sw_update.apply_strategy(
self.token, url,
strategy_name=strategy_name)
if not strategy:
raise Exception("Strategy apply failed")
LOG.debug("Strategy applied: %s" % strategy)
return strategy
def abort_strategy(self, strategy_name):
"""Abort the current orchestration strategy"""
url = self.endpoint
strategy = sw_update.abort_strategy(
self.token, url,
strategy_name=strategy_name,
stage_id=None)
if not strategy:
raise Exception("Strategy abort failed")
LOG.debug("Strategy aborted: %s" % strategy)
return strategy