Skip to content

Commit

Permalink
Merge pull request #318 from rapyuta-robotics/devel
Browse files Browse the repository at this point in the history
🎉 release: v7.5.0
  • Loading branch information
pallabpain authored Jun 12, 2024
2 parents 267803b + bf103bc commit 7c016fc
Show file tree
Hide file tree
Showing 20 changed files with 512 additions and 214 deletions.
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ graphlib-backport = ">=1.0.3"
jinja2 = ">=3.0.1"
munch = ">=2.4.0"
pyyaml = ">=5.4.1"
rapyuta-io = ">=1.15.0"
rapyuta-io = ">=1.15.1"
tabulate = ">=0.8.0"
pyrfc3339 = ">=1.1"
directory-tree = ">=0.0.3.1"
Expand Down
290 changes: 142 additions & 148 deletions Pipfile.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion riocli/apply/manifests/package-nonros-device.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ spec:
periodSeconds: 10 # How often (in seconds) to perform the probe.
failureThreshold: 1 # Minimum consecutive failures for the probe to be considered failed after having succeeded.
successThreshold: 3 # Minimum consecutive successes for the probe to be considered successful after having failed.
timeoutSeconds: 1 # Number of seconds after which the probe times out.
timeoutSeconds: 10 # Number of seconds after which the probe times out. Minimun: 10

docker:
image: "busybox:latest"
Expand Down
2 changes: 1 addition & 1 deletion riocli/apply/manifests/package-ros-device-no-rosbag.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ spec:
periodSeconds: 10 # How often (in seconds) to perform the probe.
failureThreshold: 1 # Minimum consecutive failures for the probe to be considered failed after having succeeded.
successThreshold: 3 # Minimum consecutive successes for the probe to be considered successful after having failed.
timeoutSeconds: 1 # Number of seconds after which the probe times out.
timeoutSeconds: 10 # Number of seconds after which the probe times out. Mininum: 10
docker:
image: "busybox:latest"
imagePullPolicy: "Always" # Always, Never, IfNotPresent(default)
Expand Down
2 changes: 1 addition & 1 deletion riocli/apply/manifests/package-ros-device-rosbag.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ spec:
periodSeconds: 10 # How often (in seconds) to perform the probe.
failureThreshold: 1 # Minimum consecutive failures for the probe to be considered failed after having succeeded.
successThreshold: 3 # Minimum consecutive successes for the probe to be considered successful after having failed.
timeoutSeconds: 1 # Number of seconds after which the probe times out.
timeoutSeconds: 10 # Number of seconds after which the probe times out. Minimum: 10
docker:
image: "busybox:latest"
imagePullPolicy: "Always" # Always, Never, IfNotPresent(default)
Expand Down
8 changes: 4 additions & 4 deletions riocli/apply/manifests/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ spec:
periodSeconds: 10 # How often (in seconds) to perform the probe.
failureThreshold: 1 # Minimum consecutive failures for the probe to be considered failed after having succeeded.
successThreshold: 3 # Minimum consecutive successes for the probe to be considered successful after having failed.
timeoutSeconds: 1 # Number of seconds after which the probe times out.
timeoutSeconds: 10 # Number of seconds after which the probe times out. Minimum: 10
docker:
image: "busybox:latest"
imagePullPolicy: "Always" # Always, Never, IfNotPresent(default)
Expand Down Expand Up @@ -357,7 +357,7 @@ spec:
periodSeconds: 10 # How often (in seconds) to perform the probe.
failureThreshold: 1 # Minimum consecutive failures for the probe to be considered failed after having succeeded.
successThreshold: 3 # Minimum consecutive successes for the probe to be considered successful after having failed.
timeoutSeconds: 1 # Number of seconds after which the probe times out.
timeoutSeconds: 10 # Number of seconds after which the probe times out. Minimum: 10
docker:
image: "busybox:latest"
imagePullPolicy: "Always" # Always, Never, IfNotPresent(default)
Expand All @@ -379,7 +379,7 @@ spec:
periodSeconds: 10 # How often (in seconds) to perform the probe.
failureThreshold: 1 # Minimum consecutive failures for the probe to be considered failed after having succeeded.
successThreshold: 3 # Minimum consecutive successes for the probe to be considered successful after having failed.
timeoutSeconds: 1 # Number of seconds after which the probe times out.
timeoutSeconds: 10 # Number of seconds after which the probe times out. Minimum: 10
docker:
image: "nginx:latest"
imagePullPolicy: "Always" # Always, Never, IfNotPresent(default)
Expand Down Expand Up @@ -427,7 +427,7 @@ spec:
periodSeconds: 10 # How often (in seconds) to perform the probe.
failureThreshold: 1 # Minimum consecutive failures for the probe to be considered failed after having succeeded.
successThreshold: 3 # Minimum consecutive successes for the probe to be considered successful after having failed.
timeoutSeconds: 1 # Number of seconds after which the probe times out.
timeoutSeconds: 10 # Number of seconds after which the probe times out. Minimum: 10
docker:
image: "busybox:latest"
imagePullPolicy: "Always" # Always, Never, IfNotPresent(default)
Expand Down
2 changes: 1 addition & 1 deletion riocli/apply/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def find_depends(self, depends, *args):

