Skip to content

Commit

Permalink
feat(network): adds device native network support
Browse files Browse the repository at this point in the history
  • Loading branch information
ankitrgadiya committed Dec 27, 2021
1 parent dc9ddda commit 020b096
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
4 changes: 3 additions & 1 deletion riocli/network/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -25,14 +26,15 @@
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')
@click.option('--network-interface', '-nic', type=str,
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
Expand Down
2 changes: 1 addition & 1 deletion riocli/network/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
19 changes: 11 additions & 8 deletions riocli/network/native_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
9 changes: 6 additions & 3 deletions riocli/network/routed_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -20,16 +22,17 @@
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())
if restart_policy:
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,
Expand Down

0 comments on commit 020b096

Please sign in to comment.