-
Notifications
You must be signed in to change notification settings - Fork 15
Bugfixed/further cli functionality #147
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
Closed
AneequeZubair9
wants to merge
5
commits into
aleph-im:master
from
AneequeZubair9:bugfixed/further_cli_functionality
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
07b78da
Adding 3 volumes
AneequeZubair9 9bcd8fe
fix116/Added volumes
AneequeZubair9 3eb15db
remove the whitespaces and fixed the command line
AneequeZubair9 ec9b384
removed unneccessary files
AneequeZubair9 e705e4a
Added more functionality for cli parameters
AneequeZubair9 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,15 +1,3 @@ | ||||||
| import typer | ||||||
| from typing import Optional, Dict, List | ||||||
| from aleph_client.types import AccountFromPrivateKey | ||||||
| from aleph_client.account import _load_account | ||||||
| from aleph_client.conf import settings | ||||||
| from pathlib import Path | ||||||
| import asyncio | ||||||
| from aleph_client import synchronous | ||||||
| import json | ||||||
| from zipfile import BadZipFile | ||||||
| from aleph_client.commands import help_strings | ||||||
|
|
||||||
| import asyncio | ||||||
| import json | ||||||
| import logging | ||||||
|
|
@@ -19,19 +7,18 @@ | |||||
| from zipfile import BadZipFile | ||||||
|
|
||||||
| import typer | ||||||
| from aleph_message.models import ( | ||||||
| ProgramMessage, | ||||||
| StoreMessage, | ||||||
| ) | ||||||
|
|
||||||
| from aleph_client.types import AccountFromPrivateKey | ||||||
| from aleph_client import synchronous | ||||||
| from aleph_client.account import _load_account | ||||||
| from aleph_client.commands import help_strings | ||||||
| from aleph_client.commands.utils import volume_to_dict | ||||||
| from aleph_client.conf import settings | ||||||
| from aleph_client.types import AccountFromPrivateKey | ||||||
| from aleph_client.utils import create_archive | ||||||
|
|
||||||
| logger = logging.getLogger(__name__) | ||||||
| app = typer.Typer() | ||||||
|
|
||||||
|
|
||||||
| from aleph_client.asynchronous import ( | ||||||
| get_fallback_session, | ||||||
| StorageEnum, | ||||||
|
|
@@ -56,35 +43,67 @@ | |||||
|
|
||||||
| @app.command() | ||||||
| def upload( | ||||||
| path: Path = typer.Argument(..., help="Path to your source code"), | ||||||
| entrypoint: str = typer.Argument(..., help="Your program entrypoint"), | ||||||
| channel: str = typer.Option(settings.DEFAULT_CHANNEL, help=help_strings.CHANNEL), | ||||||
| memory: int = typer.Option( | ||||||
| settings.DEFAULT_VM_MEMORY, help="Maximum memory allocation on vm in MiB" | ||||||
| ), | ||||||
| vcpus: int = typer.Option( | ||||||
| settings.DEFAULT_VM_VCPUS, help="Number of virtual cpus to allocate." | ||||||
| ), | ||||||
| timeout_seconds: float = typer.Option( | ||||||
| settings.DEFAULT_VM_TIMEOUT, | ||||||
| help="If vm is not called after [timeout_seconds] it will shutdown", | ||||||
| ), | ||||||
| private_key: Optional[str] = typer.Option( | ||||||
| settings.PRIVATE_KEY_STRING, help=help_strings.PRIVATE_KEY | ||||||
| ), | ||||||
| private_key_file: Optional[Path] = typer.Option( | ||||||
| settings.PRIVATE_KEY_FILE, help=help_strings.PRIVATE_KEY_FILE | ||||||
| ), | ||||||
| print_messages: bool = typer.Option(False), | ||||||
| print_code_message: bool = typer.Option(False), | ||||||
| print_program_message: bool = typer.Option(False), | ||||||
| runtime: str = typer.Option( | ||||||
| None, | ||||||
| help="Hash of the runtime to use for your program. Defaults to aleph debian with Python3.8 and node. You can also create your own runtime and pin it", | ||||||
| ), | ||||||
| beta: bool = typer.Option(False), | ||||||
| debug: bool = False, | ||||||
| persistent: bool = False, | ||||||
| path: Path = typer.Argument(..., help="Path to your source code"), | ||||||
| entrypoint: str = typer.Argument(..., help="Your program entrypoint"), | ||||||
| channel: str = typer.Option(settings.DEFAULT_CHANNEL, help=help_strings.CHANNEL), | ||||||
| memory: int = typer.Option( | ||||||
| settings.DEFAULT_VM_MEMORY, help="Maximum memory allocation on vm in MiB" | ||||||
| ), | ||||||
| allow_amend: bool = typer.Option(False, help='Deployed VM image may be changed and deployed on the same URL'), | ||||||
| use_latest: bool = typer.Option(True, help='Use latest version of the base docker image'), | ||||||
| reproducible: bool = typer.Option(False, help=' (Not Implemented)--> Check output is same for other nodes'), | ||||||
| internet: bool = typer.Option(True, help='VM should have internet connectivity'), | ||||||
| aleph_api: bool = typer.Option(True, help='VM needs access to Aleph messages AP'), | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| vcpus: int = typer.Option( | ||||||
| settings.DEFAULT_VM_VCPUS, help="Number of virtual CPUS to allocate." | ||||||
| ), | ||||||
| timeout_seconds: float = typer.Option( | ||||||
| settings.DEFAULT_VM_TIMEOUT, | ||||||
| help="If vm is not called after [timeout_seconds] it will shutdown", | ||||||
| ), | ||||||
| private_key: Optional[str] = typer.Option( | ||||||
| settings.PRIVATE_KEY_STRING, help=help_strings.PRIVATE_KEY | ||||||
| ), | ||||||
| private_key_file: Optional[Path] = typer.Option( | ||||||
| settings.PRIVATE_KEY_FILE, help=help_strings.PRIVATE_KEY_FILE | ||||||
| ), | ||||||
| print_messages: bool = typer.Option(False), | ||||||
| print_code_message: bool = typer.Option(False), | ||||||
| print_program_message: bool = typer.Option(False), | ||||||
| runtime: str = typer.Option( | ||||||
| None, | ||||||
| help="Hash of the runtime to use for your program. Defaults to aleph debian with Python3.8 and node. You can also create your own runtime and pin it", | ||||||
| ), | ||||||
| beta: bool = typer.Option(False), | ||||||
|
|
||||||
| debug: bool = False, | ||||||
| persistent: bool = False, | ||||||
| persistent_volume: Optional[List[str]] = typer.Option( | ||||||
| None, | ||||||
| help='''Takes 3 parameters | ||||||
| A persistent volume is allocated on the host machine at any time | ||||||
| eg: Use , to seperate the parameters and no spaces | ||||||
| --persistent_volume persistence=host,name=my-volume,size=100 ./my-program main:app | ||||||
| '''), | ||||||
|
|
||||||
| ephemeral_volume: Optional[List[str]] = typer.Option( | ||||||
| None, | ||||||
| help= | ||||||
| '''Takes 1 parameter Only | ||||||
| Ephemeral volumes can move and be removed by the host,Garbage collected basically, when the VM isn't running | ||||||
| eg: Use , to seperate the parameters and no spaces | ||||||
| --ephemeral-volume size_mib=100 ./my-program main:app '''), | ||||||
|
|
||||||
| immutable_volume: Optional[List[str]] = typer.Option( | ||||||
| None, | ||||||
| help= | ||||||
| '''Takes 3 parameters | ||||||
| Immutable volume is one whose contents do not change | ||||||
| eg: Use , to seperate the parameters and no spaces | ||||||
| --immutable-volume ref=25a393222692c2f73489dc6710ae87605a96742ceef7b91de4d7ec34bb688d94,use_latest=true,mount=/mnt/volume ./my-program main:app | ||||||
| ''' | ||||||
| ) | ||||||
|
|
||||||
| ): | ||||||
| """Register a program to run on Aleph.im virtual machines from a zip archive.""" | ||||||
|
|
||||||
|
|
@@ -104,15 +123,30 @@ def upload( | |||||
| account: AccountFromPrivateKey = _load_account(private_key, private_key_file) | ||||||
|
|
||||||
| runtime = ( | ||||||
| runtime | ||||||
| or input(f"Ref of runtime ? [{settings.DEFAULT_RUNTIME_ID}] ") | ||||||
| or settings.DEFAULT_RUNTIME_ID | ||||||
| runtime | ||||||
| or input(f"Ref of runtime ? [{settings.DEFAULT_RUNTIME_ID}] ") | ||||||
| or settings.DEFAULT_RUNTIME_ID | ||||||
| ) | ||||||
|
|
||||||
| volumes = [] | ||||||
| for volume in prompt_for_volumes(): | ||||||
| volumes.append(volume) | ||||||
| typer.echo("\n") | ||||||
|
|
||||||
| # Check if the volumes are empty | ||||||
| if persistent_volume is None or ephemeral_volume is None or immutable_volume is None: | ||||||
| for volume in prompt_for_volumes(): | ||||||
| volumes.append(volume) | ||||||
| typer.echo("\n") | ||||||
|
|
||||||
| # else Parse all the volumes that have passed as the cli parameters and put it into volume list | ||||||
| else: | ||||||
| if len(persistent_volume) > 0: | ||||||
| persistent_volume_dict = volume_to_dict(volume=persistent_volume) | ||||||
| volumes.append(persistent_volume_dict) | ||||||
| if len(ephemeral_volume) > 0: | ||||||
| ephemeral_volume_dict = volume_to_dict(volume=ephemeral_volume) | ||||||
| volumes.append(ephemeral_volume_dict) | ||||||
| if len(immutable_volume) > 0: | ||||||
| immutable_volume_dict = volume_to_dict(volume=immutable_volume) | ||||||
| volumes.append(immutable_volume_dict) | ||||||
|
|
||||||
| subscriptions: Optional[List[Dict]] | ||||||
| if beta and yes_no_input("Subscribe to messages ?", default=False): | ||||||
|
|
@@ -156,6 +190,11 @@ def upload( | |||||
| program_ref=program_ref, | ||||||
| entrypoint=entrypoint, | ||||||
| runtime=runtime, | ||||||
| allow_amend=allow_amend, | ||||||
| use_latest=use_latest, | ||||||
| reproducible=reproducible, | ||||||
| internet=internet, | ||||||
| aleph_api=aleph_api, | ||||||
| storage_engine=StorageEnum.storage, | ||||||
| channel=channel, | ||||||
| memory=memory, | ||||||
|
|
@@ -189,12 +228,12 @@ def upload( | |||||
|
|
||||||
| @app.command() | ||||||
| def update( | ||||||
| hash: str, | ||||||
| path: Path, | ||||||
| private_key: Optional[str] = settings.PRIVATE_KEY_STRING, | ||||||
| private_key_file: Optional[Path] = settings.PRIVATE_KEY_FILE, | ||||||
| print_message: bool = True, | ||||||
| debug: bool = False, | ||||||
| hash: str, | ||||||
| path: Path, | ||||||
| private_key: Optional[str] = settings.PRIVATE_KEY_STRING, | ||||||
| private_key_file: Optional[Path] = settings.PRIVATE_KEY_FILE, | ||||||
| print_message: bool = True, | ||||||
| debug: bool = False, | ||||||
| ): | ||||||
| """Update the code of an existing program""" | ||||||
|
|
||||||
|
|
@@ -252,10 +291,10 @@ def update( | |||||
|
|
||||||
| @app.command() | ||||||
| def unpersist( | ||||||
| hash: str, | ||||||
| private_key: Optional[str] = settings.PRIVATE_KEY_STRING, | ||||||
| private_key_file: Optional[Path] = settings.PRIVATE_KEY_FILE, | ||||||
| debug: bool = False, | ||||||
| hash: str, | ||||||
| private_key: Optional[str] = settings.PRIVATE_KEY_STRING, | ||||||
| private_key_file: Optional[Path] = settings.PRIVATE_KEY_FILE, | ||||||
| debug: bool = False, | ||||||
| ): | ||||||
| """Stop a persistent virtual machine by making it non-persistent""" | ||||||
|
|
||||||
|
|
||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same goes for formatting here