1616
1717import glob
1818import logging
19- import re
20- import commands
21- from django .core .exceptions import ObjectDoesNotExist
19+
2220from django .db .transaction import commit_on_success
2321from django .core .exceptions import ObjectDoesNotExist
2422
2523from rest_framework import status
26- from rest_framework .decorators import api_view
2724from rest_framework .decorators import permission_classes
2825from rest_framework .permissions import IsAuthenticated
2926from rest_framework .response import Response
3027from rest_framework .views import APIView
31- from networkapi .api_rack .permissions import Read , Write
28+
29+ from networkapi .api_rack .permissions import Write
3230from networkapi .api_rack import facade , exceptions
3331from networkapi .api_rack .serializers import RackSerializer , DCSerializer , DCRoomSerializer
3432from networkapi .api_rest import exceptions as api_exceptions
35- from networkapi .equipamento .models import Equipamento , EquipamentoAmbiente
36- from networkapi .ip .models import Ip
37- from networkapi .ip .models import IpEquipamento
38- from networkapi .rack .models import Rack , Datacenter , DatacenterRooms
39- from networkapi .rest import RestResource
40- from networkapi .rest import UserNotAuthorizedError
33+ from networkapi .equipamento .models import Equipamento
4134from networkapi .system .facade import get_value as get_variable
42- from networkapi .system .facade import save_variable as save_variable
4335from networkapi .system import exceptions as var_exceptions
4436
4537from networkapi .distributedlock import LOCK_EQUIPMENT_DEPLOY_CONFIG_USERSCRIPT
@@ -71,7 +63,7 @@ def post(self, request, *args, **kwargs):
7163 exceptions .InvalidInputException ) as exception :
7264 log .exception (exception )
7365 raise exception
74- except Exception , e :
66+ except Exception as e :
7567 log .exception (e )
7668 raise api_exceptions .NetworkAPIException (e )
7769
@@ -93,10 +85,11 @@ def put(self, request, *args, **kwargs):
9385 data ['rack' ] = rack_serializer .data
9486
9587 return Response (data , status = status .HTTP_200_OK )
96- except Exception , e :
88+ except Exception as e :
9789 log .exception (e )
9890 raise api_exceptions .NetworkAPIException (e )
9991
92+ @commit_on_success
10093 def get (self , user , * args , ** kwargs ):
10194 """Handles GET requests to list all Racks"""
10295
@@ -117,10 +110,11 @@ def get(self, user, *args, **kwargs):
117110
118111 return Response (data , status = status .HTTP_200_OK )
119112
120- except Exception , e :
113+ except Exception as e :
121114 log .exception (e )
122115 raise api_exceptions .NetworkAPIException (e )
123116
117+ @commit_on_success
124118 def delete (self , user , * args , ** kwargs ):
125119 """Handles DELETE requests to list all Racks
126120 URLs: /api/rack/<rack_id>
@@ -137,7 +131,7 @@ def delete(self, user, *args, **kwargs):
137131
138132 return Response (data , status = status .HTTP_200_OK )
139133
140- except Exception , e :
134+ except Exception as e :
141135 log .exception (e )
142136 raise api_exceptions .NetworkAPIException (e )
143137
@@ -182,7 +176,7 @@ def post(self, *args, **kwargs):
182176 output = deploy_facade .deploy_config_in_equipment_synchronous (rel_filename , equip , lockvar )
183177
184178 log .debug ("equipment output: %s" % (output ))
185- except Exception , e :
179+ except Exception as e :
186180 log .exception (e )
187181 raise exceptions .RackAplError (e )
188182
@@ -197,14 +191,14 @@ def post(self, *args, **kwargs):
197191
198192 return Response (datas , status = status .HTTP_201_CREATED )
199193
200- except exceptions .RackNumberNotFoundError , e :
194+ except exceptions .RackNumberNotFoundError as e :
201195 log .exception (e )
202196 raise exceptions .NetworkAPIException (e )
203- except var_exceptions .VariableDoesNotExistException , e :
197+ except var_exceptions .VariableDoesNotExistException as e :
204198 log .error (e )
205199 raise api_exceptions .NetworkAPIException (
206200 'Erro buscando a variável PATH_TO_ADD_CONFIG ou REL_PATH_TO_ADD_CONFIG. Erro: %s' % e )
207- except Exception , e :
201+ except Exception as e :
208202 log .exception (e )
209203 raise api_exceptions .NetworkAPIException (e )
210204
@@ -221,7 +215,7 @@ def post(self, request, *args, **kwargs):
221215
222216 data = dict ()
223217 return Response (data , status = status .HTTP_200_OK )
224- except Exception , e :
218+ except Exception as e :
225219 raise api_exceptions .NetworkAPIException (e )
226220
227221
@@ -239,7 +233,7 @@ def post(self, request, *args, **kwargs):
239233
240234 data = dict ()
241235 return Response (data , status = status .HTTP_200_OK )
242- except Exception , e :
236+ except Exception as e :
243237 raise api_exceptions .NetworkAPIException (e )
244238
245239 @permission_classes ((IsAuthenticated , Write ))
@@ -253,7 +247,7 @@ def delete(self, request, *args, **kwargs):
253247
254248 data = dict ()
255249 return Response (data , status = status .HTTP_200_OK )
256- except Exception , e :
250+ except Exception as e :
257251 raise api_exceptions .NetworkAPIException (e )
258252
259253
@@ -275,10 +269,9 @@ def post(self, request, *args, **kwargs):
275269
276270 return Response (data , status = status .HTTP_201_CREATED )
277271
278- except Exception , e :
272+ except Exception as e :
279273 raise api_exceptions .NetworkAPIException (e )
280274
281-
282275 @commit_on_success
283276 def get (self , request , * args , ** kwargs ):
284277 try :
@@ -290,7 +283,25 @@ def get(self, request, *args, **kwargs):
290283 data ['dc' ] = dc
291284
292285 return Response (data , status = status .HTTP_200_OK )
293- except Exception , e :
286+ except Exception as e :
287+ raise api_exceptions .NetworkAPIException (e )
288+
289+ @commit_on_success
290+ def delete (self , request , * args , ** kwargs ):
291+
292+ try :
293+ log .info ('Delete DC' )
294+
295+ dc_id = kwargs .get ("dc_id" ).split (";" )
296+
297+ facade .delete_dc (dc_id )
298+
299+ data = dict ()
300+
301+ return Response (data , status = status .HTTP_200_OK )
302+
303+ except Exception as e :
304+ log .exception (e )
294305 raise api_exceptions .NetworkAPIException (e )
295306
296307
@@ -311,7 +322,7 @@ def post(self, request, *args, **kwargs):
311322 data ['dcroom' ] = dcroom_serializer .data
312323
313324 return Response (data , status = status .HTTP_201_CREATED )
314- except Exception , e :
325+ except Exception as e :
315326 raise api_exceptions .NetworkAPIException (e )
316327
317328 @commit_on_success
@@ -336,10 +347,9 @@ def put(self, request, *args, **kwargs):
336347 data ['fabric' ] = fabric_serializer .data
337348
338349 return Response (data , status = status .HTTP_200_OK )
339- except Exception , e :
350+ except Exception as e :
340351 raise api_exceptions .NetworkAPIException (e )
341352
342-
343353 @commit_on_success
344354 def get (self , request , * args , ** kwargs ):
345355 try :
@@ -354,5 +364,23 @@ def get(self, request, *args, **kwargs):
354364 data ['fabric' ] = fabric
355365
356366 return Response (data , status = status .HTTP_200_OK )
357- except Exception , e :
358- raise api_exceptions .NetworkAPIException (e )
367+ except Exception as e :
368+ raise api_exceptions .NetworkAPIException (e )
369+
370+ @commit_on_success
371+ def delete (self , request , * args , ** kwargs ):
372+
373+ try :
374+ log .info ('Delete Fabric' )
375+
376+ fabric_id = kwargs .get ("fabric_id" ).split (";" )
377+
378+ facade .delete_dcrooms (fabric_id )
379+
380+ data = dict ()
381+
382+ return Response (data , status = status .HTTP_200_OK )
383+
384+ except Exception as e :
385+ log .exception (e )
386+ raise api_exceptions .NetworkAPIException (e )
0 commit comments