16
16
17
17
import glob
18
18
import logging
19
- import re
20
- import commands
21
- from django .core .exceptions import ObjectDoesNotExist
19
+
22
20
from django .db .transaction import commit_on_success
23
21
from django .core .exceptions import ObjectDoesNotExist
24
22
25
23
from rest_framework import status
26
- from rest_framework .decorators import api_view
27
24
from rest_framework .decorators import permission_classes
28
25
from rest_framework .permissions import IsAuthenticated
29
26
from rest_framework .response import Response
30
27
from rest_framework .views import APIView
31
- from networkapi .api_rack .permissions import Read , Write
28
+
29
+ from networkapi .api_rack .permissions import Write
32
30
from networkapi .api_rack import facade , exceptions
33
31
from networkapi .api_rack .serializers import RackSerializer , DCSerializer , DCRoomSerializer
34
32
from 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
41
34
from networkapi .system .facade import get_value as get_variable
42
- from networkapi .system .facade import save_variable as save_variable
43
35
from networkapi .system import exceptions as var_exceptions
44
36
45
37
from networkapi .distributedlock import LOCK_EQUIPMENT_DEPLOY_CONFIG_USERSCRIPT
@@ -71,7 +63,7 @@ def post(self, request, *args, **kwargs):
71
63
exceptions .InvalidInputException ) as exception :
72
64
log .exception (exception )
73
65
raise exception
74
- except Exception , e :
66
+ except Exception as e :
75
67
log .exception (e )
76
68
raise api_exceptions .NetworkAPIException (e )
77
69
@@ -93,10 +85,11 @@ def put(self, request, *args, **kwargs):
93
85
data ['rack' ] = rack_serializer .data
94
86
95
87
return Response (data , status = status .HTTP_200_OK )
96
- except Exception , e :
88
+ except Exception as e :
97
89
log .exception (e )
98
90
raise api_exceptions .NetworkAPIException (e )
99
91
92
+ @commit_on_success
100
93
def get (self , user , * args , ** kwargs ):
101
94
"""Handles GET requests to list all Racks"""
102
95
@@ -117,10 +110,11 @@ def get(self, user, *args, **kwargs):
117
110
118
111
return Response (data , status = status .HTTP_200_OK )
119
112
120
- except Exception , e :
113
+ except Exception as e :
121
114
log .exception (e )
122
115
raise api_exceptions .NetworkAPIException (e )
123
116
117
+ @commit_on_success
124
118
def delete (self , user , * args , ** kwargs ):
125
119
"""Handles DELETE requests to list all Racks
126
120
URLs: /api/rack/<rack_id>
@@ -137,7 +131,7 @@ def delete(self, user, *args, **kwargs):
137
131
138
132
return Response (data , status = status .HTTP_200_OK )
139
133
140
- except Exception , e :
134
+ except Exception as e :
141
135
log .exception (e )
142
136
raise api_exceptions .NetworkAPIException (e )
143
137
@@ -182,7 +176,7 @@ def post(self, *args, **kwargs):
182
176
output = deploy_facade .deploy_config_in_equipment_synchronous (rel_filename , equip , lockvar )
183
177
184
178
log .debug ("equipment output: %s" % (output ))
185
- except Exception , e :
179
+ except Exception as e :
186
180
log .exception (e )
187
181
raise exceptions .RackAplError (e )
188
182
# SEPARAR AQUI!
@@ -195,14 +189,14 @@ def post(self, *args, **kwargs):
195
189
196
190
return Response (datas , status = status .HTTP_201_CREATED )
197
191
198
- except exceptions .RackNumberNotFoundError , e :
192
+ except exceptions .RackNumberNotFoundError as e :
199
193
log .exception (e )
200
194
raise exceptions .NetworkAPIException (e )
201
- except var_exceptions .VariableDoesNotExistException , e :
195
+ except var_exceptions .VariableDoesNotExistException as e :
202
196
log .error (e )
203
197
raise api_exceptions .NetworkAPIException (
204
198
'Erro buscando a variável PATH_TO_ADD_CONFIG ou REL_PATH_TO_ADD_CONFIG. Erro: %s' % e )
205
- except Exception , e :
199
+ except Exception as e :
206
200
log .exception (e )
207
201
raise api_exceptions .NetworkAPIException (e )
208
202
@@ -246,7 +240,7 @@ def post(self, request, *args, **kwargs):
246
240
247
241
data = dict ()
248
242
return Response (data , status = status .HTTP_200_OK )
249
- except Exception , e :
243
+ except Exception as e :
250
244
raise api_exceptions .NetworkAPIException (e )
251
245
252
246
@@ -264,7 +258,7 @@ def post(self, request, *args, **kwargs):
264
258
265
259
data = dict ()
266
260
return Response (data , status = status .HTTP_200_OK )
267
- except Exception , e :
261
+ except Exception as e :
268
262
raise api_exceptions .NetworkAPIException (e )
269
263
270
264
@permission_classes ((IsAuthenticated , Write ))
@@ -278,7 +272,7 @@ def delete(self, request, *args, **kwargs):
278
272
279
273
data = dict ()
280
274
return Response (data , status = status .HTTP_200_OK )
281
- except Exception , e :
275
+ except Exception as e :
282
276
raise api_exceptions .NetworkAPIException (e )
283
277
284
278
@@ -300,10 +294,9 @@ def post(self, request, *args, **kwargs):
300
294
301
295
return Response (data , status = status .HTTP_201_CREATED )
302
296
303
- except Exception , e :
297
+ except Exception as e :
304
298
raise api_exceptions .NetworkAPIException (e )
305
299
306
-
307
300
@commit_on_success
308
301
def get (self , request , * args , ** kwargs ):
309
302
try :
@@ -315,7 +308,25 @@ def get(self, request, *args, **kwargs):
315
308
data ['dc' ] = dc
316
309
317
310
return Response (data , status = status .HTTP_200_OK )
318
- except Exception , e :
311
+ except Exception as e :
312
+ raise api_exceptions .NetworkAPIException (e )
313
+
314
+ @commit_on_success
315
+ def delete (self , request , * args , ** kwargs ):
316
+
317
+ try :
318
+ log .info ('Delete DC' )
319
+
320
+ dc_id = kwargs .get ("dc_id" ).split (";" )
321
+
322
+ facade .delete_dc (dc_id )
323
+
324
+ data = dict ()
325
+
326
+ return Response (data , status = status .HTTP_200_OK )
327
+
328
+ except Exception as e :
329
+ log .exception (e )
319
330
raise api_exceptions .NetworkAPIException (e )
320
331
321
332
@@ -336,7 +347,7 @@ def post(self, request, *args, **kwargs):
336
347
data ['dcroom' ] = dcroom_serializer .data
337
348
338
349
return Response (data , status = status .HTTP_201_CREATED )
339
- except Exception , e :
350
+ except Exception as e :
340
351
raise api_exceptions .NetworkAPIException (e )
341
352
342
353
@commit_on_success
@@ -361,10 +372,9 @@ def put(self, request, *args, **kwargs):
361
372
data ['fabric' ] = fabric_serializer .data
362
373
363
374
return Response (data , status = status .HTTP_200_OK )
364
- except Exception , e :
375
+ except Exception as e :
365
376
raise api_exceptions .NetworkAPIException (e )
366
377
367
-
368
378
@commit_on_success
369
379
def get (self , request , * args , ** kwargs ):
370
380
try :
@@ -379,5 +389,23 @@ def get(self, request, *args, **kwargs):
379
389
data ['fabric' ] = fabric
380
390
381
391
return Response (data , status = status .HTTP_200_OK )
382
- except Exception , e :
383
- raise api_exceptions .NetworkAPIException (e )
392
+ except Exception as e :
393
+ raise api_exceptions .NetworkAPIException (e )
394
+
395
+ @commit_on_success
396
+ def delete (self , request , * args , ** kwargs ):
397
+
398
+ try :
399
+ log .info ('Delete Fabric' )
400
+
401
+ fabric_id = kwargs .get ("fabric_id" ).split (";" )
402
+
403
+ facade .delete_dcrooms (fabric_id )
404
+
405
+ data = dict ()
406
+
407
+ return Response (data , status = status .HTTP_200_OK )
408
+
409
+ except Exception as e :
410
+ log .exception (e )
411
+ raise api_exceptions .NetworkAPIException (e )
0 commit comments