Skip to content

Commit 8cb5203

Browse files
committed
add get_cluster_relations to api client
looks like: ``` In [1]: from hypernode_api_python.client import HypernodeAPIPython In [2]: import os In [3]: client = HypernodeAPIPython(os.environ['MYSECRETAPITOKEN']) In [4]: client.get_cluster_relations("mytestappweb").json() Out[4]: {'parents': [{'id': 182, 'parent': 'mytestappdb', 'child': 'mytestappweb', 'relation_type': 'mysql', 'cluster_description': None}, {'id': 180, 'parent': 'mytestapp', 'child': 'mytestappweb', 'relation_type': 'loadbalancer', 'cluster_description': None}, {'id': 181, 'parent': 'mytestapp', 'child': 'mytestappweb', 'relation_type': 'nfs', 'cluster_description': None}], 'children': []} ```
1 parent 37a1f89 commit 8cb5203

2 files changed

Lines changed: 57 additions & 0 deletions

File tree

hypernode_api_python/client.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
HYPERNODE_API_ADDON_SLA_LIST_ENDPOINT = "/v2/addon/slas/"
66
HYPERNODE_API_APP_CHECK_PAYMENT_INFORMATION = "/v2/app/{}/check-payment-information/"
77
HYPERNODE_API_APP_CONFIGURATION_ENDPOINT = "/v2/configuration/"
8+
HYPERNODE_API_APP_CLUSTER_RELATIONS = "/v2/app/{}/relations/"
89
HYPERNODE_API_APP_DETAIL_ENDPOINT = "/v2/app/{}/?destroyed=false"
910
HYPERNODE_API_APP_DETAIL_WITH_ADDONS_ENDPOINT = "/v2/app/{}/with_addons?destroyed=false"
1011
HYPERNODE_API_APP_EAV_DESCRIPTION_ENDPOINT = "/v2/app/eav_descriptions/"
@@ -365,6 +366,34 @@ def get_app_configurations(self):
365366
"""
366367
return self.requests("GET", HYPERNODE_API_APP_CONFIGURATION_ENDPOINT)
367368

369+
def get_cluster_relations(self, app_name):
370+
""" "
371+
List all relations for the specified app. This will return all the
372+
relations that are currently configured for the specified app.
373+
374+
Example:
375+
> client.get_cluster_relations('mytestappweb').json()
376+
> {'children': [],
377+
> 'parents': [{'child': 'mytestappweb',
378+
> 'cluster_description': None,
379+
> 'id': 182,
380+
> 'parent': 'mytestappdb',
381+
> 'relation_type': 'mysql'},
382+
> {'child': 'mytestappweb',
383+
> 'cluster_description': None,
384+
> 'id': 180,
385+
> 'parent': 'mytestapp',
386+
> 'relation_type': 'loadbalancer'},
387+
> {'child': 'mytestappweb',
388+
> 'cluster_description': None,
389+
> 'id': 181,
390+
> 'parent': 'mytestapp',
391+
> 'relation_type': 'nfs'}]}
392+
"""
393+
return self.requests(
394+
"GET", HYPERNODE_API_APP_CLUSTER_RELATIONS.format(app_name)
395+
)
396+
368397
def get_product_info_with_price(self, product_code, error_to_raise=None):
369398
"""
370399
Get information about a specific product
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from unittest.mock import Mock
2+
3+
from tests.testcase import TestCase
4+
from hypernode_api_python.client import (
5+
HypernodeAPIPython,
6+
HYPERNODE_API_APP_CLUSTER_RELATIONS,
7+
)
8+
9+
10+
class TestGetClusterRelations(TestCase):
11+
def setUp(self):
12+
self.mock_request = Mock()
13+
self.client = HypernodeAPIPython(token="mytoken")
14+
self.client.requests = self.mock_request
15+
16+
def test_calls_hypernode_api_cluster_relations_endpoint_with_correct_parameters(
17+
self,
18+
):
19+
self.client.get_cluster_relations("yourhypernodeappname")
20+
21+
self.mock_request.assert_called_once_with(
22+
"GET", HYPERNODE_API_APP_CLUSTER_RELATIONS.format("yourhypernodeappname")
23+
)
24+
25+
def test_returns_result_for_hypernode_api_cluster_relations(self):
26+
ret = self.client.get_cluster_relations("yourhypernodeappname")
27+
28+
self.assertEqual(ret, self.mock_request.return_value)

0 commit comments

Comments
 (0)