Merge "env: validate installer_ip from environment"
[yardstick.git] / yardstick / benchmark / scenarios / lib / get_server_ip.py
1 ##############################################################################
2 # Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
3 #
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
10 from __future__ import print_function
11 from __future__ import absolute_import
12
13 import logging
14
15 from yardstick.benchmark.scenarios import base
16
17 LOG = logging.getLogger(__name__)
18
19
20 class GetServerIp(base.Scenario):
21     """Get a server by name"""
22
23     __scenario_type__ = "GetServerIp"
24
25     def __init__(self, scenario_cfg, context_cfg):
26         self.scenario_cfg = scenario_cfg
27         self.context_cfg = context_cfg
28         self.options = self.scenario_cfg.get('options', {})
29         self.ip_type = self.options.get('ip_type', "floating")
30
31     def run(self, result):
32         server = self.options.get('server', {})
33         ip = next(n['addr'] for k, v in server['addresses'].items()
34                   for n in v if n['OS-EXT-IPS:type'] == self.ip_type)
35
36         keys = self.scenario_cfg.get('output', '').split()
37         values = [ip]
38         return self._push_to_outputs(keys, values)