Skip to content

Commit 04b503a

Browse files
author
Laura
authored
Merge pull request #272 from laurapanzariello/master
merge develop
2 parents 24d7c23 + 8046e75 commit 04b503a

File tree

11 files changed

+162
-84
lines changed

11 files changed

+162
-84
lines changed

networkapi/ambiente/models.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1950,14 +1950,21 @@ def check_duplicated_cidr(self, environment, network):
19501950
:return:
19511951
"""
19521952

1953-
if environment.father_environment:
1954-
id_env_father = environment.father_environment.id
1955-
environments = EnvCIDR.objects.filter(network=network).exclude(id_env=id_env_father)
1956-
else:
1957-
environments = EnvCIDR.objects.filter(network=network)
1953+
ids = self.get_parent_env(environment, [])
1954+
log.debug("fathers: %s" % ids)
1955+
environments = EnvCIDR.objects.filter(network=network).exclude(id_env__in=ids)
1956+
log.debug("duplicated envs: %s" % environments)
19581957

19591958
return environments
19601959

1960+
def get_parent_env(self, environment, ids=[]):
1961+
log.debug("env: %s" % environment.id)
1962+
if environment.father_environment:
1963+
ids.append(environment.father_environment.id)
1964+
return self.get_parent_env(environment.father_environment, ids)
1965+
else:
1966+
return ids
1967+
19611968
def searchNextAvailableCIDR(self, subnets, network_mask=None):
19621969
"""
19631970
Method that search next availacle cidr.

networkapi/api_rack/facade.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@
3434
from networkapi.ip.models import IpEquipamento
3535
from networkapi.rack.models import Rack, Datacenter, DatacenterRooms, RackConfigError
3636
from networkapi.api_rack import serializers as rack_serializers
37-
from networkapi.api_rack import exceptions, autoprovision
37+
from networkapi.api_rack import exceptions
3838
from networkapi.api_rack import provision
3939
from networkapi.system import exceptions as var_exceptions
4040
from networkapi.system.facade import get_value as get_variable
41-
from networkapi.api_rest.exceptions import ValidationAPIException, ObjectDoesNotExistException, NetworkAPIException
41+
from networkapi.api_rest.exceptions import ValidationAPIException, ObjectDoesNotExistException, \
42+
NetworkAPIException
4243
from networkapi.api_network.facade.v3 import networkv4 as facade_redev4_v3
4344

4445
if int(get_variable('use_foreman')):
@@ -76,6 +77,12 @@ def listdc():
7677
return dc_sorted
7778

7879

80+
def delete_dc(dcs):
81+
for dc_id in dcs:
82+
dcroom_obj = Datacenter().get_dc(idt=dc_id)
83+
dcroom_obj.del_dc()
84+
85+
7986
def save_dcrooms(dcrooms_dict):
8087

8188
dcrooms = DatacenterRooms()
@@ -110,6 +117,13 @@ def edit_dcrooms(dcroom_id, dcrooms_dict):
110117
return dcrooms
111118

112119

120+
def delete_dcrooms(dcrooms):
121+
122+
for dcroom_id in dcrooms:
123+
dcroom_obj = DatacenterRooms().get_dcrooms(idt=dcroom_id)
124+
dcroom_obj.del_dcrooms()
125+
126+
113127
def get_fabric(idt=None, name=None, id_dc=None):
114128

115129
fabric_list = list()
@@ -395,7 +409,6 @@ def gerar_arquivo_config(ids):
395409
auto.spine_provision(rack, equips)
396410
auto.oob_provision(rack, equips)
397411

398-
399412
return True
400413

401414

networkapi/api_rack/urls.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
url(r'^rack/list/all/$', rack_views.RackView.as_view()),
2222
url(r'^rack/next/', rack_facade.available_rack_number),
2323

24+
url(r'^dc/(?P<dc_id>\d+)/$', rack_views.DataCenterView.as_view()),
2425
url(r'^dc/$', rack_views.DataCenterView.as_view()),
26+
url(r'^dcrooms/(?P<fabric_id>\d+)/$', rack_views.FabricView.as_view()),
2527
url(r'^dcrooms/$', rack_views.FabricView.as_view()),
2628
url(r'^dcrooms/id/(?P<fabric_id>\d+)/$', rack_views.FabricView.as_view()),
2729
url(r'^dcrooms/name/(?P<fabric_name>\s+)/$', rack_views.FabricView.as_view()),

networkapi/api_rack/views.py

Lines changed: 59 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,22 @@
1616

1717
import glob
1818
import logging
19-
import re
20-
import commands
21-
from django.core.exceptions import ObjectDoesNotExist
19+
2220
from django.db.transaction import commit_on_success
2321
from django.core.exceptions import ObjectDoesNotExist
2422

2523
from rest_framework import status
26-
from rest_framework.decorators import api_view
2724
from rest_framework.decorators import permission_classes
2825
from rest_framework.permissions import IsAuthenticated
2926
from rest_framework.response import Response
3027
from rest_framework.views import APIView
31-
from networkapi.api_rack.permissions import Read, Write
28+
29+
from networkapi.api_rack.permissions import Write
3230
from networkapi.api_rack import facade, exceptions
3331
from networkapi.api_rack.serializers import RackSerializer, DCSerializer, DCRoomSerializer
3432
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
4134
from networkapi.system.facade import get_value as get_variable
42-
from networkapi.system.facade import save_variable as save_variable
4335
from networkapi.system import exceptions as var_exceptions
4436

