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):
20 def __init__(self, conn, config_file):
21 LOG.info("welcome to EnvBuilder")
23 intent_parser = IntentParser(config_file)
24 self.cfg_intent = intent_parser.parse_cfg_file()
27 LOG.info("start build")
28 for host_cfg in self.cfg_intent['env-build']:
29 rpc = Fabricant(host_cfg['ip'], self.conn)
30 rpc.build_env(timeout=1800, cfg_intent=host_cfg)
34 for host_cfg in self.cfg_intent['env-build']:
35 rpc = Fabricant(host_cfg['ip'], self.conn)
36 rpc.clean_env(timeout=120)
41 for host_cfg in self.cfg_intent['env-build']:
43 'name': host_cfg['ip'],
44 'nic': "82599ES 10-Gigabit"
50 class TransmitterBuild(object):
51 def __init__(self, conn, config_file):
52 LOG.info("welcome to TransmitterBuild")
54 self._cfg_intent = config_file["transmitter-build"]
57 LOG.info("start build")
58 for cfg in self.cfg_intent:
59 rpc = Fabricant(cfg['ip'], self.conn)
60 cfg.setdefault("scheme", 'transmitter')
61 rpc.build_env(timeout=1800, cfg_intent=cfg)
65 for cfg in self.cfg_intent:
66 rpc = Fabricant(cfg['ip'], self.conn)
67 rpc.clean_env(timeout=10)
71 if __name__ == "__main__":
74 parser = argparse.ArgumentParser()
75 parser.add_argument('--rpc_server', help='rabbitmq server for deliver messages.')
76 parser.add_argument('--config', help='config file to parse')
77 args = parser.parse_args()
78 logging.basicConfig(level=logging.INFO)
79 conn = Server(args.rpc_server)
80 tn = EnvBuildApi(conn, args.config)