Skip to content
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

feat(hwil): implements hwil command #319

Merged
merged 2 commits into from
Jun 14, 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
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ python-benedict = ">=0.33.2"
etcd3gw = ">=2.4.0"
graphviz = ">=0.20.3"
python-magic = ">=0.4.27"
paramiko = "3.4.0"

[requires]
python_version = "3"
175 changes: 168 additions & 7 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions docs/source/hwil.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Hardware-in-Loop
================

.. toctree::
:maxdepth: 3
:caption: Contents:

.. click:: riocli.hwil:hwildevice
:prog: rio hwil
:nested: full
1 change: 1 addition & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ Rapyuta CLI has commands for all rapyuta.io resources. You can read more about t
Deployment <deployment>
Device <device>
Disk <disk>
Hardware-in-Loop <hwil>
ManagedService <managedservice>
Network <network>
Organization <organization>
Expand Down
2 changes: 2 additions & 0 deletions riocli/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from riocli.completion import completion
from riocli.config import Configuration
from riocli.configtree import config_trees
from riocli.hwil import hwildevice
from riocli.constants import Colors, Symbols
from riocli.deployment import deployment
from riocli.device import device
Expand Down Expand Up @@ -138,3 +139,4 @@ def update(silent: bool) -> None:
cli.add_command(vpn)
cli.add_command(usergroup)
cli.add_command(config_trees)
cli.add_command(hwildevice)
7 changes: 7 additions & 0 deletions riocli/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ def new_v2_client(config_inst: Configuration = None, with_project: bool = True):
return config_inst.new_v2_client(with_project=with_project)


def new_hwil_client(config_inst: Configuration = None):
if not config_inst:
config_inst = Configuration()

return config_inst.new_hwil_client()


def get_config_from_context(ctx: click.Context) -> Configuration:
config_obj = ctx.obj

Expand Down
15 changes: 13 additions & 2 deletions riocli/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
from click import get_app_dir
from rapyuta_io import Client

from riocli.exceptions import LoggedOut, NoOrganizationSelected, NoProjectSelected
from riocli.exceptions import LoggedOut, NoOrganizationSelected, NoProjectSelected, HwilLoggedOut
from riocli.hwilclient import Client as HwilClient
from riocli.v2client import Client as v2Client


Expand All @@ -48,7 +49,6 @@ def __init__(self, filepath: Optional[str] = None):
self._filepath = filepath
self.exists = True


# If config file does not exist, then initialize an empty dictionary instead.
if not os.path.exists(self.filepath):
self.exists = False
Expand Down Expand Up @@ -109,6 +109,17 @@ def new_v2_client(self: Configuration, with_project: bool = True) -> v2Client:

return v2Client(self, auth_token=token, project=project)

def new_hwil_client(self: Configuration) -> HwilClient:
if 'hwil_auth_token' not in self.data:
raise HwilLoggedOut

if 'environment' in self.data:
os.environ['RIO_CONFIG'] = self.filepath

token = self.data.get('hwil_auth_token', None)

return HwilClient(auth_token=token)

def get_auth_header(self: Configuration) -> dict:
if not ('auth_token' in self.data and 'project_id' in self.data):
raise LoggedOut
Expand Down
8 changes: 8 additions & 0 deletions riocli/exceptions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,11 @@ def __str__(self):
return """Not logged in. Please login first
$ rio auth login
"""


class HwilLoggedOut(Exception):

def __str__(self):
return """Not logged in to HWIL. Please login first
$ rio hwil login
"""
45 changes: 45 additions & 0 deletions riocli/hwil/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copyright 2024 Rapyuta Robotics
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import click
from click_help_colors import HelpColorsGroup

from riocli.constants import Colors
from riocli.hwil.create import create_device
from riocli.hwil.delete import delete_device
from riocli.hwil.execute import execute
from riocli.hwil.inspect import inspect_device
from riocli.hwil.list import list_devices
from riocli.hwil.login import login
from riocli.hwil.ssh import ssh


@click.group(
name="hwil",
invoke_without_command=False,
cls=HelpColorsGroup,
help_headers_color=Colors.YELLOW,
help_options_color=Colors.GREEN,
)
def hwildevice():
"""Manage Hardware-in-the-Loop (HWIL) devices"""
pass


hwildevice.add_command(login)
hwildevice.add_command(create_device)
hwildevice.add_command(list_devices)
hwildevice.add_command(delete_device)
hwildevice.add_command(inspect_device)
hwildevice.add_command(execute)
hwildevice.add_command(ssh)
Loading
Loading