def _guid_functor(self, kind):
mapping = {
'secret': lambda x: munchify(x).metadata.name,
'secret': lambda x: munchify(x).metadata.guid,
"project": lambda x: munchify(x).metadata.guid,
"package": lambda x: munchify(x)['id'],
"staticroute": lambda x: munchify(x)['metadata']['guid'],
Expand Down
3 changes: 2 additions & 1 deletion riocli/configtree/import_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ def import_keys(

try:
client = new_v2_client(with_project=(not with_org))
with Revision(tree_name=tree_name, commit=commit, client=client, spinner=spinner) as rev:
with Revision(tree_name=tree_name, commit=commit, client=client, spinner=spinner,
with_org=with_org) as rev:
rev_id = rev.revision_id

for key, value in data.items():
Expand Down
73 changes: 56 additions & 17 deletions riocli/configtree/revision.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __init__(self, tree_name: str,
commit: bool = False,
force_new: bool = False,
spinner: Optional[Yaspin] = None,
with_project: bool = True):
with_org: bool = True):

self._tree_name = tree_name
self._client = client
Expand All @@ -52,7 +52,9 @@ def __init__(self, tree_name: str,
self._explicit = False
self._data = {}
self._org_guid = self._config.organization_guid
self._project_guid = self._config.project_guid if with_project else None
self._project_guid = None
if not with_org:
self._project_guid = self._config.project_guid

rev = get_revision_from_state(self._org_guid, self._project_guid, self._tree_name)

Expand Down Expand Up @@ -188,8 +190,14 @@ def init_revision(
Initialize a new revision for the Config tree
"""
config = get_config_from_context(ctx)
rev = get_revision_from_state(org_guid=config.organization_guid, project_guid=config.project_guid,
project_guid = None
if not with_org:
project_guid = config.project_guid

rev = get_revision_from_state(org_guid=config.organization_guid,
project_guid=project_guid,
tree_name=tree_name)

if not force and rev is not None and not rev.committed:
spinner.text = click.style(
'Revision {} is already present. Subsequent commands will re-use it. \n'
Expand All @@ -201,7 +209,7 @@ def init_revision(

try:
client = new_v2_client(with_project=(not with_org))
Revision(tree_name=tree_name, force_new=force, spinner=spinner, client=client)
Revision(tree_name=tree_name, force_new=force, spinner=spinner, client=client, with_org=with_org)
except Exception as e:
spinner.text = click.style(
'Failed to initialize Config tree revision: {}'.format(e), Colors.RED)
Expand Down Expand Up @@ -235,13 +243,15 @@ def commit_revision(
"""

config = get_config_from_context(ctx)
project_guid = config.project_guid
if with_org:
project_guid = None
project_guid = None
if not with_org:
project_guid = config.project_guid

if not rev_id:
rev = get_revision_from_state(org_guid=config.organization_guid, project_guid=project_guid,
rev = get_revision_from_state(org_guid=config.organization_guid,
project_guid=project_guid,
tree_name=tree_name)

if not rev or rev.committed:
spinner.text = click.style(
'RevisionID not provided as argument and not found in the State file.',
Expand All @@ -252,7 +262,8 @@ def commit_revision(

try:
client = new_v2_client(with_project=(not with_org))
rev = Revision(tree_name=tree_name, rev_id=rev_id, spinner=spinner, client=client)
rev = Revision(tree_name=tree_name, rev_id=rev_id, spinner=spinner,
client=client, with_org=with_org)
rev.commit(msg=message)
except Exception as e:
spinner.text = click.style(
Expand Down Expand Up @@ -287,8 +298,14 @@ def put_key_in_revision(
"""

config = get_config_from_context(ctx)
rev = get_revision_from_state(org_guid=config.organization_guid, project_guid=config.project_guid,
project_guid = None
if not with_org:
project_guid = config.project_guid

rev = get_revision_from_state(org_guid=config.organization_guid,
project_guid=project_guid,
tree_name=tree_name)

if not rev or rev.committed:
spinner.text = click.style(
'RevisionID not provided as argument and not found in the State file. \n'
Expand All @@ -300,7 +317,8 @@ def put_key_in_revision(

try:
client = new_v2_client(with_project=(not with_org))
with Revision(tree_name=tree_name, spinner=spinner, client=client) as rev:
with Revision(tree_name=tree_name, spinner=spinner, client=client,
with_org=with_org) as rev:
rev.store(key=key, value=value)
spinner.write(click.style(
'\t{} Key {} added.'.format(Symbols.SUCCESS, key)
Expand Down Expand Up @@ -338,8 +356,14 @@ def put_file_in_revision(
"""

config = get_config_from_context(ctx)
rev = get_revision_from_state(org_guid=config.organization_guid, project_guid=config.project_guid,
project_guid = None
if not with_org:
project_guid = config.project_guid

rev = get_revision_from_state(org_guid=config.organization_guid,
project_guid=project_guid,
tree_name=tree_name)

if not rev or rev.committed:
spinner.text = click.style(
'RevisionID not provided as argument and not found in the State file. \n'
Expand All @@ -351,7 +375,8 @@ def put_file_in_revision(

try:
client = new_v2_client(with_project=(not with_org))
with Revision(tree_name=tree_name, spinner=spinner, client=client) as rev:
with Revision(tree_name=tree_name, spinner=spinner, client=client,
with_org=with_org) as rev:
rev.store_file(key=key, file_path=file_path)
spinner.write(click.style(
'\t{} File {} added.'.format(Symbols.SUCCESS, key)
Expand Down Expand Up @@ -385,10 +410,15 @@ def delete_key_in_revision(
"""
Delete the key in the uncommitted revision
"""

config = get_config_from_context(ctx)
rev = get_revision_from_state(org_guid=config.organization_guid, project_guid=config.project_guid,
project_guid = None
if not with_org:
project_guid = config.project_guid

rev = get_revision_from_state(org_guid=config.organization_guid,
project_guid=project_guid,
tree_name=tree_name)

if not rev or rev.committed:
spinner.text = click.style(
'RevisionID not provided as argument and not found in the State file. \n'
Expand All @@ -400,7 +430,8 @@ def delete_key_in_revision(

try:
client = new_v2_client(with_project=(not with_org))
with Revision(tree_name=tree_name, spinner=spinner, client=client) as rev:
with Revision(tree_name=tree_name, spinner=spinner, client=client,
with_org=with_org) as rev:
rev.delete(key=key)
spinner.write(click.style(
'\t{} Key {} removed.'.format(Symbols.SUCCESS, key)
Expand Down Expand Up @@ -434,8 +465,14 @@ def list_revision_keys(
"""
if not rev_id:
config = get_config_from_context(ctx)
rev = get_revision_from_state(org_guid=config.organization_guid, project_guid=config.project_guid,
project_guid = None
if not with_org:
project_guid = config.project_guid

rev = get_revision_from_state(org_guid=config.organization_guid,
project_guid=project_guid,
tree_name=tree_name)

if not rev or rev.committed:
click.echo(
click.style(
Expand All @@ -445,6 +482,8 @@ def list_revision_keys(
)
raise SystemExit(1)

rev_id = rev.rev_id

try:
client = new_v2_client(with_project=(not with_org))
tree = client.get_config_tree(tree_name=tree_name, rev_id=rev_id)
Expand Down
7 changes: 6 additions & 1 deletion riocli/configtree/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,15 @@ def set_tree_revision(
"""

config = get_config_from_context(ctx)
project_guid = None
if not with_org:
project_guid = config.project_guid

if not rev_id:
rev = get_revision_from_state(org_guid=config.organization_guid, project_guid=config.project_guid,
rev = get_revision_from_state(org_guid=config.organization_guid,
project_guid=project_guid,
tree_name=tree_name)

if not rev or not rev.committed:
spinner.text = click.style(
'RevisionID not provided as argument and not found in the State file.',
Expand Down
4 changes: 3 additions & 1 deletion riocli/device/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2021 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 @@ -24,6 +24,7 @@
from riocli.device.label import device_labels
from riocli.device.list import list_devices
from riocli.device.metric import device_metrics
from riocli.device.migrate import migrate_project
from riocli.device.onboard import device_onboard
from riocli.device.tools import tools
from riocli.device.topic import device_topics
Expand Down Expand Up @@ -57,3 +58,4 @@ def device():
device.add_command(list_devices)
device.add_command(tools)
device.add_command(toggle_vpn)
device.add_command(migrate_project)
69 changes: 69 additions & 0 deletions riocli/device/migrate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# 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 HelpColorsCommand
from yaspin.core import Yaspin

from riocli.config import new_client
from riocli.device.util import migrate_device_to_project, name_to_guid
from riocli.project.util import name_to_guid as project_name_to_guid

from riocli.constants import Colors, Symbols
from riocli.utils.spinner import with_spinner


@click.command(
'migrate',
cls=HelpColorsCommand,
help_headers_color=Colors.YELLOW,
help_options_color=Colors.GREEN
)
@click.argument('device-name', type=str)
@click.argument('project-name', type=str)
@click.option('--enable-vpn', is_flag=True,
type=click.BOOL, default=False,
help="Enable VPN after migrating to the destination project.")
@click.option('--advertise-routes', is_flag=True,
type=click.BOOL, default=False,
help="Advertise subnets configured in project to VPN peers")
@name_to_guid
@project_name_to_guid
@click.pass_context
@with_spinner(text="Migrating device...")
def migrate_project(ctx: click.Context, device_name: str, device_guid: str,
project_name: str, project_guid: str,
enable_vpn: bool, advertise_routes: bool,
spinner: Yaspin) -> None:
"""
Migrate the device from current project to the target project.
"""
try:
migrate_device_to_project(ctx, device_guid, project_guid)
spinner.write(
click.style('{} Device {} migrated successfully.'.format(Symbols.SUCCESS, device_name),
fg=Colors.GREEN))

if enable_vpn:
spinner.text = 'Enabling VPN on device...'
client = new_client()
client.set_project(project_guid)
client.toggle_features(device_id=device_guid, features=[('vpn', True)],
config={'vpn': {'advertise_routes': advertise_routes}})
spinner.write(click.style('{} Enabled VPN on the device.'.format(Symbols.SUCCESS), fg=Colors.GREEN))
except Exception as e:
spinner.text = click.style(
'Failed to migrate device: {}'.format(e), Colors.RED)
spinner.red.fail(Symbols.ERROR)
raise SystemExit(1) from e

Loading

0 comments on commit 7c016fc

Please sign in to comment.