mirror of
				https://github.com/Telecominfraproject/wlan-lanforge-scripts.git
				synced 2025-10-31 10:48:02 +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.find("+") > 0: | ||||||
|                 if pattern.index("+") > 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) |                 for port_name in device_name_list: | ||||||
|                     if port_name.index(prefix) == 0: |                     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)) | ||||||
|                         prefix = match.group(1) |                     #print("[group2]: ", match.group(2)) | ||||||
|                         if port_name.index(prefix): |                     #print("[group3]: ", match.group(3)) | ||||||
|                             matched_list.append(port_name) # wrong but better |                     prefix = match.group(1) | ||||||
|             except ValueError as e: |                     for port_name in device_name_list: | ||||||
|                 print(e) |                         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 | ||||||
|  |         except ValueError as e: | ||||||
|  |             super().error(e) | ||||||
|  |  | ||||||
|         return matched_list |         return matched_list | ||||||
|  |  | ||||||
|     def newCxProfile(self): |     def newCxProfile(self): | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Jed Reynolds
					Jed Reynolds