Skip to content

Commit

Permalink
feat: add report feature
Browse files Browse the repository at this point in the history
  • Loading branch information
guptadev21 committed Oct 17, 2024
1 parent c994e2e commit a7b9b8c
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
2 changes: 2 additions & 0 deletions riocli/device/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from riocli.device.list import list_devices
from riocli.device.migrate import migrate_project
from riocli.device.onboard import device_onboard
from riocli.device.report import report_device
from riocli.device.tools import tools
from riocli.device.topic import device_topics
from riocli.device.vpn import toggle_vpn
Expand Down Expand Up @@ -54,6 +55,7 @@ def device():
device.add_command(inspect_device)
device.add_command(list_deployments)
device.add_command(list_devices)
device.add_command(report_device)
device.add_command(tools)
device.add_command(toggle_vpn)
device.add_command(migrate_project)
48 changes: 48 additions & 0 deletions riocli/device/report.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# 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.


# from datetime import datetime, timedelta

import click
from click_help_colors import HelpColorsGroup

from riocli.config import new_client
from riocli.constants import Colors
from riocli.utils import tabulate_data
from riocli.device.util import report_device_api_call, find_device_guid


@click.command(
'report',
cls=HelpColorsGroup,
help_headers_color=Colors.YELLOW,
help_options_color=Colors.GREEN,
)
@click.argument('device-name', type=str)
def report_device(device_name: str) -> None:
"""
Report a device and get its debug logs in uploads section.
"""
try:
# client = new_client()
device_guid = find_device_guid(device_name)
# device = client.get_device(device_id=device_guid)
# tabulate_data(device, ["Device"])
# response = report_device_api_call(device_guid=device_guid)
# click.echo(response, color=Colors.GREEN)
click.echo(f"Device {device_name} {device_guid} reported successfully.")

except Exception as e:
click.secho(str(e), fg=Colors.RED)
24 changes: 24 additions & 0 deletions riocli/device/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,30 @@ def decorated(**kwargs: typing.Any):
return decorated


def report_device_api_call(device_guid: str) -> typing.Dict:
config = Configuration()
coreapi_host = config.data.get(
'core_api_host', 'https://gaapiserver.apps.okd4v2.prod.rapyuta.io'
)

url = '{}/api/device-manager/v0/error_handler/upload_debug_logs/{}'.format(
coreapi_host, device_guid
)

headers = config.get_auth_header()
response = (
RestClient(url).method(HttpMethod.POST).headers(headers).execute(payload={})
)

data = response.json()

if not response.ok:
err_msg = data.get('error')
raise Exception(err_msg)

return data


def get_device_name(client: Client, guid: str) -> str:
device = client.get_device(device_id=guid)
return device.name
Expand Down

0 comments on commit a7b9b8c

Please sign in to comment.