Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
174 commits
Select commit Hold shift + click to select a range
444d18e
Merge pull request #377 from renanlopes97s/master
Malinoski May 18, 2023
fd23776
Merge pull request #378 from globocom/develop
renanlopes97s May 18, 2023
7eb01bb
Merge pull request #379 from renanlopes97s/master
renanlopes97s May 23, 2023
ab81a0f
Merge pull request #380 from globocom/develop
renanlopes97s May 23, 2023
b46ddc0
Merge pull request #381 from renanlopes97s/master
renanlopes97s May 24, 2023
eb27e1d
Merge pull request #382 from globocom/develop
renanlopes97s May 29, 2023
6df2aa8
Merge pull request #383 from globocom/master
renan-lopes-rodrigues Oct 24, 2023
fbbf411
unit test
renan-lopes-rodrigues Oct 24, 2023
7f9302e
test for network v6
renan-lopes-rodrigues Oct 25, 2023
274e38c
ajustar deploy local
Mar 26, 2024
cb72441
ajustar deploy local
Mar 26, 2024
c87512f
Merge pull request #386 from globocom/ajueste_docker
Malinoski Mar 26, 2024
fcf9caa
Merge pull request #387 from globocom/develop
Malinoski Mar 28, 2024
86d1757
bugfix
renan-lopes-rodrigues May 24, 2024
ba45152
Merge pull request #388 from globocom/FLSTD-1884
renan-lopes-rodrigues May 27, 2024
6849a81
Merge pull request #389 from globocom/develop
Malinoski May 27, 2024
8930567
update docker image to globocom/networkapi
Jun 11, 2024
12f673a
fix alocacao de ambientes spine x leaf para fabric
Jun 11, 2024
d5418b2
fix alocacao de ambientes leaf x leaf
Jun 12, 2024
06a87a4
Merge pull request #390 from marcusgc/master
marcusgc Jun 12, 2024
2430bc3
fix typo for rack name identifier
Jun 18, 2024
788f669
fix operator type
Jun 19, 2024
49913bd
Merge pull request #391 from marcusgc/master
deivisonmarteleto Jun 20, 2024
d28ee85
Merge pull request #392 from globocom/master
deivisonmarteleto Jun 20, 2024
ce7453e
fix operator type
Jun 20, 2024
76b33d8
Merge pull request #393 from marcusgc/master
deivisonmarteleto Jun 20, 2024
417e56a
Change error message text
Jun 24, 2024
296779b
fix allocation of intra-rack Leaf x Leaf vlans - change order to allo…
Jun 25, 2024
cfb0d25
Merge pull request #394 from marcusgc/master
deivisonmarteleto Jun 27, 2024
0c6a4c1
Update exceptions.py
deivisonmarteleto Jun 27, 2024
79d1ab4
Update exceptions.py
deivisonmarteleto Jun 27, 2024
38d50b8
troca codigo para gerar spines de acordo com quantidade
Jul 9, 2024
165e5b8
Merge branch 'globocom:master' into master
marcusgc Jul 9, 2024
7a07fef
Merge pull request #395 from marcusgc/master
renan-lopes-rodrigues Jul 9, 2024
5dd1ea9
Merge pull request #396 from globocom/master
renan-lopes-rodrigues Jul 9, 2024
5d2966a
created migration to change relation from equipment_list_config_bgp x…
renan-lopes-rodrigues Jul 15, 2024
0343bd8
Migrations documentation
renan-lopes-rodrigues Jul 15, 2024
ebd0491
revert .env
renan-lopes-rodrigues Jul 15, 2024
6f85fb0
downgrade
renan-lopes-rodrigues Jul 15, 2024
fe6af87
revert .env
renan-lopes-rodrigues Jul 15, 2024
9f47270
Merge pull request #397 from globocom/FLSTD-1989
Malinoski Jul 15, 2024
5bd13b8
Merge pull request #398 from globocom/develop
renan-lopes-rodrigues Jul 16, 2024
f80f795
workaround bug bugged db table. do not create prefix-list for bgp rou…
Jul 18, 2024
a26b305
Merge branch 'master' of https://github.com/marcusgc/GloboNetworkAPI
Jul 18, 2024
8fd248d
fix mistypo
Jul 18, 2024
5357135
added reck_num variable to add rack template
renan-lopes-rodrigues Jul 22, 2024
83ecc17
fixed model
renan-lopes-rodrigues Jul 23, 2024
f462837
Merge pull request #399 from marcusgc/master
renan-lopes-rodrigues Jul 23, 2024
eeb112d
Merge pull request #400 from globocom/develop
renan-lopes-rodrigues Jul 23, 2024
d2f6fdf
fixed rack algorithm
renan-lopes-rodrigues Jul 23, 2024
53e34e5
Revert "fixed rack algorithm"
renan-lopes-rodrigues Jul 23, 2024
5f3e5f8
fix algorithm
renan-lopes-rodrigues Jul 23, 2024
890226a
Merge pull request #401 from globocom/teste
renan-lopes-rodrigues Jul 23, 2024
4f8669e
Merge pull request #402 from globocom/develop
renan-lopes-rodrigues Jul 23, 2024
73fa176
added variables to create 2 sessions per spine
renan-lopes-rodrigues Jul 23, 2024
9d9812b
Merge pull request #403 from globocom/develop
renan-lopes-rodrigues Jul 23, 2024
9137248
fix variables
renan-lopes-rodrigues Jul 23, 2024
fd2e361
Merge pull request #404 from globocom/develop
renan-lopes-rodrigues Jul 23, 2024
0666edb
fixed variable
renan-lopes-rodrigues Jul 23, 2024
eb9a5ca
Merge pull request #405 from globocom/develop
renan-lopes-rodrigues Jul 23, 2024
056a899
another variable
renan-lopes-rodrigues Jul 23, 2024
e0c188a
Merge pull request #406 from globocom/develop
renan-lopes-rodrigues Jul 23, 2024
4455690
testing
renan-lopes-rodrigues Jul 23, 2024
20dc198
Merge pull request #407 from globocom/develop
renan-lopes-rodrigues Jul 23, 2024
28a6e0b
two leafs per spine
renan-lopes-rodrigues Jul 23, 2024
e9fed1c
Merge pull request #408 from globocom/develop
renan-lopes-rodrigues Jul 23, 2024
b755e4e
logger test
renan-lopes-rodrigues Jul 24, 2024
5fa02b1
Merge pull request #409 from globocom/develop
renan-lopes-rodrigues Jul 24, 2024
f347118
changed algorithm to get all 4 ips
renan-lopes-rodrigues Jul 24, 2024
9bd6393
Merge pull request #410 from globocom/develop
renan-lopes-rodrigues Jul 24, 2024
ba9fda4
format fix
renan-lopes-rodrigues Jul 24, 2024
ef7dc90
Merge pull request #411 from globocom/develop
renan-lopes-rodrigues Jul 24, 2024
16fe748
testing variales
renan-lopes-rodrigues Jul 24, 2024
4ba9843
Merge pull request #412 from globocom/develop
renan-lopes-rodrigues Jul 24, 2024
95a8b54
logger
renan-lopes-rodrigues Jul 24, 2024
80fee38
Merge pull request #413 from globocom/develop
renan-lopes-rodrigues Jul 24, 2024
254f7cf
teste
renan-lopes-rodrigues Jul 24, 2024
f82df6f
Merge pull request #414 from globocom/develop
renan-lopes-rodrigues Jul 24, 2024
93f0a15
changed variables
renan-lopes-rodrigues Jul 24, 2024
470372e
Merge pull request #415 from globocom/develop
renan-lopes-rodrigues Jul 24, 2024
6b61079
fix variables
renan-lopes-rodrigues Jul 24, 2024
bf879b2
Merge pull request #416 from globocom/develop
renan-lopes-rodrigues Jul 24, 2024
947d28c
added variables to desciprion on spine
renan-lopes-rodrigues Jul 24, 2024
475a4b1
Merge pull request #417 from globocom/develop
renan-lopes-rodrigues Jul 24, 2024
0f51ad3
fix
renan-lopes-rodrigues Jul 24, 2024
a919fb7
Merge pull request #418 from globocom/develop
renan-lopes-rodrigues Jul 24, 2024
2aaece4
fix variable
renan-lopes-rodrigues Jul 24, 2024
558dbc4
Merge pull request #419 from globocom/develop
renan-lopes-rodrigues Jul 24, 2024
72e268d
testing
renan-lopes-rodrigues Jul 24, 2024
5fae003
Merge pull request #420 from globocom/develop
renan-lopes-rodrigues Jul 24, 2024
362162a
testing
renan-lopes-rodrigues Jul 24, 2024
3836b01
Merge pull request #421 from globocom/develop
renan-lopes-rodrigues Jul 24, 2024
6ce17d6
testing
renan-lopes-rodrigues Jul 24, 2024
cac792f
Merge pull request #422 from globocom/develop
renan-lopes-rodrigues Jul 24, 2024
e103358
fixed variables
renan-lopes-rodrigues Jul 25, 2024
f49d014
Merge pull request #423 from globocom/develop
renan-lopes-rodrigues Jul 25, 2024
6f42dc8
fixed
renan-lopes-rodrigues Jul 25, 2024
ed37169
Merge pull request #424 from globocom/develop
renan-lopes-rodrigues Jul 25, 2024
dffa1c9
fixed
renan-lopes-rodrigues Jul 25, 2024
012d827
Merge pull request #425 from globocom/develop
renan-lopes-rodrigues Jul 25, 2024
7a2cab3
multiple interfaces
renan-lopes-rodrigues Jul 25, 2024
7dc5eac
Merge pull request #426 from globocom/develop
renan-lopes-rodrigues Jul 25, 2024
6141afc
testing
renan-lopes-rodrigues Jul 25, 2024
2651a8c
Merge pull request #427 from globocom/develop
renan-lopes-rodrigues Jul 25, 2024
902cece
fix variable
renan-lopes-rodrigues Jul 25, 2024
a7ff6d6
Merge pull request #428 from globocom/develop
renan-lopes-rodrigues Jul 25, 2024
3179767
changed variables local
renan-lopes-rodrigues Jul 25, 2024
89059a7
Merge pull request #429 from globocom/develop
renan-lopes-rodrigues Jul 25, 2024
8fd4d5b
fix
renan-lopes-rodrigues Jul 25, 2024
f6789d6
Merge pull request #430 from globocom/develop
renan-lopes-rodrigues Jul 25, 2024
09ff98a
fix variable
renan-lopes-rodrigues Jul 25, 2024
ceed523
Merge pull request #431 from globocom/develop
renan-lopes-rodrigues Jul 25, 2024
35f1613
better variables
renan-lopes-rodrigues Jul 26, 2024
b02f657
Merge pull request #432 from globocom/develop
renan-lopes-rodrigues Jul 26, 2024
34d47bf
code cleaning
renan-lopes-rodrigues Jul 26, 2024
67f7cd9
Merge pull request #433 from globocom/develop
renan-lopes-rodrigues Jul 26, 2024
fdb2b4f
added comments
renan-lopes-rodrigues Jul 26, 2024
6e247d6
Merge pull request #434 from globocom/develop
renan-lopes-rodrigues Jul 26, 2024
bab2bad
fix leaf variables
renan-lopes-rodrigues Jul 29, 2024
98683f0
Merge pull request #435 from globocom/develop
renan-lopes-rodrigues Jul 30, 2024
cc50608
invert variables
renan-lopes-rodrigues Jul 31, 2024
34f15c0
Merge pull request #436 from globocom/develop
renan-lopes-rodrigues Jul 31, 2024
96f04d3
finished algorithm
renan-lopes-rodrigues Aug 1, 2024
c75e29d
Merge pull request #437 from globocom/develop
renan-lopes-rodrigues Aug 1, 2024
5cc8fc4
fixed variable name and query filter to allocate vlans to a new rack
renan-lopes-rodrigues Aug 9, 2024
2b507b2
Merge pull request #438 from globocom/develop
renan-lopes-rodrigues Aug 9, 2024
0a33751
fixed variable name and query filter to allocate vlans to a new rack
renan-lopes-rodrigues Aug 9, 2024
523c025
Merge pull request #439 from globocom/develop
renan-lopes-rodrigues Aug 9, 2024
ad6ae86
Better error message in the exception.
Malinoski Sep 11, 2024
a7c68de
Merge pull request #440 from globocom/FLSTD-2096-better-error-message
renan-lopes-rodrigues Sep 11, 2024
e9c5eca
Merge pull request #441 from globocom/develop
renan-lopes-rodrigues Sep 11, 2024
03527ed
Bug fix for undeploying VIP request without associated equipment; Add…
Malinoski Sep 26, 2024
b4b7054
Merge pull request #442 from globocom/FLSTD-2102-bugfix-undeploy-vip-…
renan-lopes-rodrigues Sep 26, 2024
ee87d61
Merge pull request #443 from globocom/develop
renan-lopes-rodrigues Sep 26, 2024
82ebf39
added channel verification
renan-lopes-rodrigues Oct 18, 2024
10a20e8
Merge pull request #444 from globocom/FLSTD-2165
Malinoski Oct 18, 2024
7534711
better condition
renan-lopes-rodrigues Oct 21, 2024
47b5e08
Merge pull request #445 from globocom/FLSTD-2165
renan-lopes-rodrigues Oct 21, 2024
fcfb3ba
Merge pull request #446 from globocom/develop
renan-lopes-rodrigues Oct 22, 2024
acf8948
collecting data
Malinoski Oct 24, 2024
556c5f7
code clean
Malinoski Oct 24, 2024
451b2f9
Adding overrides validator to POST interfaces.
Malinoski Oct 30, 2024
e444d6c
Merge pull request #447 from globocom/FLSTD-2164-post-interface-valid…
renan-lopes-rodrigues Oct 30, 2024
9ecaa3c
Merge pull request #448 from globocom/develop
renan-lopes-rodrigues Oct 30, 2024
c417553
first steps
Jan 31, 2025
4cfc8f0
finished cli to netconf
Feb 3, 2025
3049a45
better lint
Feb 3, 2025
7a2af8c
started to add logs on methods
Feb 4, 2025
5686762
Logs for CLI created
Feb 5, 2025
9d6d9d2
logs finished
Feb 5, 2025
8501396
Merge pull request #449 from renan-lopes-rodrigues/FLSTD-2329_NETCONF…
Malinoski Feb 5, 2025
0aeaae7
Merge pull request #450 from globocom/develop
renan-lopes-rodrigues Feb 6, 2025
e1fff97
better lint
Feb 6, 2025
fa53dd7
Merge pull request #451 from renan-lopes-rodrigues/master
renan-lopes-rodrigues Feb 6, 2025
b0474dc
Merge pull request #452 from globocom/develop
renan-lopes-rodrigues Feb 6, 2025
557b92c
changed plugin to make a request instead of apply in equipment by net…
May 23, 2025
e626dca
Merge pull request #453 from renan-lopes-rodrigues/FLSTD-2566
renan-lopes-rodrigues May 23, 2025
fd2e0a7
Merge pull request #454 from globocom/develop
renan-lopes-rodrigues May 23, 2025
5ebd43d
code cleanning
May 23, 2025
01be785
Merge pull request #455 from renan-lopes-rodrigues/FLSTD-2566
renan-lopes-rodrigues May 23, 2025
68ca363
Merge pull request #456 from globocom/develop
renan-lopes-rodrigues May 23, 2025
70ef91a
better condition to choose netconf
May 23, 2025
9e3c85d
Merge pull request #457 from renan-lopes-rodrigues/FLSTD-2566
renan-lopes-rodrigues May 23, 2025
7d5bc33
Merge pull request #458 from globocom/develop
renan-lopes-rodrigues May 23, 2025
bcbc69e
Debugs and notes added at Port Channel DELETE request
Malinoski Jun 17, 2025
b5a2d9d
Merge pull request #459 from globocom/FLSTD-2608
renan-lopes-rodrigues Jun 17, 2025
d239b5c
Merge pull request #460 from globocom/develop
renan-lopes-rodrigues Jun 17, 2025
929639b
removed config tag from templates
Jun 17, 2025
c85f955
moved tipo acesso query to the base factory plugin
Jun 27, 2025
075586f
fixed bgp deploy
Jun 30, 2025
3892ebb
starting to fix rack provision to support new topology
Sep 26, 2025
b401d1f
finished code
Oct 2, 2025
fa9cdd5
Merge pull request #1 from renan-lopes-rodrigues/FLSTD-2754
renan-lopes-rodrigues Oct 3, 2025
fc332ab
bugfix at equiptoacesso resource
Oct 29, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,16 @@ publish: clean
# Containers based target rules
#

