Skip to content

Commit 8dada70

Browse files
committed
add simple cli entrypoints for api functionality
like: ``` $ ls bin/ block_attack get_app_flavor get_block_attack_descriptions get_flows get_sla get_whitelist_rules command get_app_info get_cluster_relations get_next_best_plan_for_app get_slas validate_app_name get_app_configurations get_available_backups_for_app get_eav_description get_product_info get_whitelist_options hypernode-api-python]$ ./bin/get_sla --help usage: get_sla [-h] sla_code Get a specific SLA. $ ./bin/get_sla sla-standard { "id": 123, "code": "sla-standard", "name": "SLA Standard", "price": 1234, "billing_period": 1, "billing_period_unit": "month" } positional arguments: sla_code The code of the SLA to get optional arguments: -h, --help show this help message and exit ```
1 parent 4aa7ef2 commit 8dada70

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1222
-3
lines changed

.github/workflows/test.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
runs-on: ubuntu-latest
99
strategy:
1010
matrix:
11-
python-version: ['3.7', '3.8', '3.9', '3.10']
11+
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
1212

1313
steps:
1414
- uses: actions/checkout@v3

README.md

+29
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,35 @@ pip install -r requirements/development.txt
1818

1919
Each Hypernode has an API token associated with it, you can use that to talk to the API directly. You can find the token in `/etc/hypernode/hypernode_api_token`. For API tokens with special permissions please contact [email protected]. Not all functionality in the API is currently generally available but if you'd like to start automating and have an interesting use-case we'd love to hear from you.
2020

21+
## Using the library from the commandline
22+
23+
In the `bin/` directory you'll find entrypoints to interact with the API directly from the commandline.
24+
25+
See for example:
26+
```bash
27+
$ export PYTHONPATH=.
28+
$ ./bin/get_slas --help
29+
usage: get_slas [-h]
30+
31+
List all available SLAs.
32+
33+
Example:
34+
$ ./bin/get_slas
35+
[
36+
{
37+
"id": 123,
38+
"code": "sla-standard",
39+
"name": "SLA Standard",
40+
"price": 1234,
41+
"billing_period": 1,
42+
"billing_period_unit": "month"
43+
},
44+
...
45+
]
46+
47+
optional arguments:
48+
-h, --help show this help message and exit
49+
```
2150

2251
### Installing the library in your project
2352

bin/block_attack

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
command

bin/command

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env python3
2+
import os
3+
import sys
4+
from hypernode_api_python import commands
5+
6+
7+
if __name__ == '__main__':
8+
command = os.path.basename(__file__)
9+
10+
if hasattr(commands, command):
11+
sys.exit(getattr(commands, command)() or 0)
12+
else:
13+
sys.stderr.write("Command '{}' not found in hypernode_api_python.commands\n".format(command))
14+
sys.exit(1)

bin/get_app_configurations

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
command

bin/get_app_flavor

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
command

bin/get_app_info

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
command

bin/get_available_backups_for_app

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
command

bin/get_block_attack_descriptions

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
command

bin/get_cluster_relations

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
command

bin/get_eav_description

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
command

bin/get_flows

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
command

bin/get_next_best_plan_for_app

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
command

bin/get_product_info

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
command

bin/get_sla

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
command

bin/get_slas

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
command

bin/get_whitelist_options

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
command

bin/get_whitelist_rules

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
command

bin/validate_app_name

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
command

hypernode_api_python/client.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ def get_app_eav_description(self):
331331
"""
332332
return self.requests("GET", HYPERNODE_API_APP_EAV_DESCRIPTION_ENDPOINT)
333333

334+
# TODO: add entrypoint for this method in bin/ and commands.py
334335
def set_app_setting(self, app_name, attribute, value):
335336
"""
336337
Update a setting on the app, like the PHP or MySQL version. See
@@ -384,7 +385,7 @@ def get_app_configurations(self):
384385
return self.requests("GET", HYPERNODE_API_APP_CONFIGURATION_ENDPOINT)
385386

