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 ##############################################################################
12 import yardstick.common.utils as utils
15 @six.add_metaclass(abc.ABCMeta)
16 class Context(object):
17 '''Class that represents a context in the logical model'''
21 Context.list.append(self)
24 def init(self, attrs):
28 def get_cls(context_type):
29 '''Return class of specified type.'''
30 for context in utils.itersubclasses(Context):
31 if context_type == context.__context_type__:
33 raise RuntimeError("No such context_type %s" % context_type)
36 def get(context_type):
37 """Returns instance of a context for context type.
39 return Context.get_cls(context_type)()
47 '''Undeploy context.'''
50 def _get_server(self, attr_name):
51 '''get server info by name from context
55 def get_server(attr_name):
56 '''lookup server info by name from context
57 attr_name: either a name for a server created by yardstick or a dict
58 with attribute name mapping when using external heat templates
61 for context in Context.list:
62 server = context._get_server(attr_name)
63 if server is not None:
67 raise ValueError("context not found for server '%r'" %