Skip to content

Commit

Permalink
fix(network): handles error in name_to_guid
Browse files Browse the repository at this point in the history
  • Loading branch information
pallabpain committed Aug 3, 2023
1 parent 47b5f8f commit 2f73774
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions riocli/network/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from rapyuta_io.clients.routed_network import RoutedNetwork

from riocli.config import new_client
from riocli.constants import Colors
from riocli.utils.selector import show_selection


Expand All @@ -36,13 +37,19 @@ def decorated(**kwargs: Any):
guid = name
name = None

if guid:
network, network_type = find_network_guid(client, guid, network_type)
name = network.name
try:
if guid:
network, network_type = find_network_guid(
client, guid, network_type)
name = network.name

if name:
network, network_type = find_network_name(client, name, network_type)
guid = network.guid
if name:
network, network_type = find_network_name(
client, name, network_type)
guid = network.guid
except Exception as e:
click.secho(str(e), fg=Colors.RED)
raise SystemExit(1) from e

kwargs['network_type'] = network_type
kwargs['network_name'] = name
Expand Down Expand Up @@ -93,7 +100,8 @@ def find_network_name(
return resolve_conflict(routed, native, network_type, is_resolve_conflict)


def find_native_network_name(client: Client, name: str) -> Optional[NativeNetwork]:
def find_native_network_name(client: Client, name: str) -> Optional[
NativeNetwork]:
native_networks = client.list_native_networks()
for network in native_networks:
phase = network.internal_deployment_status.phase
Expand All @@ -103,7 +111,8 @@ def find_native_network_name(client: Client, name: str) -> Optional[NativeNetwor
return network


def find_routed_network_name(client: Client, name: str) -> Optional[RoutedNetwork]:
def find_routed_network_name(client: Client, name: str) -> Optional[
RoutedNetwork]:
routed_networks = client.get_all_routed_networks()
for network in routed_networks:
if network.phase == DeploymentPhaseConstants.DEPLOYMENT_STOPPED.value:
Expand Down Expand Up @@ -140,8 +149,9 @@ def resolve_conflict(
'routed': '{} ({})'.format(routed.name, routed.guid),
'native': '{} ({})'.format(native.name, native.guid),
}
choice = show_selection(options, header='Both Routed and Native networks were found with '
'the same name')
choice = show_selection(options,
header='Both Routed and Native networks were found with '
'the same name')

if choice == 'routed':
return routed, choice
Expand Down Expand Up @@ -180,6 +190,7 @@ def __init__(self, message='network not found!'):


class NetworkConflict(Exception):
def __init__(self, message='both routed and native networks exist with the same name!'):
def __init__(self,
message='both routed and native networks exist with the same name!'):
self.message = message
super().__init__(self.message)

0 comments on commit 2f73774

Please sign in to comment.