Code Duplication    Length = 17-17 lines in 2 locations

main.py 2 locations

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