diff --git a/aos/blueprint.py b/aos/blueprint.py index 67aa4f4..5a1afae 100644 --- a/aos/blueprint.py +++ b/aos/blueprint.py @@ -2191,3 +2191,50 @@ 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) 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"],) 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..b56b88c 100644 --- a/tests/test_blueprint.py +++ b/tests/test_blueprint.py @@ -1554,3 +1554,70 @@ 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, + ) + + 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, + ) + + 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, + ) + + 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, + )