From 020b096d34325b901e66e2152faa271d7754f5b4 Mon Sep 17 00:00:00 2001 From: Ankit R Gadiya Date: Fri, 12 Nov 2021 15:16:59 +0530 Subject: [PATCH] feat(network): adds device native network support --- riocli/network/create.py | 4 +++- riocli/network/list.py | 2 +- riocli/network/native_network.py | 19 +++++++++++-------- riocli/network/routed_network.py | 9 ++++++--- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/riocli/network/create.py b/riocli/network/create.py index dda861f7..2a5a2f81 100644 --- a/riocli/network/create.py +++ b/riocli/network/create.py @@ -17,6 +17,7 @@ from riocli.network.native_network import create_native_network from riocli.network.routed_network import create_routed_network +from riocli.device.util import name_to_guid as device_name_to_guid @click.command('create') @@ -25,7 +26,7 @@ type=click.Choice(['routed', 'native']), default='routed') @click.option('--ros', help='Version of ROS', type=click.Choice(['kinetic', 'melodic', 'noetic']), default='melodic') -@click.option('--device', help='Device ID of the Device where Network will run (device only)') +@click.option('--device', 'device_name', help='Device ID of the Device where Network will run (device only)') @click.option('--limit', help='Resource Limit for Network (cloud only) ' '[x_small is only available for Native Network]', type=click.Choice(['x_small', 'small', 'medium', 'large']), default='small') @@ -33,6 +34,7 @@ help='Network Interface on which Network will listen (device only)') @click.option('--restart-policy', help='Restart policy for the Network (device only)', type=click.Choice(['always', 'no', 'on-failure']), default='always') +@device_name_to_guid def create_network(name: str, network: str, **kwargs: typing.Any) -> None: """ Create a new network diff --git a/riocli/network/list.py b/riocli/network/list.py index fdde9f4b..e23d350a 100644 --- a/riocli/network/list.py +++ b/riocli/network/list.py @@ -65,4 +65,4 @@ def _display_network_list( if phase and phase == DeploymentPhaseConstants.DEPLOYMENT_STOPPED.value: continue click.secho('{:29} {:<15} {:8} {:8} {:20}'. - format(network.guid, network.name, network.runtime, network_type, phase)) + format(network.guid, network.name, network.runtime, network_type, phase)) diff --git a/riocli/network/native_network.py b/riocli/network/native_network.py index 138b68a8..2018b02a 100644 --- a/riocli/network/native_network.py +++ b/riocli/network/native_network.py @@ -11,6 +11,8 @@ # 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 typing + import click from click_spinner import spinner from rapyuta_io.clients.native_network import NativeNetwork, Parameters, NativeNetworkLimits @@ -19,22 +21,23 @@ from riocli.config import new_client -def create_native_network(name: str, ros: str, device: str = None, network_interface: str = None, - limit: str = None, restart_policy: str = None) -> None: +def create_native_network(name: str, ros: str, device_guid: str = None, network_interface: str = None, + limit: str = None, restart_policy: str = None, **kwargs: typing.Any) -> None: client = new_client() ros_distro = ROSDistro(ros) runtime = Runtime.CLOUD - if device: - # TODO: Update the SDK for support of Device Native Network - click.secho('Native Network on device is not supported yet (in the CLI)!', fg='red') - exit(1) - parameters = None if limit is not None: limit = getattr(NativeNetworkLimits, limit.upper()) - parameters = Parameters(limit) + device = None + if device_guid: + runtime = Runtime.DEVICE + device = client.get_device(device_id=device_guid) + + parameters = Parameters(limits=limit, device=device, network_interface=network_interface, + restart_policy=restart_policy) with spinner(): client.create_native_network(NativeNetwork(name, runtime=runtime, ros_distro=ros_distro, diff --git a/riocli/network/routed_network.py b/riocli/network/routed_network.py index b70b725c..b6c94662 100644 --- a/riocli/network/routed_network.py +++ b/riocli/network/routed_network.py @@ -11,6 +11,8 @@ # 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 typing + import click from click_spinner import spinner from rapyuta_io import ROSDistro @@ -20,8 +22,8 @@ from riocli.config import new_client -def create_routed_network(name: str, ros: str, device: str = None, network_interface: str = None, - limit: str = None, restart_policy: str = None) -> None: +def create_routed_network(name: str, ros: str, device_guid: str = None, network_interface: str = None, + limit: str = None, restart_policy: str = None, **kwargs: typing.Any) -> None: client = new_client() ros_distro = ROSDistro(ros) limit = getattr(RoutedNetworkLimits, limit.upper()) @@ -29,7 +31,8 @@ def create_routed_network(name: str, ros: str, device: str = None, network_inter restart_policy = RestartPolicy(restart_policy) with spinner(): - if device: + if device_guid: + device = client.get_device(device_id=device_guid) client.create_device_routed_network(name=name, ros_distro=ros_distro, shared=False, device=device, network_interface=network_interface,