From b10301afae712f9f3f2a831236e3f4e749bcdd88 Mon Sep 17 00:00:00 2001 From: Pallab Pain Date: Fri, 22 Nov 2024 09:46:37 +0530 Subject: [PATCH] feat: adds option for virtual device expiry (#387) Fixes AB#39668 --- riocli/apply/manifests/device.yaml | 1 + riocli/device/util.py | 1 + riocli/hwil/create.py | 18 ++++++++++++++---- riocli/jsonschema/schemas/device-schema.yaml | 4 ++++ 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/riocli/apply/manifests/device.yaml b/riocli/apply/manifests/device.yaml index 7e57b8b0..d9ab273d 100644 --- a/riocli/apply/manifests/device.yaml +++ b/riocli/apply/manifests/device.yaml @@ -70,6 +70,7 @@ spec: codename: "focal" # Options: ["bionic", "focal" (default), "jammy", "bullseye"] highperf: False # Optional [True, False (default)] wait: True # Optional [True, False (default)] Wait until the device is ready. + expireAfter: '12h' # Optional ["s", "m", "h", "d"] Expire after set duration. docker: enabled: True # Required rosbagMountPath: "/opt/rapyuta/volumes/rosbag" diff --git a/riocli/device/util.py b/riocli/device/util.py index 172447e8..70e4f2be 100644 --- a/riocli/device/util.py +++ b/riocli/device/util.py @@ -301,6 +301,7 @@ def make_hwil_labels(spec: dict, device_name: str) -> typing.Dict: "project": data["project_id"], "product": spec["product"], "rapyuta_device_name": device_name, + "expiry_after": spec["expireAfter"], } if spec.get("highperf", False): diff --git a/riocli/hwil/create.py b/riocli/hwil/create.py index ab369862..fa3dd489 100644 --- a/riocli/hwil/create.py +++ b/riocli/hwil/create.py @@ -49,6 +49,13 @@ type=click.Choice(["bionic", "focal", "jammy", "bullseye"]), default="focal", ) +@click.option( + "--expire-after", + "expire_after", + help="Duration after which the device will expire. Example: 12h, 1d, 600s, 10m", + type=str, + default="12h", +) @click.argument("device-name", type=str) @with_spinner(text="Creating device...") @click.pass_context @@ -58,6 +65,7 @@ def create_device( arch: str, os: str, codename: str, + expire_after: str, spinner: Yaspin = None, ) -> None: """Create a new hardware-in-the-loop device. @@ -78,11 +86,11 @@ def create_device( Create a new device with the name 'my-device' and the default - $ rio hwil create my-device + $ rio hwil create my-device - Create a new device with the name 'my-device' and custom - parameters for example, arm64 architecture, debian OS and - bullseye codename. + Create a new device with the name 'my-device' and custom + parameters for example, arm64 architecture, debian OS and + bullseye codename. $ rio hwil create my-device --arch arm64 --os debian --codename bullseye @@ -98,6 +106,8 @@ def create_device( client = new_hwil_client() labels = prepare_device_labels_from_context(ctx) + labels["expiry_after"] = expire_after + try: client.create_device(device_name, arch, os, codename, labels) spinner.text = click.style( diff --git a/riocli/jsonschema/schemas/device-schema.yaml b/riocli/jsonschema/schemas/device-schema.yaml index dee79ade..45f9433a 100644 --- a/riocli/jsonschema/schemas/device-schema.yaml +++ b/riocli/jsonschema/schemas/device-schema.yaml @@ -100,6 +100,10 @@ definitions: highperf: type: boolean default: False + expireAfter: + type: string + format: duration + default: 12h required: - enabled - product