Code Duplication    Length = 13-31 lines in 2 locations

models.py 2 locations

@@ 745-775 (lines=31) @@
742
743
        return flow_mod
744
745
    def _prepare_push_flow(self, *args):
746
        """Prepare push flow.
747
748
        Arguments:
749
            in_interface(str): Interface input.
750
            out_interface(str): Interface output.
751
            in_vlan(str): Vlan input.
752
            out_vlan(str): Vlan output.
753
754
        Return:
755
            dict: An python dictionary representing a FlowMod
756
757
        """
758
        # assign all arguments
759
        in_interface, out_interface, in_vlan, out_vlan = args
760
761
        flow_mod = self._prepare_flow_mod(in_interface, out_interface)
762
763
        # the service tag must be always pushed
764
        new_action = {"action_type": "set_vlan", "vlan_id": out_vlan}
765
        flow_mod["actions"].insert(0, new_action)
766
767
        new_action = {"action_type": "push_vlan", "tag_type": "s"}
768
        flow_mod["actions"].insert(0, new_action)
769
770
        if in_vlan:
771
            # if in_vlan is set, it must be included in the match
772
            flow_mod['match']['dl_vlan'] = in_vlan
773
            new_action = {"action_type": "pop_vlan"}
774
            flow_mod["actions"].insert(0, new_action)
775
        return flow_mod
776
777
    def _prepare_pop_flow(self, in_interface, out_interface, in_vlan,
778
                          out_vlan):
@@ 777-789 (lines=13) @@
774
            flow_mod["actions"].insert(0, new_action)
775
        return flow_mod
776
777
    def _prepare_pop_flow(self, in_interface, out_interface, in_vlan,
778
                          out_vlan):
779
        """Prepare pop flow."""
780
        flow_mod = self._prepare_flow_mod(in_interface, out_interface)
781
        flow_mod['match']['dl_vlan'] = out_vlan
782
        if in_vlan:
783
            new_action = {'action_type': 'set_vlan', 'vlan_id': in_vlan}
784
            flow_mod['actions'].insert(0, new_action)
785
            new_action = {'action_type': 'push_vlan', 'tag_type': 'c'}
786
            flow_mod['actions'].insert(0, new_action)
787
        new_action = {"action_type": "pop_vlan"}
788
        flow_mod["actions"].insert(0, new_action)
789
        return flow_mod
790
791
792
class LinkProtection(EVCDeploy):