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):
19 def __init__(self, path="/etc/vstf/perf/",
20 filename="sw_perf.flownodes-settings",
21 mode=sets.SETS_SINGLE):
22 self._check_actors = {'namespaces', 'senders', 'receivers', 'watchers'}
23 self._nocheck_actors = {"cpu_listens"}
24 super(FlowsSettings, self).__init__(path, filename, mode)
26 def _register_func(self):
27 super(FlowsSettings, self)._register_func()
28 for actor in self._check_actors:
29 actor = actor.encode()
30 func_name = "add_%s" % actor
40 func_name = "madd_%s" % actor
50 for actor in self._nocheck_actors:
51 actor = actor.encode()
52 func_name = "add_%s" % actor
61 func_name = "madd_%s" % actor
70 LOG.debug(self.__dict__.keys())
73 actors = self._check_actors | self._nocheck_actors
75 func_name = "set_%s" % actor
76 func = getattr(self, func_name)
80 actors = self._check_actors | self._nocheck_actors
82 func_name = "mset_%s" % actor
83 func = getattr(self, func_name)
86 def _check_add(self, value):
87 flows = ['agent', 'dev']
88 if not isinstance(value, dict):
89 raise Exception("type is error: %s" % (str(value)))
91 if flow not in value.keys():
92 raise Exception("keys[%s] is missing: %s" % (flow, str(value)))
94 items = ["ip", "namespace", "mac", "iface", "bdf"]
96 if item not in value['dev'].keys():
97 raise Exception("keys[%s] is error: %s" % (item, str(value)))
101 from vstf.common.log import setup_logging
104 log_file="/var/log/vstf/vstf-flows-settings.log",
107 flows_settings = FlowsSettings()
108 LOG.info(flows_settings.settings)
110 flows_settings.clear_all()
111 flows_settings.set_flows(2)
112 LOG.info(flows_settings.settings)
115 "agent": "192.168.188.14",
117 "ip": "192.168.1.100",
118 "namespace": "vstf-space-1",
119 "mac": "90:e2:ba:20:1f:d8",
125 "agent": "192.168.188.14",
127 "ip": "192.168.1.101",
128 "namespace": "vstf-space-2",
129 "mac": "90:e2:ba:20:1f:d9",
135 flows_settings.add_senders(flow_1)
136 flows_settings.add_senders(flow_2)
137 flows_settings.add_receivers(flow_2)
138 flows_settings.add_receivers(flow_1)
140 flows_settings.add_watchers(flow_1)
141 flows_settings.add_watchers(flow_2)
143 flows_settings.add_namespaces(flow_1)
144 flows_settings.add_namespaces(flow_2)
147 "agent": "192.168.188.16",
152 flows_settings.add_cpu_listens(cpu)
153 LOG.info(flows_settings.settings)
156 if __name__ == '__main__':