start: docker-compose-sdn.yml docker-compose.yml
start_recreate: docker-compose-sdn.yml docker-compose.yml
docker-compose up --force-recreate --remove-orphans -d
docker-compose --file $< up --force-recreate -d


start: docker-compose-sdn.yml docker-compose.yml
docker-compose up -d
docker-compose --file $< up -d


stop: docker-compose-sdn.yml docker-compose.yml
@docker-compose down --remove-orphans

Expand Down Expand Up @@ -172,8 +177,8 @@ endif


build_img: scripts/docker/Dockerfile
docker build -t networkapi:latest --file scripts/docker/Dockerfile .
docker build -t networkapi:$(NETAPI_IMAGE_VERSION) --file scripts/docker/Dockerfile .
docker build --platform=linux/x86_64 -t networkapi:latest --file scripts/docker/Dockerfile .
docker build --platform=linux/x86_64 -t networkapi:$(NETAPI_IMAGE_VERSION) --file scripts/docker/Dockerfile .


push_img: scripts/docker/push_image.sh
Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,15 @@ It was not created to be and inventory database, so it does not have CMDB functi
## Documentation
[Documentation](http://globonetworkapi.readthedocs.org/)

## Run API
Run `make build_img && make start` and visit `http://localhost:8000/healthcheck` if running locally.

## Run Unit Tests
To run the unit tests just run `make build_img && make start && make test_ci` this instruction will run all the unit tests specified in the `networkapi/tests/__init__.py` file.
Run `make test_ci`. This command will run all the unit tests specified in the `networkapi/tests/__init__.py` file.

## Create and run migrations
To create a new migration, just run into app container `cd dbmigrate; db-migrate --new=<MIGRATION_NAME>`. This step will create a enpty migration file, you must write the SQL statement.
To run a migration, just run into app container `cd dbmigrate; db-migrate`. This command will execute all migrations files not executed until now.

## How to contribute
Check this out at
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#-*- coding:utf-8 -*-
SQL_UP = u"""
ALTER TABLE equipment_list_config_bgp DROP FOREIGN KEY fk_equipment_list_config_bgp_2;
ALTER TABLE equipment_list_config_bgp ADD CONSTRAINT `fk_equipment_list_config_bgp_2` FOREIGN KEY (`id_list_config_bgp`) REFERENCES `list_config_bgp` (`id`)
"""

SQL_DOWN = u"""
ALTER TABLE equipment_list_config_bgp DROP FOREIGN KEY fk_equipment_list_config_bgp_2;
ALTER TABLE equipment_list_config_bgp ADD CONSTRAINT `fk_equipment_list_config_bgp_2` FOREIGN KEY (`id_list_config_bgp`) REFERENCES `route_map` (`id`)
"""
24 changes: 15 additions & 9 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,21 @@ services:
container_name: netapi_db
image: mysql:5.7
platform: linux/x86_64
command: --default-authentication-plugin=mysql_native_password
ports:
- "3306:3306"
- "33306:3306"
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: 1
MYSQL_ROOT_PASSWORD: 'put_your_password_here'
volumes:
- netapi_db_vol:/var/lib/mysql
networks:
- netapi_net
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "127.0.0.1",-p$$MYSQL_ROOT_PASSWORD ,"--silent"]
interval: 5s
timeout: 3s
retries: 2
start_period: 15s

