Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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 pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ classifiers = [
]

dependencies = [
"aleph-sdk-python>=1.0.0rc1",
"aleph-sdk-python@git+https://github.com/aleph-im/aleph-sdk-python.git@1yam-vm-client#egg=aleph-sdk-python", # need revert before merge
"aleph-message>=0.4.6",
"aiohttp==3.9.5",
"typer==0.12.3",
Expand Down
126 changes: 125 additions & 1 deletion src/aleph_client/commands/instance/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
from aiohttp import ClientResponseError, ClientSession
from aleph.sdk import AlephHttpClient, AuthenticatedAlephHttpClient
from aleph.sdk.account import _load_account
from aleph.sdk.client.vmclient import VmClient
from aleph.sdk.conf import settings as sdk_settings
from aleph.sdk.exceptions import (
ForgottenMessageError,
InsufficientFundsError,
MessageNotFoundError,
)
from aleph.sdk.query.filters import MessageFilter
from aleph.sdk.types import AccountFromPrivateKey, StorageEnum
from aleph.sdk.types import Account, AccountFromPrivateKey, StorageEnum
from aleph_message.models import InstanceMessage, StoreMessage
from aleph_message.models.base import Chain, MessageType
from aleph_message.models.execution.base import Payment, PaymentType
Expand Down Expand Up @@ -321,3 +322,126 @@ async def list(
# Since we filtered on message type, we can safely cast as InstanceMessage.
messages = cast(List[InstanceMessage], resp.messages)
await _show_instances(messages)


@app.command()
async def expire(
vm_id: str,
domain: str,
private_key: Optional[str] = typer.Option(sdk_settings.PRIVATE_KEY_STRING, help=help_strings.PRIVATE_KEY),
private_key_file: Optional[Path] = typer.Option(sdk_settings.PRIVATE_KEY_FILE, help=help_strings.PRIVATE_KEY_FILE),
debug: bool = False,
):
"""expire an instance"""

setup_logging(debug)
account = _load_account(private_key, private_key_file)

async with VmClient(account, domain) as manager:
status, result = await manager.expire_instance(vm_id=vm_id)
if status != 200:
typer.echo(f"Status : {status}")
typer.echo(result)


@app.command()
async def erase(
vm_id: str,
domain: str,
private_key: Optional[str] = typer.Option(sdk_settings.PRIVATE_KEY_STRING, help=help_strings.PRIVATE_KEY),
private_key_file: Optional[Path] = typer.Option(sdk_settings.PRIVATE_KEY_FILE, help=help_strings.PRIVATE_KEY_FILE),
debug: bool = False,
):
"""erase an instance"""

setup_logging(debug)

account = _load_account(private_key, private_key_file)

async with VmClient(account, domain) as manager:
status, result = await manager.erase_instance(vm_id=vm_id)
if status != 200:
typer.echo(f"Status : {status}")
typer.echo(result)


@app.command()
async def reboot(
vm_id: str,
domain: str,
private_key: Optional[str] = typer.Option(sdk_settings.PRIVATE_KEY_STRING, help=help_strings.PRIVATE_KEY),
private_key_file: Optional[Path] = typer.Option(sdk_settings.PRIVATE_KEY_FILE, help=help_strings.PRIVATE_KEY_FILE),
debug: bool = False,
):
"""reboot an instance"""

setup_logging(debug)

account = _load_account(private_key, private_key_file)

async with VmClient(account, domain) as manager:
status, result = await manager.reboot_instance(vm_id=vm_id)
if status != 200:
typer.echo(f"Status : {status}")
typer.echo(result)


@app.command()
async def notify(
vm_id: str,
domain: str,
private_key: Optional[str] = typer.Option(sdk_settings.PRIVATE_KEY_STRING, help=help_strings.PRIVATE_KEY),
private_key_file: Optional[Path] = typer.Option(sdk_settings.PRIVATE_KEY_FILE, help=help_strings.PRIVATE_KEY_FILE),
debug: bool = False,
):
"""notify crn the instance, can be use to start VM"""

setup_logging(debug)

account = _load_account(private_key, private_key_file)

async with VmClient(account, domain) as manager:
status, result = await manager.start_instance(vm_id=vm_id)
if status != 200:
typer.echo(f"Status : {status}")
typer.echo(result)


@app.command()
async def logs(
vm_id: str,
domain: str,
private_key: Optional[str] = typer.Option(sdk_settings.PRIVATE_KEY_STRING, help=help_strings.PRIVATE_KEY),
private_key_file: Optional[Path] = typer.Option(sdk_settings.PRIVATE_KEY_FILE, help=help_strings.PRIVATE_KEY_FILE),
debug: bool = False,
):
"""logs of the instance"""

setup_logging(debug)

account = _load_account(private_key, private_key_file)

async with VmClient(account, domain) as manager:
async for log in manager.get_logs(vm_id=vm_id):
typer.echo(f"{log}")


@app.command()
async def stop(
vm_id: str,
domain: str,
private_key: Optional[str] = typer.Option(sdk_settings.PRIVATE_KEY_STRING, help=help_strings.PRIVATE_KEY),
private_key_file: Optional[Path] = typer.Option(sdk_settings.PRIVATE_KEY_FILE, help=help_strings.PRIVATE_KEY_FILE),
debug: bool = False,
):
"""Stop an instance"""

setup_logging(debug)

account = _load_account(private_key, private_key_file)

async with VmClient(account, domain) as manager:
status, result = await manager.stop_instance(vm_id=vm_id)
if status != 200:
typer.echo(f"Status : {status}")
typer.echo(result)