1 # Copyright 2016 Intel Corporation.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 """Wrapper for an OVS dpctl (``ovs-dpctl``) for managing datapaths.
23 from tools import tasks
24 from conf import settings
26 _OVS_DPCTL_BIN = os.path.join(settings.getValue('OVS_DIR'), 'utilities',
29 _OVS_LOCAL_DATAPATH = 'ovs-system'
32 """remove/show datapaths using ``ovs-dpctl``.
34 def __init__(self, timeout=10):
37 :param timeout: Timeout to be used for each command
41 self.logger = logging.getLogger(__name__)
42 self.timeout = timeout
46 def run_dpctl(self, args, check_error=False):
47 """Run ``ovs-dpctl`` with supplied arguments.
49 :param args: Arguments to pass to ``ovs-dpctl``
50 :param check_error: Throw exception on error
54 cmd = ['sudo', _OVS_DPCTL_BIN,
56 str(self.timeout)] + args
57 return tasks.run_task(
58 cmd, self.logger, 'Running ovs-dpctl ..', check_error)
62 def del_dp(self, dp_name=_OVS_LOCAL_DATAPATH):
63 """Delete local datapath (ovs-dpctl).
65 :param br_name: Name of bridge
69 self.logger.debug('delete datapath ' + dp_name)
70 self.run_dpctl(['del-dp', dp_name])