mirror of
				https://github.com/Telecominfraproject/wlan-ap.git
				synced 2025-10-29 17:42:41 +00:00 
			
		
		
		
	cloud_discovery: Track and persist discovery method
Adds support for recording the method used to discover the cloud controller (e.g. DHCP, FLASH, OpenLAN). The selected method records the current date and time along with the discovery method into "/etc/ucentral/discovery.state.json". The date is stored in epoch format. Fixed: WIFI-14966 Signed-off-by: Marek Kwaczynski <marek@shasta.cloud>
This commit is contained in:
		 Marek Kwaczynski
					Marek Kwaczynski
				
			
				
					committed by
					
						 John Crispin
						John Crispin
					
				
			
			
				
	
			
			
			 John Crispin
						John Crispin
					
				
			
						parent
						
							68dfd58303
						
					
				
				
					commit
					b982f3f4c2
				
			| @@ -15,9 +15,14 @@ const ONLINE = 2; | |||||||
| const OFFLINE = 3; | const OFFLINE = 3; | ||||||
| const ORPHAN = 4; | const ORPHAN = 4; | ||||||
|  |  | ||||||
|  | const DISCOVER_DHCP = "DHCP"; | ||||||
|  | const DISCOVER_FLASH = "FLASH"; | ||||||
|  | const DISCOVER_LOOKUP = "OpenLAN"; | ||||||
|  |  | ||||||
| let ubus = libubus.connect(); | let ubus = libubus.connect(); | ||||||
| let uci = libuci.cursor(); | let uci = libuci.cursor(); | ||||||
| let state = DISCOVER; | let state = DISCOVER; | ||||||
|  | let discovery_method = ""; | ||||||
| let validate_time; | let validate_time; | ||||||
| let offline_time; | let offline_time; | ||||||
| let orphan_time; | let orphan_time; | ||||||
| @@ -78,6 +83,14 @@ function gateway_load() { | |||||||
| 	return readjsonfile('/etc/ucentral/gateway.json'); | 	return readjsonfile('/etc/ucentral/gateway.json'); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | function discovery_state_write() { | ||||||
|  | 	let discovery_state = { | ||||||
|  | 		"type": discovery_method, | ||||||
|  | 		"updated": time() | ||||||
|  | 	}; | ||||||
|  | 	fs.writefile('/etc/ucentral/discovery.state.json', discovery_state); | ||||||
|  | } | ||||||
|  |  | ||||||
| function gateway_write(data) { | function gateway_write(data) { | ||||||
| 	let gateway = gateway_load(); | 	let gateway = gateway_load(); | ||||||
| 	gateway ??= {}; | 	gateway ??= {}; | ||||||
| @@ -130,6 +143,7 @@ function set_state(set) { | |||||||
| 		if (prev == VALIDATING) { | 		if (prev == VALIDATING) { | ||||||
| 			ulog(LOG_INFO, 'Setting cloud controller to validated\n'); | 			ulog(LOG_INFO, 'Setting cloud controller to validated\n'); | ||||||
| 			gateway_write({ valid: true }); | 			gateway_write({ valid: true }); | ||||||
|  | 			discovery_state_write(); | ||||||
| 		} | 		} | ||||||
| 		break; | 		break; | ||||||
|  |  | ||||||
| @@ -227,15 +241,18 @@ function interval_handler() { | |||||||
| 		if (!time_is_valid()) | 		if (!time_is_valid()) | ||||||
| 			return; | 			return; | ||||||
|  |  | ||||||
|  | 		discovery_method = DISCOVER_DHCP; | ||||||
| 		if (discover_dhcp()) | 		if (discover_dhcp()) | ||||||
| 			return; | 			return; | ||||||
|  |  | ||||||
| 		if (system('/usr/bin/est_client enroll')) | 		if (system('/usr/bin/est_client enroll')) | ||||||
| 			return; | 			return; | ||||||
|  |  | ||||||
|  | 		discovery_method = DISCOVER_FLASH; | ||||||
| 		if (!discover_flash()) | 		if (!discover_flash()) | ||||||
| 			return; | 			return; | ||||||
|  |  | ||||||
|  | 		discovery_method = DISCOVER_LOOKUP; | ||||||
| 		redirector_lookup(); | 		redirector_lookup(); | ||||||
| 		break; | 		break; | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user