queue:
container_name: netapi_queue
Expand All @@ -37,7 +44,7 @@ services:

celery:
container_name: netapi_celery
image: networkapi:latest
image: globocom/networkapi:latest
build:
context: .
dockerfile: ./scripts/docker/Dockerfile
Expand All @@ -55,11 +62,11 @@ services:
- queue:netapi_queue
- cache:netapi_cache
depends_on:
- queue
- queue

netapi:
container_name: netapi_app
image: globocom:latest
image: globocom/networkapi:latest
build:
context: .
dockerfile: ./scripts/docker/Dockerfile
Expand All @@ -79,9 +86,8 @@ services:
networks:
- netapi_net
depends_on:
- db
- queue
- cache
db:
condition: service_healthy
links:
- db:netapi_db
external_links:
Expand All @@ -94,4 +100,4 @@ volumes:
netapi_db_vol:

networks:
netapi_net:
netapi_net:
4 changes: 2 additions & 2 deletions fast_start_test.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh
source venv/bin/activate
source /venv/bin/activate

pip install --no-cache --upgrade pip
pip install -r requirements_test.txt
Expand Down Expand Up @@ -100,7 +100,7 @@ echo "=============== Tests for Network v6 ================="
python manage.py test networkapi/api_network.tests.v3.unit.networkipv6.async.test_delete.py
python manage.py test networkapi/api_network.tests.v3.unit.networkipv6.async.test_post.py
python manage.py test networkapi/api_network.tests.v3.unit.networkipv6.async.test_put.py
python manage.py test networkapi/api_network.tests.v3.sanity.allocate.test_network_v4.py
python manage.py test networkapi/api_network.tests.v3.sanity.allocate.test_network_v6.py
python manage.py test networkapi/api_network.tests.v3.sanity.networkipv6.sync.test_delete.py
python manage.py test networkapi/api_network.tests.v3.sanity.networkipv6.sync.test_get.py
python manage.py test networkapi/api_network.tests.v3.sanity.networkipv6.sync.test_post.py
Expand Down
4 changes: 2 additions & 2 deletions networkapi/ambiente/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1976,7 +1976,7 @@ def searchNextAvailableCIDR(self, subnets, network_mask=None):
for idx in range(len(subnets)-1):
step = int(subnets[idx+1].network_first_ip) - int(subnets[idx].network_last_ip) - 1
if step >= 2 ** (32-int(network_mask)):
subnet = NETADDR(str(NETADDR(subnets[idx].network).next().ip) + "/" + network_mask)
subnet = NETADDR(str(NETADDR(subnets[idx].network).next().ip) + "/" + str(network_mask))
if subnet.ip == subnet.network and \
not ipaddr.IPNetwork(subnet).overlaps(ipaddr.IPNetwork(subnets[idx+1].network)):
return str(subnet)
Expand All @@ -2000,7 +2000,7 @@ def nextAvailableCIDR(self, subnets, network, network_mask=None):
elif int(network_mask) == last_subnet.prefixlen:
subnet = last_subnet.next()
else:
subnet = NETADDR(str(last_subnet.next().ip) + "/" + network_mask)
subnet = NETADDR(str(last_subnet.next().ip) + "/" + str(network_mask))
if not subnet.ip == subnet.network:
subnet = subnet.next()

