Skip to content

Commit

Permalink
fix(deployment): add phase filter for list_deployments
Browse files Browse the repository at this point in the history
  • Loading branch information
ankitrgadiya committed Jun 27, 2024
1 parent 8c56f17 commit 9b8705f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 32 deletions.
6 changes: 5 additions & 1 deletion riocli/apply/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,11 @@ def _list_functors(self, kind):
"staticroute": self.v2client.list_static_routes,
"disk": self.v2client.list_disks,
"network": self.v2client.list_networks,
"deployment": functools.partial(self.v2client.list_deployments),
"deployment": functools.partial(self.v2client.list_deployments,
query={'phases': ['InProgress',
'Succeeded',
'FailedToStart',
'Provisioning']}),
"device": self.client.get_all_devices,
"managedservice": self._list_managedservices,
"usergroup": self.client.list_usergroups
Expand Down
23 changes: 11 additions & 12 deletions riocli/deployment/list.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 Rapyuta Robotics
# 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.
Expand All @@ -22,19 +22,18 @@
from riocli.utils import tabulate_data

ALL_PHASES = [
DeploymentPhaseConstants.INPROGRESS,
DeploymentPhaseConstants.PROVISIONING,
DeploymentPhaseConstants.SUCCEEDED,
DeploymentPhaseConstants.FAILED_TO_START,
DeploymentPhaseConstants.PARTIALLY_DEPROVISIONED,
DeploymentPhaseConstants.DEPLOYMENT_STOPPED,
'InProgress',
'Provisioning',
'Succeeded',
'FailedToStart',
'Stopped',
]

DEFAULT_PHASES = [
DeploymentPhaseConstants.INPROGRESS,
DeploymentPhaseConstants.PROVISIONING,
DeploymentPhaseConstants.SUCCEEDED,
DeploymentPhaseConstants.FAILED_TO_START,
'InProgress',
'Provisioning',
'Succeeded',
'FailedToStart',
]


Expand All @@ -56,7 +55,7 @@ def list_deployments(device: str, phase: typing.List[str]) -> None:
"""
try:
client = new_v2_client(with_project=True)
deployments = client.list_deployments()
deployments = client.list_deployments(query={'phases': phase})
deployments = sorted(deployments, key=lambda d: d.metadata.name.lower())
display_deployment_list(deployments, show_header=True)
except Exception as e:
Expand Down
36 changes: 17 additions & 19 deletions riocli/deployment/util.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 Rapyuta Robotics
# 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.
Expand All @@ -18,14 +18,16 @@
from typing import List

import click
from rapyuta_io import Client, DeploymentPhaseConstants
from rapyuta_io import DeploymentPhaseConstants
from rapyuta_io.clients import Device
from rapyuta_io.clients.deployment import Deployment
from rapyuta_io.clients.package import ExecutableMount
from rapyuta_io.utils import InvalidParameterException, OperationNotAllowedError
from rapyuta_io.utils.constants import DEVICE_ID

from riocli.config import new_client
from riocli.config import new_client, new_v2_client
from riocli.deployment.list import DEFAULT_PHASES
from riocli.v2client import Client
from riocli.constants import Colors
from riocli.utils import tabulate_data
from riocli.utils.selector import show_selection
Expand All @@ -35,7 +37,7 @@ def name_to_guid(f: typing.Callable) -> typing.Callable:
@functools.wraps(f)
def decorated(**kwargs: typing.Any) -> None:
try:
client = new_client()
client = new_v2_client()
except Exception as e:
click.secho(str(e), fg=Colors.RED)
raise SystemExit(1) from e
Expand All @@ -52,7 +54,8 @@ def decorated(**kwargs: typing.Any) -> None:
name = get_deployment_name(client, guid)

if guid is None:
guid = find_deployment_guid(client, name)
guid = get_deployment_guid(client, name)

except Exception as e:
click.secho(str(e), fg=Colors.RED)
raise SystemExit(1) from e
Expand All @@ -63,22 +66,17 @@ def decorated(**kwargs: typing.Any) -> None:

return decorated


def get_deployment_name(client: Client, guid: str) -> str:
deployment = client.get_deployment(guid)
return deployment.name
def get_deployment_guid(client: Client, name: str) -> str:
deployment = client.get_deployment(name)
return deployment.metadata.guid


def find_deployment_guid(client: Client, name: str) -> str:
find_func = functools.partial(client.get_all_deployments,
phases=[DeploymentPhaseConstants.SUCCEEDED,
DeploymentPhaseConstants.PROVISIONING])
deployments = find_func()
for deployment in deployments:
if deployment.name == name:
return deployment.deploymentId
def get_deployment_name(client: Client, guid: str) -> str:
deployments = client.list_deployments(query={'guids': [guid]})
if len(deployments) == 0:
raise DeploymentNotFound

raise DeploymentNotFound()
return deployments[0].metadata.name


def select_details(deployment_guid, component_name=None, exec_name=None) -> (str, str, str):
Expand Down Expand Up @@ -126,7 +124,7 @@ def fetch_deployments(
deployment_name_or_regex: str,
include_all: bool,
) -> List[Deployment]:
deployments = client.list_deployments()
deployments = client.list_deployments(query={'phases': DEFAULT_PHASES})
result = []
for deployment in deployments:
if (include_all or deployment_name_or_regex == deployment.metadata.name or
Expand Down

0 comments on commit 9b8705f

Please sign in to comment.