1 ##############################################################################
2 # Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9 from __future__ import absolute_import
13 import yardstick.common.utils as utils
16 @six.add_metaclass(abc.ABCMeta)
17 class Context(object):
18 """Class that represents a context in the logical model"""
22 Context.list.append(self)
25 def init(self, attrs):
29 def get_cls(context_type):
30 """Return class of specified type."""
31 for context in utils.itersubclasses(Context):
32 if context_type == context.__context_type__:
34 raise RuntimeError("No such context_type %s" % context_type)
37 def get(context_type):
38 """Returns instance of a context for context type.
40 return Context.get_cls(context_type)()
48 """Undeploy context."""
49 self._delete_context()
51 def _delete_context(self):
52 Context.list.remove(self)
55 def _get_server(self, attr_name):
56 """get server info by name from context
60 def get_server(attr_name):
61 """lookup server info by name from context
62 attr_name: either a name for a server created by yardstick or a dict
63 with attribute name mapping when using external heat templates
66 for context in Context.list:
67 server = context._get_server(attr_name)
68 if server is not None:
72 raise ValueError("context not found for server '%r'" %