Files
watcher/watcher/decision_engine/strategy/context/default.py
Michael Gugino 52ffc2c8e2 Implement goal_id, strategy_id and host_aggregate into Audit api
Modifying the api controller for audit objects to allow
creation of audit objects by specifying either an
audit_template uuid/id and/or a goal_id.

strategy_id is optional.

Partially Implements: blueprint persistent-audit-parameters
Change-Id: I7b3eae4d0752a11208f5f92ee13ab1018d8521ad
2016-07-28 20:12:52 -04:00

69 lines
2.4 KiB
Python

# -*- encoding: utf-8 -*-
# Copyright (c) 2015 b<>com
#
# 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.
from oslo_log import log
from watcher.common import clients
from watcher.common import utils
from watcher.decision_engine.strategy.context import base
from watcher.decision_engine.strategy.selection import default
from watcher import objects
LOG = log.getLogger(__name__)
class DefaultStrategyContext(base.BaseStrategyContext):
def __init__(self):
super(DefaultStrategyContext, self).__init__()
LOG.debug("Initializing Strategy Context")
def execute_strategy(self, audit_uuid, request_context):
audit = objects.Audit.get_by_uuid(request_context, audit_uuid)
osc = clients.OpenStackClients()
# todo(jed) retrieve in audit parameters (threshold,...)
# todo(jed) create ActionPlan
goal = objects.Goal.get_by_id(request_context, audit.goal_id)
# NOTE(jed56) In the audit object, the 'strategy_id' attribute
# is optional. If the admin wants to force the trigger of a Strategy
# it could specify the Strategy uuid in the Audit.
strategy_name = None
if audit.strategy_id:
strategy = objects.Strategy.get_by_id(request_context,
audit.strategy_id)
strategy_name = strategy.name
strategy_selector = default.DefaultStrategySelector(
goal_name=goal.name,
strategy_name=strategy_name,
osc=osc)
selected_strategy = strategy_selector.select()
schema = selected_strategy.get_schema()
if not audit.parameters and schema:
# Default value feedback if no predefined strategy
utils.DefaultValidatingDraft4Validator(schema).validate(
audit.parameters)
selected_strategy.input_parameters.update({
name: value for name, value in audit.parameters.items()
})
return selected_strategy.execute()