Expand Down
7 changes: 7 additions & 0 deletions networkapi/api_channel/facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ def create(self, data):
vlan_nativa = data.get('vlan')
envs_vlans = data.get('envs_vlans')

### Verify if channel number is greater than 0 and smaller or equal to 4096
if int(nome) > 4096 or int(nome) <=1 :
log.error("Channel %s must be between 0 and 4097." % nome)
raise InterfaceError(
"Channel %s must be between 0 and 4097." % nome
)

api_interface_facade.verificar_vlan_nativa(vlan_nativa)

# Checks if Port Channel name already exists on equipment
Expand Down
7 changes: 6 additions & 1 deletion networkapi/api_deploy/facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from networkapi.api_equipment.exceptions import AllEquipmentsAreInMaintenanceException
from networkapi.api_rest import exceptions as api_exceptions
from networkapi.distributedlock import distributedlock
from networkapi.equipamento.models import Equipamento
from networkapi.equipamento.models import Equipamento, EquipamentoAcesso
from networkapi.extra_logging import local
from networkapi.extra_logging import NO_REQUEST_ID
from networkapi.plugins.factory import PluginFactory
Expand Down Expand Up @@ -65,6 +65,11 @@ def _applyconfig(equipment, filename, equipment_access=None, source_server=None,

# TODO: Handle exceptions from the following methods and generate response
# for the caller
# tipo_acesso = EquipamentoAcesso.search(None,
# equipment,
# ).uniqueResult()
# if tipo_acesso is None:
# return 'Equipment has no Access.'

equip_plugin = PluginFactory.factory(equipment)
equip_plugin.connect()
Expand Down
4 changes: 2 additions & 2 deletions networkapi/api_equipment/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ class AllEquipmentsAreInMaintenanceException(APIException):
status_code = status.HTTP_400_BAD_REQUEST
default_detail = 'All equipments to be configured are in maintenance mode.'

def __init__(self, param=default_detail):
self.detail = param
def __init__(self, param=default_detail, equips=None):
self.detail = param if not equips else "{} Equipments: {}".format(param, equips)


class EquipmentInvalidValueException(APIException):
Expand Down
12 changes: 12 additions & 0 deletions networkapi/api_interface/facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,13 +290,21 @@ def get_interface_by_ids(interface_ids):


def generate_delete_file(user, equip_id, interface_list, channel):

log.info("generate_delete_file equip_id:%s interface_list:%s channel:%s", equip_id, interface_list, channel)

try:
INTERFACE_CONFIG_TOAPPLY_REL_PATH = get_variable(
'interface_config_toapply_rel_path')
INTERFACE_CONFIG_FILES_PATH = get_variable(
'interface_config_files_path')
TEMPLATE_REMOVE_CHANNEL = get_variable('template_remove_channel')
TEMPLATE_REMOVE_INTERFACE = get_variable('template_remove_interface')

log.debug('INTERFACE_CONFIG_TOAPPLY_REL_PATH:%s', INTERFACE_CONFIG_TOAPPLY_REL_PATH)
log.debug('INTERFACE_CONFIG_FILES_PATH:%s', INTERFACE_CONFIG_FILES_PATH)
log.debug('TEMPLATE_REMOVE_CHANNEL:%s', TEMPLATE_REMOVE_CHANNEL)
log.debug('TEMPLATE_REMOVE_INTERFACE:%s', TEMPLATE_REMOVE_INTERFACE)
except ObjectDoesNotExist:
raise var_exceptions.VariableDoesNotExistException(
'Erro buscando a variável INTERFACE_CONFIG_TEMPLATE_PATH,'
Expand Down Expand Up @@ -350,9 +358,12 @@ def generate_delete_file(user, equip_id, interface_list, channel):

def delete_channel(user, equip_id, interface_list, channel):

log.info('delete_channel equip_id:%s interface_list:%s channel:%s', equip_id, interface_list, channel)

file_to_deploy = generate_delete_file(
user, equip_id, interface_list, channel)

log.debug('file_to_deploy: %s', file_to_deploy)
# TODO Deploy config file
try:
lockvar = LOCK_EQUIPMENT % (equip_id)
Expand Down Expand Up @@ -510,6 +521,7 @@ def _load_template_file(equipment_id, template_type):

filename_in = INTERFACE_CONFIG_TEMPLATE_PATH + \
equipment_template.roteiro.roteiro
log.debug("filename_in: %s", filename_in)

# Read contents from file
try:
Expand Down
35 changes: 35 additions & 0 deletions networkapi/api_interface/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
from networkapi.util.decorators import prepare_search
from networkapi.util.json_validate import json_validate
from networkapi.util.json_validate import raise_json_validate
from networkapi.util.interface_validate import InterfaceOverrideValidator
from networkapi.util.geral import create_lock
from networkapi.util.geral import destroy_lock
from networkapi.util.geral import render_to_json
Expand Down Expand Up @@ -327,6 +328,10 @@ class InterfaceV3View(CustomAPIView):
def get(self, request, *args, **kwargs):
"""URL: api/v3/interface/"""

log.info('InterfaceV3View GET')
log.info('kwargs: %s', kwargs)
log.info('search: %s', self.search)

if not kwargs.get('obj_ids'):
obj_model = facade.get_interface_by_search(self.search)
interfaces = obj_model['query_set']
Expand Down Expand Up @@ -354,6 +359,8 @@ def get(self, request, *args, **kwargs):
only_main_property=only_main_property
)

log.info('get interfaces response: %s', data)

return Response(data, status=status.HTTP_200_OK)

@logs_method_apiview
Expand All @@ -369,8 +376,36 @@ def post(self, request, *args, **kwargs):
response = list()

interfaces = request.DATA
log.info('InterfaceV3View POST')
log.info('interfaces: %s', interfaces)
log.info('kwargs: %s', kwargs)
json_validate(SPECS.get('interface_post')).validate(interfaces)

user_interface_str_list = []
equipmemnt_interface_str_list = []
for interface in interfaces.get('interfaces'):

# User interface input, ex.:
# ex.: eth1, eth1/1, 1, Gi1/5, FF:FF:FF:FF:FF:F, int1, mgmt0, ethernet1/12, ..
interface_input = interface['interface']
user_interface_str_list.append(interface_input)

# Equipments from input interface
equipment_id = interface['equipment']
obj_model = facade.get_interface_by_search(
{'extends_search': [], 'start_record': 0, 'custom_search': equipment_id, 'end_record': 1000, 'asorting_cols': ['id'], 'searchable_columns': ['equipamento__id']}
)
equipment_list = obj_model['query_set']
log.debug("equipment_list %s", equipment_list)
for equipment_interface in equipment_list:
equipmemnt_interface_str_list.append(equipment_interface.interface)

# Validate interface overrinding
InterfaceOverrideValidator().check_overriding(
source_interface_str_list=user_interface_str_list,
target_interface_str_list=equipmemnt_interface_str_list
)

for i in interfaces.get('interfaces'):
try:
interface = facade.create_interface(i)
Expand Down
10 changes: 6 additions & 4 deletions networkapi/api_neighbor/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,12 @@ def deploy(self):
list_config_bgp=entry.list_config_bgp
)
if not eqpt_list_config:
EquipmentListConfig().create_v4({
'equipment': equipment.id,
'list_config_bgp': entry.list_config_bgp.id
})
self.log.debug('equipment id %s' % equipment.id)
self.log.debug('id_list_config_bgp %s' % entry.list_config_bgp.id)
# EquipmentListConfig().create_v4({
# 'equipment': equipment.id,
# 'list_config_bgp': entry.list_config_bgp.id
# })

