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 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
16 LOG = logging.getLogger(__name__)
19 class EnvBuildApi(object):
21 def __init__(self, conn, config_file):
22 LOG.info("welcome to EnvBuilder")
24 intent_parser = IntentParser(config_file)
25 self.cfg_intent = intent_parser.parse_cfg_file()
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)
35 for host_cfg in self.cfg_intent['env-build']:
36 rpc = Fabricant(host_cfg['ip'], self.conn)
37 rpc.clean_env(timeout=120)
42 for host_cfg in self.cfg_intent['env-build']:
44 'name': host_cfg['ip'],
45 'nic': "82599ES 10-Gigabit"
51 class TransmitterBuild(object):
53 def __init__(self, conn, config_file):
54 LOG.info("welcome to TransmitterBuild")
56 self._cfg_intent = config_file["transmitter-build"]
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)
67 for cfg in self.cfg_intent:
68 rpc = Fabricant(cfg['ip'], self.conn)
69 rpc.clean_env(timeout=10)
73 if __name__ == "__main__":
76 parser = argparse.ArgumentParser()
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)