Skip to content

Commit 833bda2

Browse files
author
laura.panzariello
committed
create lfxlf env to a new rack
1 parent 4cfb5b1 commit 833bda2

1 file changed

Lines changed: 53 additions & 4 deletions

File tree

networkapi/api_rack/rackenvironments.py

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ def leaf_leaf_vlans_save(self):
176176
log.debug("_create_lflf_vlans")
177177

178178
env_lf = models_env.Ambiente.objects.filter(dcroom=int(self.rack.dcroom.id),
179-
father_environment__isnull=True,
180179
grupo_l3__nome=str(self.rack.dcroom.name),
181180
ambiente_logico__nome="LEAF-LEAF")
182181
log.debug("Leaf-leaf environments: " + str(env_lf))
@@ -201,15 +200,15 @@ def leaf_leaf_vlans_save(self):
201200
except:
202201
log.debug("debug lfxlf")
203202
for net in env.configs:
204-
bloco = net.ip_config.subnet
203+
bloco = net.network
205204
prefix = bloco.split('/')[-1]
206205
network = {
207206
'prefix': prefix,
208207
'network_type': id_network_type
209208
}
210-
if str(net.ip_config.type)[-1] is "4":
209+
if str(net.ip_version)[-1] is "4":
211210
create_networkv4 = network
212-
elif str(net.ip_config.type)[-1] is "6":
211+
elif str(net.ip_version)[-1] is "6":
213212
create_networkv6 = network
214213
obj = {
215214
'name': vlan_name,
@@ -222,6 +221,56 @@ def leaf_leaf_vlans_save(self):
222221
}
223222
facade_vlan_v3.create_vlan(obj, self.user)
224223

224+
def leaf_leaf_envs_save(self):
225+
log.debug("_create_lflf_envs")
226+
227+
env_lf = models_env.Ambiente.objects.filter(dcroom=int(self.rack.dcroom.id),
228+
grupo_l3__nome=str(self.rack.dcroom.name),
229+
ambiente_logico__nome="LEAF-LEAF")
230+
log.debug("Leaf-leaf environments: " + str(env_lf))
231+
232+
try:
233+
id_l3 = models_env.GrupoL3().get_by_name(self.rack.nome).id
234+
except:
235+
l3_dict = models_env.GrupoL3()
236+
l3_dict.nome = self.rack.nome
237+
l3_dict.save()
238+
id_l3 = l3_dict.id
239+
pass
240+
241+
for env in env_lf:
242+
config_subnet = []
243+
for net in env.configs:
244+
cidr = list(IPNetwork(net.network).subnet(int(net.subnet_mask)))[self.rack.numero]
245+
network = {
246+
'network': str(cidr),
247+
'ip_version': str(net.ip_version),
248+
'network_type': int(net.id_network_type.id),
249+
'subnet_mask': int(net.subnet_mask)
250+
}
251+
config_subnet.append(network)
252+
253+
obj = {
254+
'grupo_l3': id_l3,
255+
'ambiente_logico': env.ambiente_logico.id,
256+
'divisao_dc': env.divisao_dc.id,
257+
'acl_path': env.acl_path,
258+
'ipv4_template': env.ipv4_template,
259+
'ipv6_template': env.ipv6_template,
260+
'link': env.link,
261+
'min_num_vlan_2': env.min_num_vlan_1,
262+
'max_num_vlan_2': env.max_num_vlan_1,
263+
'min_num_vlan_1': env.min_num_vlan_1,
264+
'max_num_vlan_1': env.max_num_vlan_1,
265+
'vrf': env.vrf,
266+
'father_environment': env.id,
267+
'default_vrf': env.default_vrf.id,
268+
'configs': config_subnet,
269+
'fabric_id': self.rack.dcroom.id
270+
}
271+
environment = facade_env.create_environment(obj)
272+
log.debug("Environment object: %s" % str(environment))
273+
225274
def prod_environment_save(self):
226275
log.debug("_create_prod_envs")
227276

0 commit comments

Comments
 (0)