Code Duplication    Length = 14-32 lines in 2 locations

models.py 2 locations

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