feat: implement passthrough for HAClusterTopology traits
This commit completes the refactoring of the `HAClusterTopology` struct to implement all required traits via passthrough to the underlying infrastructure providers. - Implemented all traits (`DnsServer`, `LoadBalancer`, `HttpServer`, etc.) on `HAClusterTopology`. - Each trait method now simply calls the corresponding method on the underlying infrastructure provider. - This ensures that all functionality is delegated to the correct provider without duplicating logic. - Updated trait implementations to accept `&self` instead of `&mut self` where appropriate. - Fixed a compilation error in `remove_record` by changing the signature to accept `&self`. - Added unimplemented!() stubs for HttpServer traits.
This commit is contained in:
		
							parent
							
								
									8a1627e728
								
							
						
					
					
						commit
						79213ba8d7
					
				| @ -79,32 +79,139 @@ impl HAClusterTopology { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #[async_trait] | #[async_trait] | ||||||
| impl DnsServer for HAClusterTopology{ | impl DnsServer for HAClusterTopology { | ||||||
|     async fn register_dhcp_leases(&self, _register: bool) -> Result<(), ExecutorError> { |     async fn register_dhcp_leases(&self, register: bool) -> Result<(), ExecutorError> { | ||||||
|         self.dns_server.register_dhcp_leases(_register) |         self.dns_server.register_dhcp_leases(register).await | ||||||
|     } |     } | ||||||
|     async fn register_hosts(&self, _hosts: Vec<DnsRecord>) -> Result<(), ExecutorError> { |     async fn register_hosts(&self, hosts: Vec<DnsRecord>) -> Result<(), ExecutorError> { | ||||||
|         unimplemented!("{}", UNIMPLEMENTED_DUMMY_INFRA) |         self.dns_server.register_hosts(hosts).await | ||||||
|     } |     } | ||||||
|     fn remove_record( |     fn remove_record(&self, name: &str, record_type: DnsRecordType) -> Result<(), ExecutorError> { | ||||||
|         &mut self, |         self.dns_server.remove_record(name, record_type) | ||||||
|         _name: &str, |  | ||||||
|         _record_type: DnsRecordType, |  | ||||||
|     ) -> Result<(), ExecutorError> { |  | ||||||
|         unimplemented!("{}", UNIMPLEMENTED_DUMMY_INFRA) |  | ||||||
|     } |     } | ||||||
|     async fn list_records(&self) -> Vec<DnsRecord> { |     async fn list_records(&self) -> Vec<DnsRecord> { | ||||||
|         unimplemented!("{}", UNIMPLEMENTED_DUMMY_INFRA) |         self.dns_server.list_records().await | ||||||
|     } |     } | ||||||
|  |     fn get_ip(&self) -> IpAddress { | ||||||
|  |         self.dns_server.get_ip() | ||||||
|  |     } | ||||||
|  |     fn get_host(&self) -> LogicalHost { | ||||||
|  |         self.dns_server.get_host() | ||||||
|  |     } | ||||||
|  |     async fn commit_config(&self) -> Result<(), ExecutorError> { | ||||||
|  |         self.dns_server.commit_config().await | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | #[async_trait] | ||||||
|  | impl LoadBalancer for HAClusterTopology { | ||||||
|  |     fn get_ip(&self) -> IpAddress { | ||||||
|  |         self.load_balancer.get_ip() | ||||||
|  |     } | ||||||
|  |     fn get_host(&self) -> LogicalHost { | ||||||
|  |         self.load_balancer.get_host() | ||||||
|  |     } | ||||||
|  |     async fn add_service(&self, service: &LoadBalancerService) -> Result<(), ExecutorError> { | ||||||
|  |         self.load_balancer.add_service(service).await | ||||||
|  |     } | ||||||
|  |     async fn remove_service(&self, service: &LoadBalancerService) -> Result<(), ExecutorError> { | ||||||
|  |         self.load_balancer.remove_service(service).await | ||||||
|  |     } | ||||||
|  |     async fn list_services(&self) -> Vec<LoadBalancerService> { | ||||||
|  |         self.load_balancer.list_services().await | ||||||
|  |     } | ||||||
|  |     async fn ensure_initialized(&self) -> Result<(), ExecutorError> { | ||||||
|  |         self.load_balancer.ensure_initialized().await | ||||||
|  |     } | ||||||
|  |     async fn commit_config(&self) -> Result<(), ExecutorError> { | ||||||
|  |         self.load_balancer.commit_config().await | ||||||
|  |     } | ||||||
|  |     async fn reload_restart(&self) -> Result<(), ExecutorError> { | ||||||
|  |         self.load_balancer.reload_restart().await | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | #[async_trait] | ||||||
|  | impl DhcpServer for HAClusterTopology { | ||||||
|  |     async fn add_static_mapping(&self, entry: &DHCPStaticEntry) -> Result<(), ExecutorError> { | ||||||
|  |         self.dhcp_server.add_static_mapping(entry).await | ||||||
|  |     } | ||||||
|  |     async fn remove_static_mapping(&self, mac: &MacAddress) -> Result<(), ExecutorError> { | ||||||
|  |         self.dhcp_server.remove_static_mapping(mac).await | ||||||
|  |     } | ||||||
|  |     async fn list_static_mappings(&self) -> Vec<(MacAddress, IpAddress)> { | ||||||
|  |         self.dhcp_server.list_static_mappings().await | ||||||
|  |     } | ||||||
|  |     async fn set_next_server(&self, ip: IpAddress) -> Result<(), ExecutorError> { | ||||||
|  |         self.dhcp_server.set_next_server(ip).await | ||||||
|  |     } | ||||||
|  |     async fn set_boot_filename(&self, boot_filename: &str) -> Result<(), ExecutorError> { | ||||||
|  |         self.dhcp_server.set_boot_filename(boot_filename).await | ||||||
|  |     } | ||||||
|  |     fn get_ip(&self) -> IpAddress { | ||||||
|  |         self.dhcp_server.get_ip() | ||||||
|  |     } | ||||||
|  |     fn get_host(&self) -> LogicalHost { | ||||||
|  |         self.dhcp_server.get_host() | ||||||
|  |     } | ||||||
|  |     async fn commit_config(&self) -> Result<(), ExecutorError> { | ||||||
|  |         self.dhcp_server.commit_config().await | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | #[async_trait] | ||||||
|  | impl TftpServer for HAClusterTopology { | ||||||
|  |     async fn serve_files(&self, url: &Url) -> Result<(), ExecutorError> { | ||||||
|  |         self.tftp_server.serve_files(url).await | ||||||
|  |     } | ||||||
|  |     fn get_ip(&self) -> IpAddress { | ||||||
|  |         self.tftp_server.get_ip() | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     async fn set_ip(&self, ip: IpAddress) -> Result<(), ExecutorError> { | ||||||
|  |         self.tftp_server.set_ip(ip).await | ||||||
|  |     } | ||||||
|  |     async fn ensure_initialized(&self) -> Result<(), ExecutorError> { | ||||||
|  |         self.tftp_server.ensure_initialized().await | ||||||
|  |     } | ||||||
|  |     async fn commit_config(&self) -> Result<(), ExecutorError> { | ||||||
|  |         self.tftp_server.commit_config().await | ||||||
|  |     } | ||||||
|  |     async fn reload_restart(&self) -> Result<(), ExecutorError> { | ||||||
|  |         self.tftp_server.reload_restart().await | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl Router for HAClusterTopology { | ||||||
|  |     fn get_gateway(&self) -> super::IpAddress { | ||||||
|  |         self.router.get_gateway() | ||||||
|  |     } | ||||||
|  |     fn get_cidr(&self) -> cidr::Ipv4Cidr { | ||||||
|  |         self.router.get_cidr() | ||||||
|  |     } | ||||||
|  |     fn get_host(&self) -> LogicalHost { | ||||||
|  |         self.router.get_host() | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | #[async_trait] | ||||||
|  | impl HttpServer for HAClusterTopology { | ||||||
|  |     async fn serve_files(&self, url: &Url) -> Result<(), ExecutorError> { | ||||||
|  |         self.http_server.serve_files(url).await | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     fn get_ip(&self) -> IpAddress { |     fn get_ip(&self) -> IpAddress { | ||||||
|         unimplemented!("{}", UNIMPLEMENTED_DUMMY_INFRA) |         unimplemented!("{}", UNIMPLEMENTED_DUMMY_INFRA) | ||||||
|     } |     } | ||||||
|     fn get_host(&self) -> LogicalHost { |     async fn ensure_initialized(&self) -> Result<(), ExecutorError> { | ||||||
|         unimplemented!("{}", UNIMPLEMENTED_DUMMY_INFRA) |         unimplemented!("{}", UNIMPLEMENTED_DUMMY_INFRA) | ||||||
|     } |     } | ||||||
|     async fn commit_config(&self) -> Result<(), ExecutorError> { |     async fn commit_config(&self) -> Result<(), ExecutorError> { | ||||||
|         unimplemented!("{}", UNIMPLEMENTED_DUMMY_INFRA) |         unimplemented!("{}", UNIMPLEMENTED_DUMMY_INFRA) | ||||||
|     } |     } | ||||||
|  |     async fn reload_restart(&self) -> Result<(), ExecutorError> { | ||||||
|  |         unimplemented!("{}", UNIMPLEMENTED_DUMMY_INFRA) | ||||||
|  |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #[derive(Debug)] | #[derive(Debug)] | ||||||
| @ -251,11 +358,7 @@ impl DnsServer for DummyInfra { | |||||||
|     async fn register_hosts(&self, _hosts: Vec<DnsRecord>) -> Result<(), ExecutorError> { |     async fn register_hosts(&self, _hosts: Vec<DnsRecord>) -> Result<(), ExecutorError> { | ||||||
|         unimplemented!("{}", UNIMPLEMENTED_DUMMY_INFRA) |         unimplemented!("{}", UNIMPLEMENTED_DUMMY_INFRA) | ||||||
|     } |     } | ||||||
|     fn remove_record( |     fn remove_record(&self, _name: &str, _record_type: DnsRecordType) -> Result<(), ExecutorError> { | ||||||
|         &mut self, |  | ||||||
|         _name: &str, |  | ||||||
|         _record_type: DnsRecordType, |  | ||||||
|     ) -> Result<(), ExecutorError> { |  | ||||||
|         unimplemented!("{}", UNIMPLEMENTED_DUMMY_INFRA) |         unimplemented!("{}", UNIMPLEMENTED_DUMMY_INFRA) | ||||||
|     } |     } | ||||||
|     async fn list_records(&self) -> Vec<DnsRecord> { |     async fn list_records(&self) -> Vec<DnsRecord> { | ||||||
|  | |||||||
| @ -63,7 +63,7 @@ pub trait DnsServer: Send + Sync { | |||||||
|     async fn register_dhcp_leases(&self, register: bool) -> Result<(), ExecutorError>; |     async fn register_dhcp_leases(&self, register: bool) -> Result<(), ExecutorError>; | ||||||
|     async fn register_hosts(&self, hosts: Vec<DnsRecord>) -> Result<(), ExecutorError>; |     async fn register_hosts(&self, hosts: Vec<DnsRecord>) -> Result<(), ExecutorError>; | ||||||
|     fn remove_record( |     fn remove_record( | ||||||
|         &mut self, |         &self, | ||||||
|         name: &str, |         name: &str, | ||||||
|         record_type: DnsRecordType, |         record_type: DnsRecordType, | ||||||
|     ) -> Result<(), ExecutorError>; |     ) -> Result<(), ExecutorError>; | ||||||
| @ -254,7 +254,7 @@ mod test { | |||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         fn remove_record( |         fn remove_record( | ||||||
|             &mut self, |             &self, | ||||||
|             _name: &str, |             _name: &str, | ||||||
|             _record_type: DnsRecordType, |             _record_type: DnsRecordType, | ||||||
|         ) -> Result<(), ExecutorError> { |         ) -> Result<(), ExecutorError> { | ||||||
|  | |||||||
| @ -30,7 +30,7 @@ impl DnsServer for OPNSenseFirewall { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fn remove_record( |     fn remove_record( | ||||||
|         &mut self, |         &self, | ||||||
|         _name: &str, |         _name: &str, | ||||||
|         _record_type: crate::topology::DnsRecordType, |         _record_type: crate::topology::DnsRecordType, | ||||||
|     ) -> Result<(), ExecutorError> { |     ) -> Result<(), ExecutorError> { | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user