Upload the contribution of vstf as bottleneck network framework.
[bottlenecks.git] / vstf / vstf / controller / fabricant.py
diff --git a/vstf/vstf/controller/fabricant.py b/vstf/vstf/controller/fabricant.py
new file mode 100755 (executable)
index 0000000..c67bfa1
--- /dev/null
@@ -0,0 +1,49 @@
+from vstf.rpc_frame_work import constant as const
+import vstf.common.constants as cst
+
+
+class Fabricant(object):
+    def __init__(self, target, conn):
+        self.conn = conn
+        self.target = target
+
+        self.all_commands = self.declare_commands
+        self.instance_commands()
+
+    @property
+    def declare_commands(self):
+        driver = {"install_drivers", "clean_drivers", "autoneg_on", "autoneg_off", "autoneg_query"}
+
+        builder = {"build_env", "clean_env"}
+
+        cpu = {"affctl_load", "affctl_list", "run_cpuwatch", "kill_cpuwatch"}
+
+        perf = {"perf_run", "run_vnstat", "kill_vnstat", "force_clean"}
+
+        device_mgr = {"get_device_detail", "list_nic_devices", "get_device_verbose"}
+
+        netns = {"clean_all_namespace", "config_dev", "recover_dev", "ping"}
+
+        collect = {"collect_host_info"}
+
+        cmdline = {"execute"}
+
+        spirent = {"send_packet", "stop_flow", "mac_learning", "run_rfc2544suite", "run_rfc2544_throughput",
+                   "run_rfc2544_frameloss", "run_rfc2544_latency"}
+
+        equalizer = {"get_numa_core", "get_nic_numa", "get_nic_interrupt_proc", "get_vm_info", "bind_cpu",
+                     "catch_thread_info"}
+
+        return driver | cpu | builder | perf | device_mgr | netns | cmdline | collect | spirent | equalizer
+
+    def instance_commands(self):
+        for command in self.all_commands:
+            setattr(self, command, self.__transfer_msg(command))
+
+    def __transfer_msg(self, command):
+        def infunc(timeout=cst.TIMEOUT, **kwargs):
+            msg = self.conn.make_msg(command, **kwargs)
+            return self.conn.call(msg, self.target, timeout)
+
+        infunc.__name__ = command
+        return infunc