Skip to content

Commit

Permalink
refactor(device): makes product optional in device manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
pallabpain committed Dec 5, 2024
1 parent 94bb48e commit 2886c4d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion riocli/apply/manifests/device.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ spec:
rosDistro: "melodic" # Options: ["kinetic", "melodic" (default), "noetic"]
virtual:
enabled: True # Required
product: "sootballs" # Required Options: ["sootballs", "flaptter", "oks", "platform"]
product: "sootballs" # Optional: ["sootballs", "flaptter", "oks"]
arch: "amd64" # Options: ["amd64" (default), "arm64" ]
os: "ubuntu" # Options: ["ubuntu" (default), "debian" ]
codename: "focal" # Options: ["bionic", "focal" (default), "jammy", "noble", "bullseye"]
Expand Down
15 changes: 9 additions & 6 deletions riocli/device/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,15 +250,19 @@ def generate_hwil_device_name(
) -> str:
"""Generates a valid hardware-in-the-loop device name."""
project = project_id.split("project-")[1]
return sanitize_hwil_device_name(f"{name}-{product}-{user}-{project}")
device_name = f"{name}-{product}-{user}-{project}"
if not product:
device_name = f"{name}-{user}-{project}"

return sanitize_hwil_device_name(device_name)


def create_hwil_device(spec: dict, metadata: dict) -> Munch:
"""Create a new hardware-in-the-loop device."""
os = spec["os"]
codename = spec["codename"]
arch = spec["arch"]
product = spec["product"]
product = spec.get("product")
name = metadata["name"]

labels = make_hwil_labels(spec, name)
Expand Down Expand Up @@ -294,7 +298,7 @@ def create_hwil_device(spec: dict, metadata: dict) -> Munch:

def delete_hwil_device(spec: dict, metadata: dict) -> None:
"""Delete a hardware-in-the-loop device by name."""
product = spec["product"]
product = spec.get("product")
name = metadata["name"]
labels = make_hwil_labels(spec, name)
device_name = generate_hwil_device_name(
Expand Down Expand Up @@ -329,13 +333,12 @@ def make_hwil_labels(spec: dict, device_name: str) -> typing.Dict:
"user": user_email,
"organization": data["organization_id"],
"project": data["project_id"],
"product": spec["product"],
"rapyuta_device_name": device_name,
"expiry_after": spec["expireAfter"],
}

if spec.get("highperf", False):
labels["highperf"] = ""
if "product" in spec:
labels["product"] = spec["product"]

return labels

Expand Down
2 changes: 0 additions & 2 deletions riocli/jsonschema/schemas/device-schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ definitions:
- sootballs
- flaptter
- oks
- platform
arch:
type: string
enum:
Expand Down Expand Up @@ -106,7 +105,6 @@ definitions:
default: 12h
required:
- enabled
- product
dependencies:
docker:
oneOf:
Expand Down

0 comments on commit 2886c4d

Please sign in to comment.