From 508f6e90ada58038aa936ce9f342fde8a451d777 Mon Sep 17 00:00:00 2001 From: Roopa Prabhu Date: Fri, 8 Jul 2016 08:13:37 -0700 Subject: [PATCH] ifupdownaddons: iproute2: add bridge_commit_batch api to batch bridge commands Ticket: CM-11274 Testing Done: julien, wkok, nikhil It uses and goes with the the other batch variables and apis. This one just calls the 'bridge -batch' command instead of the 'ip -batch' command. This can be used to batch bridge commands. Signed-off-by: Roopa Prabhu --- ifupdownaddons/iproute2.py | 47 +++++++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 8 deletions(-) diff --git a/ifupdownaddons/iproute2.py b/ifupdownaddons/iproute2.py index 67a63c5..43d4118 100644 --- a/ifupdownaddons/iproute2.py +++ b/ifupdownaddons/iproute2.py @@ -284,6 +284,21 @@ class iproute2(utilsBase): self.ipbatch = False self.ipbatch_pause = False + def bridge_batch_commit(self): + if not self.ipbatchbuf: + self.ipbatchbuf = '' + self.ipbatch = False + self.ipbatch_pause = False + return + try: + utils.exec_command('bridge -force -batch -', stdin=self.ipbatchbuf) + except: + raise + finally: + self.ipbatchbuf = '' + self.ipbatch = False + self.ipbatch_pause = False + def addr_show(self, ifacename=None): if ifacename: if not self.link_exists(ifacename): @@ -724,12 +739,20 @@ class iproute2(utilsBase): return brvlaninfo def bridge_port_pvid_add(self, bridgeportname, pvid): - utils.exec_command('bridge vlan add vid %s untagged pvid dev %s' % - (pvid, bridgeportname)) + if self.ipbatch and not self.ipbatch_pause: + self.add_to_batch('vlan add vid %s untagged pvid dev %s' % + (pvid, bridgeportname)) + else: + utils.exec_command('bridge vlan add vid %s untagged pvid dev %s' % + (pvid, bridgeportname)) def bridge_port_pvid_del(self, bridgeportname, pvid): - utils.exec_command('bridge vlan del vid %s untagged pvid dev %s' % - (pvid, bridgeportname)) + if self.ipbatch and not self.ipbatch_pause: + self.add_to_batch('vlan del vid %s untagged pvid dev %s' % + (pvid, bridgeportname)) + else: + utils.exec_command('bridge vlan del vid %s untagged pvid dev %s' % + (pvid, bridgeportname)) def bridge_port_pvids_get(self, bridgeportname): return self.read_file_oneline('/sys/class/net/%s/brport/pvid' @@ -737,13 +760,21 @@ class iproute2(utilsBase): def bridge_vids_add(self, bridgeportname, vids, bridge=True): target = 'self' if bridge else '' - [utils.exec_command('bridge vlan add vid %s dev %s %s' % - (v, bridgeportname, target)) for v in vids] + if self.ipbatch and not self.ipbatch_pause: + [self.add_to_batch('vlan add vid %s dev %s %s' % + (v, bridgeportname, target)) for v in vids] + else: + [utils.exec_command('bridge vlan add vid %s dev %s %s' % + (v, bridgeportname, target)) for v in vids] def bridge_vids_del(self, bridgeportname, vids, bridge=True): target = 'self' if bridge else '' - [utils.exec_command('bridge vlan del vid %s dev %s %s' % - (v, bridgeportname, target)) for v in vids] + if self.ipbatch and not self.ipbatch_pause: + [self.add_to_batch('vlan del vid %s dev %s %s' % + (v, bridgeportname, target)) for v in vids] + else: + [utils.exec_command('bridge vlan del vid %s dev %s %s' % + (v, bridgeportname, target)) for v in vids] def bridge_fdb_add(self, dev, address, vlan=None, bridge=True, remote=None): target = 'self' if bridge else ''