> +__PACKAGE__->register_method({
> +    name => 'dry-run',
> +    path => 'dry-run',
> +    method => 'GET',
> +    permissions => {
> +        check => ['perm', '/nodes/{node}', ['Sys.Modify']],
> +    },
> +    description =>
> +        "Dry-run the SDN apply action and return the difference between the 
> current configuration and the pending configuration",
> +    protected => 1,
> +    proxyto => 'node',
> +    parameters => {
> +        additionalProperties => 0,
> +        properties => {
> +            node => get_standard_option('pve-node'),
> +        },
> +    },
> +
> +    returns => {
> +        type => 'object',
> +        properties => {
> +            "frr-diff" => {
> +                type => 'string',
> +                description =>
> +                    'The difference between the current and pending FRR 
> configuration.',
> +            },
> +            "interfaces-diff" => {
> +                type => 'string',
> +                description =>
> +                    'The difference between the current and pending 
> /etc/network/interfaces.d/sdn configuration.',
> +            },
> +        },
> +    },
> +    code => sub {
> +        my ($param) = @_;
> +
> +        my $cfg = PVE::Network::SDN::compile_running_cfg();
> +
> +        my $fabric_cfg = PVE::Network::SDN::Fabrics::config(0);
> +        my $frr_cfg = PVE::Network::SDN::generate_frr_raw_config($cfg, 
> $fabric_cfg);
> +        my $new_cfg_frr = 
> PVE::Network::SDN::Frr::raw_config_to_string($frr_cfg);
> +
> +        # compile running config and skip version bump
> +        my $running_cfg = PVE::Network::SDN::compile_running_cfg(1);

Ah, a small oopsie happened here :(

The $running_cfg declaration should be at the top instead of the $cfg 
declaration.
This way we don't skip the version bump when having a fabrics-only sdn config.

> +
> +        my $new_interfaces_cfg =
> +            PVE::Network::SDN::generate_raw_etc_network_config($running_cfg);
> +
> +        my ($frr_tmp_filename, $frr_tmp_fh) = 
> PVE::File::tempfile_contents($new_cfg_frr, 700);
> +
> +        my ($interfaces_tmp_filename, $interfaces_tmp_fh) =
> +            PVE::File::tempfile_contents($new_interfaces_cfg, 700);
> +
> +        my $return_value = {};
> +        $return_value->{"frr-diff"} = get_diff('/etc/frr/frr.conf', 
> $frr_tmp_filename);
> +        $return_value->{"interfaces-diff"} =
> +            get_diff('/etc/network/interfaces.d/sdn', 
> $interfaces_tmp_filename);
> +
> +        close($frr_tmp_fh);
> +        close($interfaces_tmp_fh);
> +        return $return_value;
> +    },
> +});
> +
>  1;
> [snip]

Gabriel



Reply via email to