4537
from 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
# SEPARAR AQUI!
@@ -195,14 +189,14 @@ def post(self, *args, **kwargs):
195189

196190
return Response(datas, status=status.HTTP_201_CREATED)
197191

198-
except exceptions.RackNumberNotFoundError, e:
192+
except exceptions.RackNumberNotFoundError as e:
199193
log.exception(e)
200194
raise exceptions.NetworkAPIException(e)
201-
except var_exceptions.VariableDoesNotExistException, e:
195+
except var_exceptions.VariableDoesNotExistException as e:
202196
log.error(e)
203197
raise api_exceptions.NetworkAPIException(
204198
'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:
206200
log.exception(e)
207201
raise api_exceptions.NetworkAPIException(e)
208202

@@ -246,7 +240,7 @@ def post(self, request, *args, **kwargs):
246240

247241
data = dict()
248242
return Response(data, status=status.HTTP_200_OK)
249-
except Exception, e:
243+
except Exception as e:
250244
raise api_exceptions.NetworkAPIException(e)
251245

252246

@@ -264,7 +258,7 @@ def post(self, request, *args, **kwargs):
264258

265259
data = dict()
266260
return Response(data, status=status.HTTP_200_OK)
267-
except Exception, e:
261+
except Exception as e:
268262
raise api_exceptions.NetworkAPIException(e)
269263

270264
@permission_classes((IsAuthenticated, Write))
@@ -278,7 +272,7 @@ def delete(self, request, *args, **kwargs):
278272

279273
data = dict()
280274
return Response(data, status=status.HTTP_200_OK)
281-
except Exception, e:
275+
except Exception as e:
282276
raise api_exceptions.NetworkAPIException(e)
283277

284278

@@ -300,10 +294,9 @@ def post(self, request, *args, **kwargs):
300294

301295
return Response(data, status=status.HTTP_201_CREATED)
302296

303-
except Exception, e:
297+
except Exception as e:
304298
raise api_exceptions.NetworkAPIException(e)
305299

306-
307300
@commit_on_success
308301
def get(self, request, *args, **kwargs):
309302
try:
@@ -315,7 +308,25 @@ def get(self, request, *args, **kwargs):
315308
data['dc'] = dc
316309

317310
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)
319330
raise api_exceptions.NetworkAPIException(e)
320331

321332

@@ -336,7 +347,7 @@ def post(self, request, *args, **kwargs):
336347
data['dcroom'] = dcroom_serializer.data
337348

338349
return Response(data, status=status.HTTP_201_CREATED)
339-
except Exception, e:
350+
except Exception as e:
340351
raise api_exceptions.NetworkAPIException(e)
341352

342353
@commit_on_success
@@ -361,10 +372,9 @@ def put(self, request, *args, **kwargs):
361372
data['fabric'] = fabric_serializer.data
362373

363374
return Response(data, status=status.HTTP_200_OK)
364-
except Exception, e:
375+
except Exception as e:
365376
raise api_exceptions.NetworkAPIException(e)
366377

367-
368378
@commit_on_success
369379
def get(self, request, *args, **kwargs):
370380
try:
@@ -379,5 +389,23 @@ def get(self, request, *args, **kwargs):
379389
data['fabric'] = fabric
380390

381391
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)

networkapi/api_vlan/tests/sanity/json/get/get_one_vlan.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"id": 1,
1414
"name": "VLAN NUM 2 - RACK-1",
1515
"num_vlan": 2,
16-
"vrf": null
16+
"vrf": null,
17+
"vxlan": false
1718
}
1819
]
1920
}

networkapi/api_vlan/tests/sanity/json/get/get_one_vlan_details.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@
7272
"id": 1,
7373
"name": "VLAN NUM 2 - RACK-1",
7474
"num_vlan": 2,
75-
"vrf": null
75+
"vrf": null,
76+
"vxlan": false
7677
}
7778
]
7879
}

networkapi/api_vlan/tests/sanity/json/post/post_one_vlan.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"environment": 1,
1313
"name": "VLAN 300 - AMBIENTE 1",
1414
"num_vlan": 300,
15-
"vrf": null
15+
"vrf": null,
16+
"vxlan": false
1617
}
1718
]
1819
}

networkapi/api_vlan/tests/sanity/json/post/post_one_vlan_without_number.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"description": "",
1212
"environment": 1,
1313
"name": "VLAN AUTO - AMBIENTE 1",
14-
"vrf": null
14+
"vrf": null,
15+
"vxlan": false
1516
}
1617
]
1718
}

networkapi/api_vlan/tests/sanity/json/put/put_one_change_env_vlan_with_nets.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"id": 4,
1414
"name": "VLAN NUM 4 - RACK-1",
1515
"num_vlan": 4,
16-
"vrf": null
16+
"vrf": null,
17+
"vxlan": false
1718
}
1819
]
1920
}

networkapi/api_vlan/tests/sanity/json/put/put_one_vlan.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"id": 1,
1414
"name": "VLAN NUM 2 - RACK-1",
1515
"num_vlan": 2,
16-
"vrf": null
16+
"vrf": null,
17+
"vxlan": false
1718
}
1819
]
1920
}

0 commit comments

Comments
 (0)