feat: started to prepare inventory / topoplogy for NCD #1
| @ -127,6 +127,9 @@ impl DhcpServer for DummyInfra { | |||||||
|     async fn set_filename64(&self, _filename: &str) -> Result<(), ExecutorError> { |     async fn set_filename64(&self, _filename: &str) -> Result<(), ExecutorError> { | ||||||
|         unimplemented!("{}", UNIMPLEMENTED_DUMMY_INFRA) |         unimplemented!("{}", UNIMPLEMENTED_DUMMY_INFRA) | ||||||
|     } |     } | ||||||
|  |     async fn set_filenameipxe(&self, _filenameipxe: &str) -> Result<(), ExecutorError> { | ||||||
|  |         unimplemented!("{}", UNIMPLEMENTED_DUMMY_INFRA) | ||||||
|  |     } | ||||||
|     fn get_ip(&self) -> IpAddress { |     fn get_ip(&self) -> IpAddress { | ||||||
|         unimplemented!("{}", UNIMPLEMENTED_DUMMY_INFRA) |         unimplemented!("{}", UNIMPLEMENTED_DUMMY_INFRA) | ||||||
|     } |     } | ||||||
|  | |||||||
| @ -50,6 +50,7 @@ pub trait DhcpServer: Send + Sync { | |||||||
|     async fn set_boot_filename(&self, boot_filename: &str) -> Result<(), ExecutorError>; |     async fn set_boot_filename(&self, boot_filename: &str) -> Result<(), ExecutorError>; | ||||||
|     async fn set_filename(&self, filename: &str) -> Result<(), ExecutorError>; |     async fn set_filename(&self, filename: &str) -> Result<(), ExecutorError>; | ||||||
|  | |||||||
|     async fn set_filename64(&self, filename64: &str) -> Result<(), ExecutorError>; |     async fn set_filename64(&self, filename64: &str) -> Result<(), ExecutorError>; | ||||||
|  |     async fn set_filenameipxe(&self, filenameipxe: &str) -> Result<(), ExecutorError>; | ||||||
|     fn get_ip(&self) -> IpAddress; |     fn get_ip(&self) -> IpAddress; | ||||||
|     fn get_host(&self) -> LogicalHost; |     fn get_host(&self) -> LogicalHost; | ||||||
|     async fn commit_config(&self) -> Result<(), ExecutorError>; |     async fn commit_config(&self) -> Result<(), ExecutorError>; | ||||||
|  | |||||||
| @ -89,4 +89,14 @@ impl DhcpServer for OPNSenseFirewall { | |||||||
| 
 | 
 | ||||||
|         Ok(()) |         Ok(()) | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|  |     async fn set_filenameipxe(&self, filenameipxe: &str) -> Result<(), ExecutorError> { | ||||||
|  |         { | ||||||
|  |             let mut writable_opnsense = self.opnsense_config.write().await; | ||||||
|  |             writable_opnsense.dhcp().set_filenameipxe(filenameipxe); | ||||||
|  |             debug!("OPNsense dhcp server set filenameipxe {filenameipxe}"); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         Ok(()) | ||||||
|  |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -20,7 +20,7 @@ pub struct DhcpScore { | |||||||
|     pub boot_filename: Option<String>, |     pub boot_filename: Option<String>, | ||||||
|     pub filename: Option<String>, |     pub filename: Option<String>, | ||||||
|     pub filename64: Option<String>, |     pub filename64: Option<String>, | ||||||
|     pub filename_ipxe: Option<String>, |     pub filenameipxe: Option<String>, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| impl Score for DhcpScore { | impl Score for DhcpScore { | ||||||
| @ -152,10 +152,23 @@ impl DhcpInterpret { | |||||||
|             None => Outcome::noop(), |             None => Outcome::noop(), | ||||||
|         }; |         }; | ||||||
| 
 | 
 | ||||||
|  |         let filenameipxe_outcome = match &self.score.filenameipxe { | ||||||
| 
				
					
						johnride
						commented  Rendu a 5 copier-coller du meme bout de code ca meriterait un refactor pour une fonction qui prend une closure qui a le minimum d'information. Un petit coup de Claude m'a donne ceci qui semble legit : Rendu a 5 copier-coller du meme bout de code ca meriterait un refactor pour une fonction qui prend une closure qui a le minimum d'information.
Un petit coup de Claude m'a donne ceci qui semble legit :
```rust
async fn set_pxe_options(
    &self,
    _inventory: &Inventory,
    topology: &HAClusterTopology,
) -> Result<Outcome, InterpretError> {
    async fn process_option<T, F, Fut>(
        option: &Option<T>, 
        description: &str,
        action: F
    ) -> Result<Outcome, InterpretError> 
    where
        T: std::fmt::Display,
        F: FnOnce(&T) -> Fut,
        Fut: std::future::Future<Output = Result<(), InterpretError>>,
    {
        match option {
            Some(value) => {
                action(value).await?;
                Ok(Outcome::new(
                    InterpretStatus::SUCCESS,
                    format!("Dhcp Interpret Set {} to {}", description, value),
                ))
            }
            None => Ok(Outcome::noop()),
        }
    }
    let dhcp_server = Arc::new(topology.dhcp_server.clone());
    
    let next_server_outcome = process_option(
        &self.score.next_server,
        "next boot",
        |next_server| dhcp_server.set_next_server(*next_server)
    ).await?;
    
    let boot_filename_outcome = process_option(
        &self.score.boot_filename,
        "boot filename",
        |boot_filename| dhcp_server.set_boot_filename(boot_filename)
    ).await?;
    
    let filename_outcome = process_option(
        &self.score.filename,
        "filename",
        |filename| dhcp_server.set_filename(filename)
    ).await?;
    
    let filename64_outcome = process_option(
        &self.score.filename64,
        "filename64",
        |filename64| dhcp_server.set_filename64(filename64)
    ).await?;
    
    let filenameipxe_outcome = process_option(
        &self.score.filenameipxe,
        "filenameipxe",
        |filenameipxe| dhcp_server.set_filenameipxe(filenameipxe)
    ).await?;
    if next_server_outcome.status == InterpretStatus::NOOP
        && boot_filename_outcome.status == InterpretStatus::NOOP
        && filename_outcome.status == InterpretStatus::NOOP
        && filename64_outcome.status == InterpretStatus::NOOP
        && filenameipxe_outcome.status == InterpretStatus::NOOP
    {
        return Ok(Outcome::noop());
    }
    Ok(Outcome::new(
        InterpretStatus::SUCCESS,
        format!(
            "Dhcp Interpret Set next boot to [{:?}], boot_filename to [{:?}], filename to [{:?}], filename64 to [{:?}], filenameipxe to [{:?}]",
            self.score.next_server, self.score.boot_filename, self.score.filename, self.score.filename64, self.score.filenameipxe
        ),
    ))
}
``` | |||||||
|  |             Some(filenameipxe) => { | ||||||
|  |                 let dhcp_server = Arc::new(topology.dhcp_server.clone()); | ||||||
|  |                 dhcp_server.set_filenameipxe(&filenameipxe).await?; | ||||||
|  |                 Outcome::new( | ||||||
|  |                     InterpretStatus::SUCCESS, | ||||||
|  |                     format!("Dhcp Interpret Set filenameipxe to {filenameipxe}"), | ||||||
|  |                 ) | ||||||
|  |             } | ||||||
|  |             None => Outcome::noop(), | ||||||
|  |         }; | ||||||
|  | 
 | ||||||
|         if next_server_outcome.status == InterpretStatus::NOOP |         if next_server_outcome.status == InterpretStatus::NOOP | ||||||
|             && boot_filename_outcome.status == InterpretStatus::NOOP |             && boot_filename_outcome.status == InterpretStatus::NOOP | ||||||
|             && filename_outcome.status == InterpretStatus::NOOP |             && filename_outcome.status == InterpretStatus::NOOP | ||||||
|             && filename64_outcome.status == InterpretStatus::NOOP |             && filename64_outcome.status == InterpretStatus::NOOP | ||||||
|  |             && filenameipxe_outcome.status == InterpretStatus::NOOP | ||||||
|         { |         { | ||||||
|             return Ok(Outcome::noop()); |             return Ok(Outcome::noop()); | ||||||
|         } |         } | ||||||
| @ -163,8 +176,8 @@ impl DhcpInterpret { | |||||||
|         Ok(Outcome::new( |         Ok(Outcome::new( | ||||||
|             InterpretStatus::SUCCESS, |             InterpretStatus::SUCCESS, | ||||||
|             format!( |             format!( | ||||||
|                 "Dhcp Interpret Set next boot to [{:?}], boot_filename to [{:?}], filename to [{:?}], filename64 to [{:?}]", |                 "Dhcp Interpret Set next boot to [{:?}], boot_filename to [{:?}], filename to [{:?}], filename64 to [{:?}], filenameipxe to [:{:?}]", | ||||||
|                 self.score.boot_filename, self.score.boot_filename, self.score.filename, self.score.filename64 |                 self.score.boot_filename, self.score.boot_filename, self.score.filename, self.score.filename64, self.score.filenameipxe | ||||||
|             ), |             ), | ||||||
|         )) |         )) | ||||||
|     } |     } | ||||||
|  | |||||||
| @ -33,7 +33,7 @@ impl OKDDhcpScore { | |||||||
|                 host_binding, |                 host_binding, | ||||||
|                 next_server: Some(topology.router.get_gateway()), |                 next_server: Some(topology.router.get_gateway()), | ||||||
|                 boot_filename: None, |                 boot_filename: None, | ||||||
|                 filename_ipxe: Some(format!("{}:8080/boot.ipxe", topology.router.get_gateway())), |                 filenameipxe: Some(format!("{}:8080/boot.ipxe", topology.router.get_gateway())), | ||||||
|                 filename: Some("undionly.kpxe".to_string()), |                 filename: Some("undionly.kpxe".to_string()), | ||||||
|                 filename64: Some("ipxe.efi".to_string()), |                 filename64: Some("ipxe.efi".to_string()), | ||||||
|             }, |             }, | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	
Ca gosse de devoir fix ces dummy la tout le temps. Peut-etre qu'on pourrait creer une macro assez facilement qui cree une implementation dummy? Pas urgent.