def undeploy(self):
"""Undeploy NeighborV4."""
Expand Down
18 changes: 10 additions & 8 deletions networkapi/api_neighbor/v4/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,27 +123,29 @@ class RemoteIpAndRemoteAsnAtDifferentEquipmentsException(APIException):
status_code = status.HTTP_400_BAD_REQUEST

def __init__(self, neighbor):
self.detail = u'RemoteIp id = {} and RemoteAsn id = {} belongs to ' \
u'different Equipments'.\
format(neighbor.remote_ip, neighbor.remote_asn)
# self.detail = u'RemoteIp id = {} and RemoteAsn id = {} belongs to ' \
# u'different Equipments'.\
# format(neighbor.remote_ip, neighbor.remote_asn)
self.detail = u'O ASN remoto (id: {}) não está associado a qualquer equipamento do IP (id: {}). '.\
format(neighbor.remote_asn, neighbor.remote_ip)


class LocalIpAndPeerGroupAtDifferentEnvironmentsException(APIException):
status_code = status.HTTP_400_BAD_REQUEST

def __init__(self, neighbor):
self.detail = u'LocalIp id = {} and PeerGroup id = {} belongs to ' \
u'different Environments'. \
format(neighbor.local_ip, neighbor.peer_group)
self.detail = u'Not allowed to configure BGP neighbor using this Peer Group. ' \
u'PeerGroup id = {} is not mapped to the environment of LocalIp id = {}'.\
format(neighbor.peer_group, neighbor.local_ip)


