Code Duplication    Length = 17-17 lines in 2 locations

main.py 2 locations

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