386387
def get_cluster_relations(self, app_name):
387-
""" "
388+
"""
388389
List all relations for the specified app. This will return all the
389390
relations that are currently configured for the specified app.
390391
@@ -579,6 +580,7 @@ def get_whitelist_rules(self, app_name, filter_data=None):
579580
"GET", HYPERNODE_API_WHITELIST_ENDPOINT.format(app_name), filter_data
580581
)
581582

583+
# TODO: add entrypoint for this method in bin/ and commands.py
582584
def get_current_product_for_app(self, app_name):
583585
"""
584586
Retrieve information about the product the specified App is currently on.
@@ -647,6 +649,7 @@ def get_current_product_for_app(self, app_name):
647649
"GET", HYPERNODE_API_PRODUCT_APP_DETAIL_ENDPOINT.format(app_name)
648650
)
649651

652+
# TODO: add entrypoint for this method in bin/ and commands.py
650653
def check_payment_information_for_app(self, app_name):
651654
"""
652655
Get the payment information that is currently configured for this Hypernode
@@ -664,6 +667,7 @@ def check_payment_information_for_app(self, app_name):
664667
"GET", HYPERNODE_API_APP_CHECK_PAYMENT_INFORMATION.format(app_name)
665668
)
666669

670+
# TODO: add entrypoint for this method in bin/ and commands.py
667671
def get_active_products(self):
668672
"""
669673
Retrieve the list of products that are currently available. You can
@@ -731,6 +735,7 @@ def get_active_products(self):
731735
"""
732736
return self.requests("GET", HYPERNODE_API_PRODUCT_LIST_ENDPOINT)
733737

738+
# TODO: add entrypoint for this method in bin/ and commands.py
734739
def check_xgrade(self, app_name, product_code):
735740
"""
736741
Checks if the Hypernode 'is going to fit' on the new product. Retrieves some
@@ -759,6 +764,7 @@ def check_xgrade(self, app_name, product_code):
759764
HYPERNODE_API_APP_XGRADE_CHECK_ENDPOINT.format(app_name, product_code),
760765
)
761766

767+
# TODO: add entrypoint for this method in bin/ and commands.py
762768
def xgrade(self, app_name, data):
763769
"""
764770
Change the product of a Hypernode to a different plan. This will initiate
@@ -780,6 +786,7 @@ def xgrade(self, app_name, data):
780786
"PATCH", HYPERNODE_API_APP_XGRADE_ENDPOINT.format(app_name), data=data
781787
)
782788

789+
# TODO: add entrypoint for this method in bin/ and commands.py
783790
def order_hypernode(self, data):
784791
"""
785792
Orders a new Hypernode. Note that you can not do this with the API permissions
@@ -799,6 +806,7 @@ def order_hypernode(self, data):
799806
"""
800807
return self.requests("POST", HYPERNODE_API_APP_ORDER_ENDPOINT, data=data)
801808

809+
# TODO: add entrypoint for this method in bin/ and commands.py
802810
def get_active_branchers(self, app_name):
803811
"""
804812
List all active brancher nodes of your Hypernode.
@@ -838,6 +846,7 @@ def get_active_branchers(self, app_name):
838846
"GET", HYPERNODE_API_BRANCHER_APP_ENDPOINT.format(app_name)
839847
)
840848

849+
# TODO: add entrypoint for this method in bin/ and commands.py
841850
def create_brancher(self, app_name, data):
842851
"""
843852
Create a new branch (server replica) of your Hypernode.
@@ -851,6 +860,7 @@ def create_brancher(self, app_name, data):
851860
"POST", HYPERNODE_API_BRANCHER_APP_ENDPOINT.format(app_name), data=data
852861
)
853862

863+
# TODO: add entrypoint for this method in bin/ and commands.py
854864
def destroy_brancher(self, brancher_name):
855865
"""
856866
Destroy an existing brancher node of your Hypernode.

0 commit comments

Comments
 (0)