Code Duplication    Length = 15-32 lines in 2 locations

models/evc.py 2 locations

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