Skip to content

add simple cli entrypoints for api functionality #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 support@hypernode.com. 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
1 change: 1 addition & 0 deletions bin/check_payment_information_for_app
1 change: 1 addition & 0 deletions bin/check_xgrade
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/create_brancher
1 change: 1 addition & 0 deletions bin/destroy_brancher
1 change: 1 addition & 0 deletions bin/get_active_branchers
1 change: 1 addition & 0 deletions bin/get_active_products
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_current_product_for_app
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
1 change: 1 addition & 0 deletions bin/xgrade
4 changes: 3 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 @@ -780,6 +781,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 Down
Loading
Loading