JIRA: BOTTLENECKS-29
[bottlenecks.git] / vstf / vstf / controller / env_build / env_collect.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 from vstf.rpc_frame_work import rpc_producer
11
12
13 class EnvCollectApi(object):
14     def __init__(self, rb_mq_server):
15         """
16         When use collect, a connection of rabbitmq is needed.
17         """
18         super(EnvCollectApi, self).__init__()
19         if rb_mq_server is None:
20             raise Exception("The connection of rabbitmq is None.")
21         self.conn = rb_mq_server
22
23     def collect_host_info(self, host):
24         msg = self.conn.make_msg("collect_host_info")
25         return self.conn.call(msg, host, timeout=2)
26
27     def get_device_detail(self, host, nic_identity):
28         msg = self.conn.make_msg("get_device_detail", identity=nic_identity)
29         return self.conn.call(msg, host, timeout=2)
30
31     def list_nic_devices(self, host):
32         msg = self.conn.make_msg("list_nic_devices")
33         return self.conn.call(msg, host, timeout=2)
34
35
36 if __name__ == "__main__":
37     conn = rpc_producer.Server("192.168.188.10")
38     c = EnvCollectApi(conn)
39     print c.collect_host_info("local")