Code Duplication    Length = 17-17 lines in 2 locations

main.py 2 locations

@@ 170-186 (lines=17) @@
167
168
        return jsonify("Operation successful"), 201
169
170
    @rest('v3/interfaces/<interface_id>/disable', methods=['POST'])
171
    def disable_interface(self, interface_id):
172
        """Administratively disable an interface in the topology."""
173
        switch_id = ":".join(interface_id.split(":")[:-1])
174
        interface_number = int(interface_id.split(":")[-1])
175
176
        try:
177
            switch = self.controller.switches[switch_id]
178
        except KeyError:
179
            return jsonify("Switch not found"), 404
180
181
        try:
182
            switch.interfaces[interface_number].disable()
183
        except KeyError:
184
            return jsonify("Interface not found"), 404
185
186
        return jsonify("Operation successful"), 201
187
188
    @rest('v3/interfaces/<interface_id>/metadata')
189
    def get_interface_metadata(self, interface_id):
@@ 152-168 (lines=17) @@
149
150
        return jsonify({'interfaces': interfaces})
151
152
    @rest('v3/interfaces/<interface_id>/enable', methods=['POST'])
153
    def enable_interface(self, interface_id):
154
        """Administratively enable an interface in the topology."""
155
        switch_id = ":".join(interface_id.split(":")[:-1])
156
        interface_number = int(interface_id.split(":")[-1])
157
158
        try:
159
            switch = self.controller.switches[switch_id]
160
        except KeyError:
161
            return jsonify("Switch not found"), 404
162
163
        try:
164
            switch.interfaces[interface_number].enable()
165
        except KeyError:
166
            return jsonify("Interface not found"), 404
167
168
        return jsonify("Operation successful"), 201
169
170
    @rest('v3/interfaces/<interface_id>/disable', methods=['POST'])
171
    def disable_interface(self, interface_id):