Skip to content

Commit

Permalink
add simple cli entrypoints for api functionality
Browse files Browse the repository at this point in the history
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
```
  • Loading branch information
vdloo committed May 25, 2024
1 parent 4aa7ef2 commit 91aaa9e
Show file tree
Hide file tree
Showing 42 changed files with 1,224 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10']
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']

steps:
- uses: actions/checkout@v3
Expand Down
32 changes: 31 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,36 @@ pip install -r requirements/development.txt

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.

## Using the library from the commandline

In the `bin/` directory you'll find entry points to interact with the API directly from the commandline.

See for example:
```bash
$ export PYTHONPATH=.

$ ./bin/get_slas --help
usage: get_slas [-h]

List all available SLAs.

Example:
$ ./bin/get_slas
[
{
"id": 123,
"code": "sla-standard",
"name": "SLA Standard",
"price": 1234,
"billing_period": 1,
"billing_period_unit": "month"
},
...
]

optional arguments:
-h, --help show this help message and exit
```

### Installing the library in your project

Expand Down Expand Up @@ -56,7 +86,7 @@ client.set_app_setting('yourhypernodeappname', 'php_version', '8.1').json()
{'name': 'yourhypernodeappname', 'type': 'persistent', 'php_version': '8.1', ...}
```

To even performing acts of cloud automation, like scaling to the first next larger plan:
You can even perform acts of cloud automation, like scaling to the first next larger plan:
```python
client.xgrade(
'yourhypernodeappname',
Expand Down
1 change: 1 addition & 0 deletions bin/block_attack
14 changes: 14 additions & 0 deletions bin/command
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env python3
import os
import sys
from hypernode_api_python import commands


if __name__ == '__main__':
command = os.path.basename(__file__)

if hasattr(commands, command):
sys.exit(getattr(commands, command)() or 0)
else:
sys.stderr.write("Command '{}' not found in hypernode_api_python.commands\n".format(command))
sys.exit(1)
1 change: 1 addition & 0 deletions bin/get_app_configurations
1 change: 1 addition & 0 deletions bin/get_app_flavor
1 change: 1 addition & 0 deletions bin/get_app_info
1 change: 1 addition & 0 deletions bin/get_available_backups_for_app
1 change: 1 addition & 0 deletions bin/get_block_attack_descriptions
1 change: 1 addition & 0 deletions bin/get_cluster_relations
1 change: 1 addition & 0 deletions bin/get_eav_description
1 change: 1 addition & 0 deletions bin/get_flows
1 change: 1 addition & 0 deletions bin/get_next_best_plan_for_app
1 change: 1 addition & 0 deletions bin/get_product_info
1 change: 1 addition & 0 deletions bin/get_sla
1 change: 1 addition & 0 deletions bin/get_slas
1 change: 1 addition & 0 deletions bin/get_whitelist_options
1 change: 1 addition & 0 deletions bin/get_whitelist_rules
1 change: 1 addition & 0 deletions bin/validate_app_name
12 changes: 11 additions & 1 deletion hypernode_api_python/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ def get_app_eav_description(self):
"""
return self.requests("GET", HYPERNODE_API_APP_EAV_DESCRIPTION_ENDPOINT)

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

def get_cluster_relations(self, app_name):
""" "
"""
List all relations for the specified app. This will return all the
relations that are currently configured for the specified app.
Expand Down Expand Up @@ -579,6 +580,7 @@ def get_whitelist_rules(self, app_name, filter_data=None):
"GET", HYPERNODE_API_WHITELIST_ENDPOINT.format(app_name), filter_data
)

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

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

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

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

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

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

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

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

# TODO: add entrypoint for this method in bin/ and commands.py
def destroy_brancher(self, brancher_name):
"""
Destroy an existing brancher node of your Hypernode.
Expand Down
Loading

0 comments on commit 91aaa9e

Please sign in to comment.