feat: started to prepare inventory / topoplogy for NCD #1

Merged
johnride merged 17 commits from feat/settingUpNDC into master 2025-05-06 16:38:41 +00:00
Owner

Debut setup inventory / topology pour NCD

J'ai aussi fixé les problèmes de path suite au refactor /data

Ajouté le contrôle de nouveaux fields dans la config dhcp pour pxe

updaté le README avec un cookbook sur l'ajout de nouveaux fields

créé un shell de nouveau score iPXE

Debut setup inventory / topology pour NCD J'ai aussi fixé les problèmes de path suite au refactor `/data` Ajouté le contrôle de nouveaux fields dans la config dhcp pour pxe updaté le README avec un cookbook sur l'ajout de nouveaux fields créé un shell de nouveau score iPXE
stremblay added 1 commit 2025-02-22 16:16:51 +00:00
stremblay requested review from johnride 2025-02-22 16:16:57 +00:00
stremblay added 1 commit 2025-02-22 19:24:56 +00:00
stremblay added 1 commit 2025-02-23 21:40:07 +00:00
stremblay added 1 commit 2025-03-01 13:56:50 +00:00
stremblay added 1 commit 2025-03-01 15:17:57 +00:00
stremblay added 1 commit 2025-03-01 15:25:28 +00:00
stremblay added 1 commit 2025-03-01 15:29:27 +00:00
stremblay added 1 commit 2025-03-01 15:41:57 +00:00
stremblay added 1 commit 2025-03-01 15:51:06 +00:00
stremblay added 1 commit 2025-03-02 12:59:35 +00:00
stremblay added 1 commit 2025-03-02 14:37:17 +00:00
stremblay added 1 commit 2025-03-02 15:08:02 +00:00
stremblay added 1 commit 2025-03-02 17:14:08 +00:00
johnride requested changes 2025-03-03 21:48:00 +00:00
johnride left a comment
Owner

Quelques details a refactor mais tres bien dans l'ensemble.

Le plus important c'est de ne pas polluer le README avec autant d'information sur un detail d'implementation.

Quelques details a refactor mais tres bien dans l'ensemble. Le plus important c'est de ne pas polluer le README avec autant d'information sur un detail d'implementation.
README.md Outdated
@ -8,2 +8,4 @@
This will run the nationtech bin (likely `private_repos/nationtech/src/main.rs`) on any change in the harmony or private_repos folders.
## Supporting a new field in OPNSense `config.xml`
Owner

Ca ne va pas au complet dans le root README. Ca irait dans docs/opense-config.md.

Dans ce fichier-ci je mettrais un court resume genre :

FAQ : 

I am receiving error `missing field <some_field> in struct CaddyConfig`

This means you are using an unsupported (yet) configuration for this module. Adding a new field is very easy, see [opnsense-config Adding a Field](docs/opnsense-config.md)

Et d'autres entrees de FAQ si pertinent, je n'ai pas lu tout le detail

Ca ne va pas au complet dans le root README. Ca irait dans docs/opense-config.md. Dans ce fichier-ci je mettrais un court resume genre : ```md FAQ : I am receiving error `missing field <some_field> in struct CaddyConfig` This means you are using an unsupported (yet) configuration for this module. Adding a new field is very easy, see [opnsense-config Adding a Field](docs/opnsense-config.md) ``` Et d'autres entrees de FAQ si pertinent, je n'ai pas lu tout le detail
@ -1 +0,0 @@
hey i am paul
Owner

heille mon paul!

heille mon paul!
@ -14,0 +67,4 @@
let inventory = Inventory {
location: Location::new(
"I am mobile".to_string(),
"earth".to_string(),
Owner

universe ?
Physical world ?
Reality ?
Existence ?
Truth ?
Answer ?
42 ?

universe ? Physical world ? Reality ? Existence ? Truth ? Answer ? 42 ?
@ -98,3 +98,3 @@
fn get_supported_protocol_names(&self) -> String {
todo!()
// todo!()
Owner

no comment

no comment
@ -48,6 +48,9 @@ pub trait DhcpServer: Send + Sync {
async fn list_static_mappings(&self) -> Vec<(MacAddress, IpAddress)>;
async fn set_next_server(&self, ip: IpAddress) -> Result<(), ExecutorError>;
async fn set_boot_filename(&self, boot_filename: &str) -> Result<(), ExecutorError>;
async fn set_filename(&self, filename: &str) -> Result<(), ExecutorError>;
Owner

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.

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.
@ -62,3 +62,3 @@
config
.upload_files(
"../../../watchguard/caddy_config",
"./data/watchguard/caddy_config",
Owner

Ca prendra une methode plus intelligente un jour que juste ./ mais good for now.

Ca prendra une methode plus intelligente un jour que juste `./` mais good for now.
@ -128,0 +152,4 @@
None => Outcome::noop(),
};
let filenameipxe_outcome = match &self.score.filenameipxe {
Owner

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 :

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
        ),
    ))
}
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 ), )) } ```
@ -0,0 +11,4 @@
#[derive(Debug, new, Clone)]
pub struct IpxeScore {
//files_to_serve: Url,
Owner

no comment

no comment
@ -0,0 +41,4 @@
_topology: &HAClusterTopology,
) -> Result<Outcome, InterpretError> {
/*
let http_server = &topology.http_server;
Owner

no commemememememememememennttntntnttt

no commemememememememememennttntntnttt
@ -0,0 +53,4 @@
"Success running {}",
self.score.name()
)))
//Ok(Outcome::success("Success".to_string()))
Owner

no comomemoememtn

no comomemoememtn
@ -0,0 +71,4 @@
fn get_children(&self) -> Vec<Id> {
todo!()
}
}
Owner

Delete le fichier? Ca ne fait rien en ce moment?

Delete le fichier? Ca ne fait rien en ce moment?
johnride added 2 commits 2025-05-06 15:45:24 +00:00
johnride added 2 commits 2025-05-06 16:00:59 +00:00
johnride merged commit 78e9893341 into master 2025-05-06 16:38:41 +00:00
johnride deleted branch feat/settingUpNDC 2025-05-06 16:38:41 +00:00
Sign in to join this conversation.
No reviewers
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: NationTech/harmony#1
No description provided.