Code Duplication    Length = 14-32 lines in 2 locations

models.py 2 locations

@@ 764-795 (lines=32) @@
761
762
        return flow_mod
763
764
    def _prepare_push_flow(self, *args, queue_id=None):
765
        """Prepare push flow.
766
767
        Arguments:
768
            in_interface(str): Interface input.
769
            out_interface(str): Interface output.
770
            in_vlan(str): Vlan input.
771
            out_vlan(str): Vlan output.
772
773
        Return:
774
            dict: An python dictionary representing a FlowMod
775
776
        """
777
        # assign all arguments
778
        in_interface, out_interface, in_vlan, out_vlan = args
779
780
        flow_mod = self._prepare_flow_mod(in_interface, out_interface,
781
                                          queue_id)
782
783
        # the service tag must be always pushed
784
        new_action = {"action_type": "set_vlan", "vlan_id": out_vlan}
785
        flow_mod["actions"].insert(0, new_action)
786
787
        new_action = {"action_type": "push_vlan", "tag_type": "s"}
788
        flow_mod["actions"].insert(0, new_action)
789
790
        if in_vlan:
791
            # if in_vlan is set, it must be included in the match
792
            flow_mod['match']['dl_vlan'] = in_vlan
793
            new_action = {"action_type": "pop_vlan"}
794
            flow_mod["actions"].insert(0, new_action)
795
        return flow_mod
796
797
    def _prepare_pop_flow(self, in_interface, out_interface, in_vlan,
798
                          out_vlan, queue_id=None):
@@ 797-810 (lines=14) @@
794
            flow_mod["actions"].insert(0, new_action)
795
        return flow_mod
796
797
    def _prepare_pop_flow(self, in_interface, out_interface, in_vlan,
798
                          out_vlan, queue_id=None):
799
        # pylint: disable=too-many-arguments
800
        """Prepare pop flow."""
801
        flow_mod = self._prepare_flow_mod(in_interface, out_interface,
802
                                          queue_id)
803
        flow_mod['match']['dl_vlan'] = out_vlan
804
        if in_vlan:
805
            new_action = {'action_type': 'set_vlan', 'vlan_id': in_vlan}
806
            flow_mod['actions'].insert(0, new_action)
807
            new_action = {'action_type': 'push_vlan', 'tag_type': 'c'}
808
            flow_mod['actions'].insert(0, new_action)
809
        new_action = {"action_type": "pop_vlan"}
810
        flow_mod["actions"].insert(0, new_action)
811
        return flow_mod
812
813