From ae4480664ee3cfc83d629dc10c7622291385298e Mon Sep 17 00:00:00 2001 From: Eishun Kondoh Date: Mon, 31 Oct 2022 08:45:17 +0000 Subject: [PATCH 1/4] blueprint: Add support for blueprint fabric-addressing-policy API --- aos/blueprint.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/aos/blueprint.py b/aos/blueprint.py index 67aa4f4..5722e96 100644 --- a/aos/blueprint.py +++ b/aos/blueprint.py @@ -2191,3 +2191,44 @@ def add_virtual_network_batch(self, bp_id: str, payload: str): vn_path = f"/api/blueprints/{bp_id}/virtual-networks-batch" return self.rest.json_resp_post(uri=vn_path, data=payload) + + def get_fabric_addressing_policy(self, bp_id): + """ + Return fabric-addressing-policy in a given blueprint. + + Parameters + ---------- + bp_id + (str) - ID of AOS Blueprint + + Returns + ---------- + (obj) json object + """ + path = f'/api/blueprints/{bp_id}/fabric-addressing-policy' + return self.rest.json_resp_get(path) + + def update_fabric_addressing_policy(self, bp_id, ipv6_enabled=None, esi_mac_msb=None): + """ + Sets a fabric addressing policy for a given blueprint. + + Parameters + ---------- + bp_id + (str) - ID of AOS Blueprint + (bool) - (optional) enable or disable support for IPv6 virtual networks + (int) - (optional) Most Significant Byte (MSB) value used for ESI MAC addresses + Returns + ------- + """ + + data = {} + + if ipv6_enabled: + data['ipv6_enabled'] = ipv6_enabled + + if esi_mac_msb: + data['esi_mac_msb'] = esi_mac_msb + + url = f'/api/blueprints/{bp_id}/fabric-addressing-policy' + return self.rest.patch(url, data=data) From a13e7d767943b9f118dda49d85ba9ab28a616230 Mon Sep 17 00:00:00 2001 From: Eishun Kondoh Date: Mon, 31 Oct 2022 16:18:07 +0000 Subject: [PATCH 2/4] tests: Add unit tests for fabric-addressing-policy --- .../get_fabric_addressing_policy.json | 1 + .../get_fabric_addressing_policy.json | 1 + tests/test_blueprint.py | 56 +++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 tests/fixtures/aos/3.3.0/blueprints/get_fabric_addressing_policy.json create mode 100644 tests/fixtures/aos/4.0.0/blueprints/get_fabric_addressing_policy.json diff --git a/tests/fixtures/aos/3.3.0/blueprints/get_fabric_addressing_policy.json b/tests/fixtures/aos/3.3.0/blueprints/get_fabric_addressing_policy.json new file mode 100644 index 0000000..40f3aa3 --- /dev/null +++ b/tests/fixtures/aos/3.3.0/blueprints/get_fabric_addressing_policy.json @@ -0,0 +1 @@ +{"ipv6_enabled": false, "esi_mac_msb": 2} diff --git a/tests/fixtures/aos/4.0.0/blueprints/get_fabric_addressing_policy.json b/tests/fixtures/aos/4.0.0/blueprints/get_fabric_addressing_policy.json new file mode 100644 index 0000000..40f3aa3 --- /dev/null +++ b/tests/fixtures/aos/4.0.0/blueprints/get_fabric_addressing_policy.json @@ -0,0 +1 @@ +{"ipv6_enabled": false, "esi_mac_msb": 2} diff --git a/tests/test_blueprint.py b/tests/test_blueprint.py index 93e3130..191c752 100644 --- a/tests/test_blueprint.py +++ b/tests/test_blueprint.py @@ -1554,3 +1554,59 @@ def test_get_routing_policies( "static_routes": False, "l3edge_server_links": True, } + + +def test_get_fabric_addressing_policy( + aos_logged_in, aos_session, expected_auth_headers, aos_api_version +): + bp_id = 'test-bp-1' + aos_session.add_response( + 'GET', + f"http://aos:80/api/blueprints/{bp_id}/fabric-addressing-policy", + status=200, + resp=read_fixture( + f'aos/{aos_api_version}/blueprints/' f'get_fabric_addressing_policy.json' + ), + ) + + resp = aos_logged_in.blueprint.get_fabric_addressing_policy(bp_id=bp_id) + assert not resp['ipv6_enabled'] + assert resp['esi_mac_msb'] % 2 == 0 + +def test_update_fabric_addressing_policy( + aos_logged_in, aos_session, expected_auth_headers, aos_api_version +): + bp_id = 'test-bp-1' + url = f"http://aos:80/api/blueprints/{bp_id}/fabric-addressing-policy" + aos_session.add_response( + 'PATCH', + url, + status=200, + ) + + resp = aos_logged_in.blueprint.update_fabric_addressing_policy(bp_id=bp_id, ipv6_enabled=True) + aos_session.request.assert_called_with( + "PATCH", + url, + json={"ipv6_enabled": True}, + params=None, + headers=expected_auth_headers, + ) + + resp = aos_logged_in.blueprint.update_fabric_addressing_policy(bp_id=bp_id, esi_mac_msb=4) + aos_session.request.assert_called_with( + "PATCH", + url, + json={"esi_mac_msb": 4}, + params=None, + headers=expected_auth_headers, + ) + + resp = aos_logged_in.blueprint.update_fabric_addressing_policy(bp_id=bp_id, ipv6_enabled=True, esi_mac_msb=4) + aos_session.request.assert_called_with( + "PATCH", + url, + json={"ipv6_enabled": True, "esi_mac_msb": 4}, + params=None, + headers=expected_auth_headers, + ) From 720937d16c39b809ce4224f1ab1dbd004c8ca409 Mon Sep 17 00:00:00 2001 From: shun159 Date: Sat, 5 Nov 2022 11:54:00 +0900 Subject: [PATCH 3/4] blueprint: Fix for lint check --- aos/blueprint.py | 10 ++++++++-- tests/test_blueprint.py | 17 ++++++++++++++--- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/aos/blueprint.py b/aos/blueprint.py index 5722e96..5a1afae 100644 --- a/aos/blueprint.py +++ b/aos/blueprint.py @@ -2208,7 +2208,12 @@ def get_fabric_addressing_policy(self, bp_id): path = f'/api/blueprints/{bp_id}/fabric-addressing-policy' return self.rest.json_resp_get(path) - def update_fabric_addressing_policy(self, bp_id, ipv6_enabled=None, esi_mac_msb=None): + def update_fabric_addressing_policy( + self, + bp_id, + ipv6_enabled=None, + esi_mac_msb=None + ): """ Sets a fabric addressing policy for a given blueprint. @@ -2217,7 +2222,8 @@ def update_fabric_addressing_policy(self, bp_id, ipv6_enabled=None, esi_mac_msb= bp_id (str) - ID of AOS Blueprint (bool) - (optional) enable or disable support for IPv6 virtual networks - (int) - (optional) Most Significant Byte (MSB) value used for ESI MAC addresses + (int) - (optional) Most Significant Byte (MSB) value used for + ESI MAC addresses Returns ------- """ diff --git a/tests/test_blueprint.py b/tests/test_blueprint.py index 191c752..b56b88c 100644 --- a/tests/test_blueprint.py +++ b/tests/test_blueprint.py @@ -1573,6 +1573,7 @@ def test_get_fabric_addressing_policy( assert not resp['ipv6_enabled'] assert resp['esi_mac_msb'] % 2 == 0 + def test_update_fabric_addressing_policy( aos_logged_in, aos_session, expected_auth_headers, aos_api_version ): @@ -1584,7 +1585,10 @@ def test_update_fabric_addressing_policy( status=200, ) - resp = aos_logged_in.blueprint.update_fabric_addressing_policy(bp_id=bp_id, ipv6_enabled=True) + aos_logged_in.blueprint.update_fabric_addressing_policy( + bp_id=bp_id, + ipv6_enabled=True + ) aos_session.request.assert_called_with( "PATCH", url, @@ -1593,7 +1597,10 @@ def test_update_fabric_addressing_policy( headers=expected_auth_headers, ) - resp = aos_logged_in.blueprint.update_fabric_addressing_policy(bp_id=bp_id, esi_mac_msb=4) + aos_logged_in.blueprint.update_fabric_addressing_policy( + bp_id=bp_id, + esi_mac_msb=4 + ) aos_session.request.assert_called_with( "PATCH", url, @@ -1602,7 +1609,11 @@ def test_update_fabric_addressing_policy( headers=expected_auth_headers, ) - resp = aos_logged_in.blueprint.update_fabric_addressing_policy(bp_id=bp_id, ipv6_enabled=True, esi_mac_msb=4) + aos_logged_in.blueprint.update_fabric_addressing_policy( + bp_id=bp_id, + ipv6_enabled=True, + esi_mac_msb=4 + ) aos_session.request.assert_called_with( "PATCH", url, From 5e8c856c80f1d7e22376e4047d5e75983a0398f3 Mon Sep 17 00:00:00 2001 From: shun159 Date: Sat, 5 Nov 2022 11:54:13 +0900 Subject: [PATCH 4/4] Version bump --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 05719e4..5779478 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ NAME = "apstra-api-python" -VERSION = '0.1.20' +VERSION = '0.1.21' REQUIRES = (["requests==2.24.0"],)