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_LOCAL_DATAPATH = 'ovs-system'
29 """remove/show datapaths using ``ovs-dpctl``.
31 def __init__(self, timeout=10):
34 :param timeout: Timeout to be used for each command
38 self.logger = logging.getLogger(__name__)
39 self.timeout = timeout
43 def run_dpctl(self, args, check_error=False):
44 """Run ``ovs-dpctl`` with supplied arguments.
46 :param args: Arguments to pass to ``ovs-dpctl``
47 :param check_error: Throw exception on error
51 cmd = ['sudo', settings.getValue('TOOLS')['ovs-dpctl'],
53 str(self.timeout)] + args
54 return tasks.run_task(
55 cmd, self.logger, 'Running ovs-dpctl ..', check_error)
59 def del_dp(self, dp_name=_OVS_LOCAL_DATAPATH):
60 """Delete local datapath (ovs-dpctl).
62 :param br_name: Name of bridge
66 self.logger.debug('delete datapath ' + dp_name)
67 self.run_dpctl(['del-dp', dp_name])