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 import vstf.controller.settings.settings as sets
14 LOG = logging.getLogger(__name__)
17 class FlowsSettings(sets.Settings):
18 def __init__(self, path="/etc/vstf/perf/",
19 filename="sw_perf.flownodes-settings",
20 mode=sets.SETS_SINGLE):
21 self._check_actors = {'namespaces', 'senders', 'receivers', 'watchers'}
22 self._nocheck_actors = {"cpu_listens"}
23 super(FlowsSettings, self).__init__(path, filename, mode)
25 def _register_func(self):
26 super(FlowsSettings, self)._register_func()
27 for actor in self._check_actors:
28 actor = actor.encode()
29 func_name = "add_%s" % actor
30 setattr(self, func_name, self._adding_file(func_name, self._mset, self._fset, actor, self._check_add))
31 func_name = "madd_%s" % actor
32 setattr(self, func_name, self._adding_memory(func_name, self._mset, actor, self._check_add))
34 for actor in self._nocheck_actors:
35 actor = actor.encode()
36 func_name = "add_%s" % actor
37 setattr(self, func_name, self._adding_file(func_name, self._mset, self._fset, actor))
38 func_name = "madd_%s" % actor
39 setattr(self, func_name, self._adding_memory(func_name, self._mset, actor))
41 LOG.debug(self.__dict__.keys())
44 actors = self._check_actors | self._nocheck_actors
46 func_name = "set_%s" % actor
47 func = getattr(self, func_name)
51 actors = self._check_actors | self._nocheck_actors
53 func_name = "mset_%s" % actor
54 func = getattr(self, func_name)
57 def _check_add(self, value):
58 flows = ['agent', 'dev']
59 if not isinstance(value, dict):
60 raise Exception("type is error: %s" % (str(value)))
62 if flow not in value.keys():
63 raise Exception("keys[%s] is missing: %s" % (flow, str(value)))
65 items = ["ip", "namespace", "mac", "iface", "bdf"]
67 if item not in value['dev'].keys():
68 raise Exception("keys[%s] is error: %s" % (item, str(value)))
72 from vstf.common.log import setup_logging
73 setup_logging(level=logging.DEBUG, log_file="/var/log/vstf/vstf-flows-settings.log", clevel=logging.INFO)
75 flows_settings = FlowsSettings()
76 LOG.info(flows_settings.settings)
78 flows_settings.clear_all()
79 flows_settings.set_flows(2)
80 LOG.info(flows_settings.settings)
83 "agent": "192.168.188.14",
85 "ip": "192.168.1.100",
86 "namespace": "vstf-space-1",
87 "mac": "90:e2:ba:20:1f:d8",
93 "agent": "192.168.188.14",
95 "ip": "192.168.1.101",
96 "namespace": "vstf-space-2",
97 "mac": "90:e2:ba:20:1f:d9",
103 flows_settings.add_senders(flow_1)
104 flows_settings.add_senders(flow_2)
105 flows_settings.add_receivers(flow_2)
106 flows_settings.add_receivers(flow_1)
108 flows_settings.add_watchers(flow_1)
109 flows_settings.add_watchers(flow_2)
111 flows_settings.add_namespaces(flow_1)
112 flows_settings.add_namespaces(flow_2)
115 "agent": "192.168.188.16",
120 flows_settings.add_cpu_listens(cpu)
121 LOG.info(flows_settings.settings)
124 if __name__ == '__main__':