Merge "Change PTL informatin in INFO"
[bottlenecks.git] / testsuites / vstf / vstf_scripts / vstf / controller / env_build / env_build.py
1 ##############################################################################
2 # Copyright (c) 2015 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 import logging
11
12 from vstf.controller.fabricant import Fabricant
13 from vstf.rpc_frame_work.rpc_producer import Server
14 from vstf.controller.env_build.cfg_intent_parse import IntentParser
15
16 LOG = logging.getLogger(__name__)
17
18
19 class EnvBuildApi(object):
20
21     def __init__(self, conn, config_file):
22         LOG.info("welcome to EnvBuilder")
23         self.conn = conn
24         intent_parser = IntentParser(config_file)
25         self.cfg_intent = intent_parser.parse_cfg_file()
26
27     def build(self):
28         LOG.info("start build")
29         for host_cfg in self.cfg_intent['env-build']:
30             rpc = Fabricant(host_cfg['ip'], self.conn)
31             rpc.build_env(timeout=1800, cfg_intent=host_cfg)
32         return True
33
34     def clean(self):
35         for host_cfg in self.cfg_intent['env-build']:
36             rpc = Fabricant(host_cfg['ip'], self.conn)
37             rpc.clean_env(timeout=120)
38         return True
39
40     def get_hosts(self):
41         result = []
42         for host_cfg in self.cfg_intent['env-build']:
43             host = {
44                 'name': host_cfg['ip'],
45                 'nic': "82599ES 10-Gigabit"
46             }
47             result.append(host)
48         return result
49
50
51 class TransmitterBuild(object):
52
53     def __init__(self, conn, config_file):
54         LOG.info("welcome to TransmitterBuild")
55         self.conn = conn
56         self._cfg_intent = config_file["transmitter-build"]
57
58     def build(self):
59         LOG.info("start build")
60         for cfg in self.cfg_intent:
61             rpc = Fabricant(cfg['ip'], self.conn)
62             cfg.setdefault("scheme", 'transmitter')
63             rpc.build_env(timeout=1800, cfg_intent=cfg)
64         return True
65
66     def clean(self):
67         for cfg in self.cfg_intent:
68             rpc = Fabricant(cfg['ip'], self.conn)
69             rpc.clean_env(timeout=10)
70         return True
71
72
73 if __name__ == "__main__":
74     import argparse
75
76     parser = argparse.ArgumentParser()
77     parser.add_argument(
78         '--rpc_server',
79         help='rabbitmq server for deliver messages.')
80     parser.add_argument('--config', help='config file to parse')
81     args = parser.parse_args()
82     logging.basicConfig(level=logging.INFO)
83     conn = Server(args.rpc_server)
84     tn = EnvBuildApi(conn, args.config)
85     tn.build()