Skip to content

Commit dbf0dd2

Browse files
authored
blueprint: Add support for GET /api/blueprints/{bp_id}/relationships (#44)
* blueprint: Add support for GET /api/blueprints/{bp_id}/relationships * blueprint: fix to use params instead of querystring
1 parent a061172 commit dbf0dd2

File tree

5 files changed

+184
-1
lines changed

5 files changed

+184
-1
lines changed

aos/blueprint.py

+32
Original file line numberDiff line numberDiff line change
@@ -2238,3 +2238,35 @@ def update_fabric_addressing_policy(
22382238

22392239
url = f'/api/blueprints/{bp_id}/fabric-addressing-policy'
22402240
return self.rest.patch(url, data=data)
2241+
2242+
def get_node_relationships(
2243+
self,
2244+
bp_id,
2245+
relationship_type: str = None,
2246+
source_id: str = None,
2247+
target_id: str = None
2248+
):
2249+
"""
2250+
Return node relationships in a given blueprint
2251+
2252+
Parameters
2253+
---------
2254+
bp_id
2255+
(str) - ID of AOS Blueprint
2256+
relationship_type
2257+
(str) - (optional) type of relationship
2258+
source_id
2259+
(str) - (optional) ID of source of relationship
2260+
target_id
2261+
(str) - (optional) ID of target of relationship
2262+
"""
2263+
2264+
url = f'/api/blueprints/{bp_id}/relationships'
2265+
2266+
params = {
2267+
'relationship_type': relationship_type,
2268+
'source_id': source_id,
2269+
'target_id': target_id
2270+
}
2271+
2272+
return self.rest.json_resp_get(url, params=params)['relationships']

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
NAME = "apstra-api-python"
1111

12-
VERSION = '0.2.0'
12+
VERSION = '0.2.1'
1313

1414

1515
REQUIRES = (["requests==2.24.0"],)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"relationships": {
3+
"nnJEIevQlNSjwAgVE3I": {
4+
"tags": null,
5+
"source_id": "y0D9CFzGPmBmGILP3Mk",
6+
"target_id": "C36GOMzvZZW1uQqGQQY",
7+
"property_set": null,
8+
"type": "composed_of_systems",
9+
"id": "nnJEIevQlNSjwAgVE3I"
10+
},
11+
"jbQgo_63gfCxgiKIe6g": {
12+
"tags": null,
13+
"source_id": "Generic_Server_1RU_2x10G_Centos__AOS-2x10-1",
14+
"target_id": "Nw5QmnTrk8-0_5ISLWs",
15+
"property_set": null,
16+
"type": "device_profile",
17+
"id": "jbQgo_63gfCxgiKIe6g"
18+
},
19+
"TqXFFIYLduOVpqW9eU0": {
20+
"tags": null,
21+
"source_id": "xX00o5Alv6f6WGbMprw",
22+
"target_id": "bTqiHdi9nhVWqt1jhUE",
23+
"property_set": null,
24+
"type": "composed_of",
25+
"id": "TqXFFIYLduOVpqW9eU0"
26+
}
27+
}
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"relationships": {
3+
"nnJEIevQlNSjwAgVE3I": {
4+
"tags": null,
5+
"source_id": "y0D9CFzGPmBmGILP3Mk",
6+
"target_id": "C36GOMzvZZW1uQqGQQY",
7+
"property_set": null,
8+
"type": "composed_of_systems",
9+
"id": "nnJEIevQlNSjwAgVE3I"
10+
},
11+
"jbQgo_63gfCxgiKIe6g": {
12+
"tags": null,
13+
"source_id": "Generic_Server_1RU_2x10G_Centos__AOS-2x10-1",
14+
"target_id": "Nw5QmnTrk8-0_5ISLWs",
15+
"property_set": null,
16+
"type": "device_profile",
17+
"id": "jbQgo_63gfCxgiKIe6g"
18+
},
19+
"TqXFFIYLduOVpqW9eU0": {
20+
"tags": null,
21+
"source_id": "xX00o5Alv6f6WGbMprw",
22+
"target_id": "bTqiHdi9nhVWqt1jhUE",
23+
"property_set": null,
24+
"type": "composed_of",
25+
"id": "TqXFFIYLduOVpqW9eU0"
26+
}
27+
}
28+
}

tests/test_blueprint.py

+95
Original file line numberDiff line numberDiff line change
@@ -1623,3 +1623,98 @@ def test_update_fabric_addressing_policy(
16231623
params=None,
16241624
headers=expected_auth_headers,
16251625
)
1626+
1627+
1628+
def test_get_node_relationships(
1629+
aos_logged_in, aos_session, expected_auth_headers, aos_api_version
1630+
):
1631+
bp_id = 'test-bp-1'
1632+
url = f"http://aos:80/api/blueprints/{bp_id}/relationships"
1633+
aos_session.add_response(
1634+
'GET',
1635+
url,
1636+
status=200,
1637+
params={
1638+
'relationship_type': None,
1639+
'source_id': None,
1640+
'target_id': None
1641+
},
1642+
resp=read_fixture(
1643+
f'aos/{aos_api_version}/blueprints/' f'get_relationships.json'
1644+
),
1645+
)
1646+
aos_logged_in.blueprint.get_node_relationships(bp_id=bp_id)
1647+
1648+
aos_session.add_response(
1649+
'GET',
1650+
url,
1651+
status=200,
1652+
params={
1653+
'relationship_type': 'composed_of_systems',
1654+
'source_id': None,
1655+
'target_id': None
1656+
},
1657+
resp=read_fixture(
1658+
f'aos/{aos_api_version}/blueprints/' f'get_relationships.json'
1659+
),
1660+
)
1661+
aos_logged_in.blueprint.get_node_relationships(
1662+
bp_id=bp_id,
1663+
relationship_type='composed_of_systems'
1664+
)
1665+
1666+
aos_session.add_response(
1667+
'GET',
1668+
url,
1669+
status=200,
1670+
params={
1671+
'relationship_type': None,
1672+
'source_id': 'y0D9CFzGPmBmGILP3Mk',
1673+
'target_id': None
1674+
},
1675+
resp=read_fixture(
1676+
f'aos/{aos_api_version}/blueprints/' f'get_relationships.json'
1677+
),
1678+
)
1679+
aos_logged_in.blueprint.get_node_relationships(
1680+
bp_id=bp_id,
1681+
source_id='y0D9CFzGPmBmGILP3Mk'
1682+
)
1683+
1684+
aos_session.add_response(
1685+
'GET',
1686+
url,
1687+
status=200,
1688+
params={
1689+
'relationship_type': None,
1690+
'source_id': None,
1691+
'target_id': 'C36GOMzvZZW1uQqGQQY'
1692+
},
1693+
resp=read_fixture(
1694+
f'aos/{aos_api_version}/blueprints/' f'get_relationships.json'
1695+
),
1696+
)
1697+
aos_logged_in.blueprint.get_node_relationships(
1698+
bp_id=bp_id,
1699+
target_id='C36GOMzvZZW1uQqGQQY'
1700+
)
1701+
1702+
aos_session.add_response(
1703+
'GET',
1704+
url,
1705+
status=200,
1706+
params={
1707+
'relationship_type': 'composed_of_systems',
1708+
'source_id': 'y0D9CFzGPmBmGILP3Mk',
1709+
'target_id': 'C36GOMzvZZW1uQqGQQY'
1710+
},
1711+
resp=read_fixture(
1712+
f'aos/{aos_api_version}/blueprints/' f'get_relationships.json'
1713+
),
1714+
)
1715+
aos_logged_in.blueprint.get_node_relationships(
1716+
bp_id=bp_id,
1717+
relationship_type='composed_of_systems',
1718+
source_id='y0D9CFzGPmBmGILP3Mk',
1719+
target_id='C36GOMzvZZW1uQqGQQY'
1720+
)

0 commit comments

Comments
 (0)