class NeighborDuplicatedException(APIException):
status_code = status.HTTP_400_BAD_REQUEST

def __init__(self, neighbor):
self.detail = u'It already exists Neighbor with LocalAsn id = {}, ' \
self.detail = u'Duplicated neighbor. A Neighbor with LocalAsn id = {}, ' \
u'LocalIp id = {}, RemoteAsn id = {} and ' \
u'RemoteIp id = {}'.\
u'RemoteIp id = {} already exists'.\
format(neighbor.local_asn, neighbor.local_ip,
neighbor.remote_asn, neighbor.remote_ip)

Expand Down
8 changes: 8 additions & 0 deletions networkapi/api_rack/autoprovision.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,8 +509,16 @@ def autoprovision_splf(rack, equips):
variablestochangespine1["VLANBORDACACHOSLEAF"] = str(VLANBORDACACHOSLEAF[numero_rack][spine_num-1])
variablestochangespine1["VLANBORDACACHOSBLEAF"] = str(VLANBORDACACHOSBLEAF[numero_rack][spine_num-1])
variablestochangespine1["ASLEAF"] = str(ASLEAF[numero_rack][0])

### To pop Berrini
variablestochangespine1["IPNEIGHLEAF2IPV4"] = str(IPLEAFipv4[numero_rack][spine_num])
variablestochangespine1["IPNEIGHLEAF2IPV6"] = str(IPLEAFipv6[numero_rack][spine_num])


variablestochangespine1["IPNEIGHLEAFIPV4"] = str(IPLEAFipv4[numero_rack][spine_num-1])
variablestochangespine1["IPNEIGHLEAFIPV6"] = str(IPLEAFipv6[numero_rack][spine_num-1])

variablestochangespine1["RACK_NUM"] = str(numero_rack)
if spine_num in [1, 3]:
variablestochangeleaf1["SP1_HOSTNAME"] = i.get("nome")
variablestochangeleaf1["INTERFACE_SP1"] = i.get("interface")
Expand Down
2 changes: 1 addition & 1 deletion networkapi/api_rack/facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -970,8 +970,8 @@ def allocate_env_vlan(user, rack_id):
rack_env.spine_leaf_vlans_save()

# leaf x leaf
rack_env.leaf_leaf_vlans_save()
rack_env.leaf_leaf_envs_save()
rack_env.leaf_leaf_vlans_save()

# producao/cloud
rack_env.prod_environment_save()
Expand Down
Loading