Skip to content

Commit

Permalink
Merge pull request #12 from aitomatic/feat/integrate_deploy_train_furuno
Browse files Browse the repository at this point in the history
Integrate command to trigger Furuno training job
  • Loading branch information
phamhoangtuan committed Apr 23, 2022
2 parents 585b45b + 9600bd2 commit de8c362
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ You will be prompted for a username and password. For the username, use __token_
deactivate
virtualenv .venv-test -p python3
source .venv-test/bin/activate
pip install -i https://test.pypi.org/simple/ aitomatic-cli
pip install -i https://test.pypi.org/simple/ aitomatic
```

## Steps to package and distribute CLI to PyPI
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The Command Line Interface (CLI) to create a project, build an image or deploy a
To install this CLI tool you can run the below command

```shell
pip3 install aitomatic-cli
pip3 install aitomatic
```

Alternatively, you clone this repo and then run this command from within the repository folder
Expand All @@ -25,8 +25,9 @@ Both the above commands would install the package globally and `aito` will be av

## How to use

- `aito login`: Login to Aitomatic account
- `aito app deploy`: Deploy app to Aitomatic cloud
- `aito login`: Login to Aitomatic cloud
- `aito app deploy`: Deploy app to Aitomatic cluster
- `aito app execute <app_name>`: Execute app in Aitomatic cluster

## Feedback

Expand Down
3 changes: 2 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[metadata]
name = aitomatic-cli
name = aitomatic
version = file: version.txt
author = Pham Hoang Tuan
author_email = [email protected]
Expand All @@ -19,6 +19,7 @@ packages =
src
src.app
src.login
src.api
install_requires =
click == 8.0.4
requests == 2.27.1
Expand Down
12 changes: 12 additions & 0 deletions src/api/aitomatic.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,15 @@ def deploy(self, app_id, data):
)

return res

def execute(self, app_id, data):
res = requests.post(
url=f"{self.API_BASE}/app/{app_id}/execute",
data=data,
headers={
'content-type': 'application/x-www-form-urlencoded',
'Authorization': f'Bearer {self.token}',
},
)

return res
22 changes: 22 additions & 0 deletions src/app/execute.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import click
from src.login.main import authenticated
from src.api.aitomatic import AiCloudApi


@click.command()
@click.argument('app_name', type=str)
@click.pass_obj
@authenticated
def execute(obj, app_name):
'''Execute app in Aitomatic cluster'''

click.echo(f'Execute {app_name} app in Aitomatic...')

api = AiCloudApi(token=obj.get("access_token"))
res = api.execute(app_id=app_name, data={"foo": "bar"})

data = res.json()
if data['status'] == 'OK':
click.echo(f'{data["message"]}. Open {data["url"]} for more information')
else:
click.echo(f'{data["message"]}.')
2 changes: 2 additions & 0 deletions src/app/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import click
from src.app.deploy import deploy
from src.app.execute import execute


@click.group()
Expand All @@ -8,3 +9,4 @@ def app():


app.add_command(deploy)
app.add_command(execute)
1 change: 1 addition & 0 deletions src/login/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ def wrapper(obj, *args, **kwargs):
if res.status_code == 200:
f(*args, **kwargs)
else:
click.echo(res.text)
prompt_login()
exit(1)

Expand Down

0 comments on commit de8c362

Please sign in to comment.