mirror of
https://github.com/Telecominfraproject/wlan-lanforge-scripts.git
synced 2025-11-01 11:18:03 +00:00
LFRequest.py: sets die-on-error, improves efficiency of find_ports_like
This commit is contained in:
@@ -12,7 +12,7 @@ from LANforge.lfcli_base import LFCliBase
|
|||||||
|
|
||||||
class Realm(LFCliBase):
|
class Realm(LFCliBase):
|
||||||
def __init__(self, lfclient_host="localhost", lfclient_port=8080, debug=False):
|
def __init__(self, lfclient_host="localhost", lfclient_port=8080, debug=False):
|
||||||
super().__init__(lfclient_host, lfclient_port, debug)
|
super().__init__(lfclient_host, lfclient_port, debug, _halt_on_error=True)
|
||||||
self.lfclient_url = f"http://{lfclient_host}:{lfclient_port}"
|
self.lfclient_url = f"http://{lfclient_host}:{lfclient_port}"
|
||||||
super().checkConnect()
|
super().checkConnect()
|
||||||
|
|
||||||
@@ -58,33 +58,41 @@ class Realm(LFCliBase):
|
|||||||
device_name_list.append(v['device'])
|
device_name_list.append(v['device'])
|
||||||
matched_list = []
|
matched_list = []
|
||||||
prefix = ""
|
prefix = ""
|
||||||
for port_name in device_name_list:
|
|
||||||
try:
|
try:
|
||||||
if pattern.index("+") > 0:
|
if pattern.find("+") > 0:
|
||||||
match = re.search(r"^([^+]+)[+]$", pattern)
|
match = re.search(r"^([^+]+)[+]$", pattern)
|
||||||
if match.group(1):
|
if match.group(1):
|
||||||
#print("name:", port_name, " Group 1: ",match.group(1))
|
#print("name:", port_name, " Group 1: ",match.group(1))
|
||||||
prefix = match.group(1)
|
prefix = match.group(1)
|
||||||
if port_name.index(prefix) == 0:
|
for port_name in device_name_list:
|
||||||
|
if port_name.find(prefix) == 0:
|
||||||
matched_list.append(port_name)
|
matched_list.append(port_name)
|
||||||
|
|
||||||
elif pattern.index("*") > 0:
|
elif pattern.find("*") > 0:
|
||||||
match = re.search(r"^([^\*]+)[\*]$", pattern)
|
match = re.search(r"^([^\*]+)[\*]$", pattern)
|
||||||
if match.group(1):
|
if match.group(1):
|
||||||
prefix = match.group(1)
|
prefix = match.group(1)
|
||||||
#print("group 1: ",prefix)
|
#print("group 1: ",prefix)
|
||||||
if port_name.index(prefix) == 0:
|
for port_name in device_name_list:
|
||||||
|
if port_name.find(prefix) == 0:
|
||||||
matched_list.append(port_name)
|
matched_list.append(port_name)
|
||||||
|
|
||||||
elif pattern.index("[") > 0:
|
elif pattern.find("[") > 0:
|
||||||
match = re.search(r"^([^\[]+)\[(\d+)\.\.(\d+)\]$", pattern)
|
match = re.search(r"^([^\[]+)\[(\d+)\.\.(\d+)\]$", pattern)
|
||||||
if match.group(0):
|
if match.group(0):
|
||||||
#print("[group1]: ", match.group(1))
|
#print("[group1]: ", match.group(1))
|
||||||
|
#print("[group2]: ", match.group(2))
|
||||||
|
#print("[group3]: ", match.group(3))
|
||||||
prefix = match.group(1)
|
prefix = match.group(1)
|
||||||
if port_name.index(prefix):
|
for port_name in device_name_list:
|
||||||
|
if port_name.find(prefix) == 0:
|
||||||
|
port_suf = port_name[len(prefix):]
|
||||||
|
if (port_suf >= match.group(2)) and (port_suf <= match.group(3)):
|
||||||
|
#print(f"{port_name}: suffix[{port_name}] between {match.group(2)}:{match.group(3)}")
|
||||||
matched_list.append(port_name) # wrong but better
|
matched_list.append(port_name) # wrong but better
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
print(e)
|
super().error(e)
|
||||||
|
|
||||||
return matched_list
|
return matched_list
|
||||||
|
|
||||||
def newCxProfile(self):
|
def newCxProfile(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user