[pve-devel] [PATCH v10 pve-network 27/35] api: add running/pending zones/vnets/subnets/controllers
Thomas Lamprecht
t.lamprecht at proxmox.com
Thu Oct 8 11:04:43 CEST 2020
On 05.10.20 17:09, Alexandre Derumier wrote:
> diff --git a/PVE/API2/Network/SDN/Vnets.pm b/PVE/API2/Network/SDN/Vnets.pm
> index 0fbb747..6ff61c5 100644
> --- a/PVE/API2/Network/SDN/Vnets.pm
> +++ b/PVE/API2/Network/SDN/Vnets.pm
> @@ -3,6 +3,8 @@ package PVE::API2::Network::SDN::Vnets;
> use strict;
> use warnings;
>
> +use Hash::Diff qw( diff );
You add this use statement here, but never use it nor add the corresponding
dependency to debian/control (would probably be libhash-diff-perl?)
Can I just drop this line or do I overlook something?
> +
> use PVE::SafeSyslog;
> use PVE::Tools qw(extract_param);
> use PVE::Cluster qw(cfs_read_file cfs_write_file);
> @@ -33,10 +35,22 @@ my $api_sdn_vnets_config = sub {
> my $scfg = dclone(PVE::Network::SDN::Vnets::sdn_vnets_config($cfg, $id));
> $scfg->{vnet} = $id;
> $scfg->{digest} = $cfg->{digest};
> -
> +
> return $scfg;
> };
>
> +my $api_sdn_vnets_deleted_config = sub {
> + my ($cfg, $running_cfg, $id) = @_;
> +
> + if (!$cfg->{ids}->{$id}) {
> +
> + my $vnet_cfg = dclone(PVE::Network::SDN::Vnets::sdn_vnets_config($running_cfg->{vnets}, $id));
> + $vnet_cfg->{state} = "deleted";
> + $vnet_cfg->{vnet} = $id;
> + return $vnet_cfg;
> + }
> +};
> +
> __PACKAGE__->register_method ({
> name => 'index',
> path => '',
> @@ -49,6 +63,18 @@ __PACKAGE__->register_method ({
> },
> parameters => {
> additionalProperties => 0,
> + properties => {
> + running => {
> + type => 'boolean',
> + optional => 1,
> + description => "Display running config.",
> + },
> + pending => {
> + type => 'boolean',
> + optional => 1,
> + description => "Display pending config.",
> + },
> + },
> },
> returns => {
> type => 'array',
> @@ -64,7 +90,17 @@ __PACKAGE__->register_method ({
> my $rpcenv = PVE::RPCEnvironment::get();
> my $authuser = $rpcenv->get_user();
>
> - my $cfg = PVE::Network::SDN::Vnets::config();
> + my $cfg = {};
> + if($param->{pending}) {
> + my $running_cfg = PVE::Network::SDN::config();
> + my $config = PVE::Network::SDN::Vnets::config();
> + $cfg = PVE::Network::SDN::pending_config($running_cfg, $config, 'vnets');
> + } elsif ($param->{running}) {
> + my $running_cfg = PVE::Network::SDN::config();
> + $cfg = $running_cfg->{vnets};
> + } else {
> + $cfg = PVE::Network::SDN::Vnets::config();
> + }
>
> my @sids = PVE::Network::SDN::Vnets::sdn_vnets_ids($cfg);
> my $res = [];
> @@ -93,13 +129,33 @@ __PACKAGE__->register_method ({
> vnet => get_standard_option('pve-sdn-vnet-id', {
> completion => \&PVE::Network::SDN::Vnets::complete_sdn_vnets,
> }),
> + running => {
> + type => 'boolean',
> + optional => 1,
> + description => "Display running config.",
> + },
> + pending => {
> + type => 'boolean',
> + optional => 1,
> + description => "Display pending config.",
> + },
> },
> },
> returns => { type => 'object' },
> code => sub {
> my ($param) = @_;
>
> - my $cfg = PVE::Network::SDN::Vnets::config();
> + my $cfg = {};
> + if($param->{pending}) {
> + my $running_cfg = PVE::Network::SDN::config();
> + my $config = PVE::Network::SDN::Vnets::config();
> + $cfg = PVE::Network::SDN::pending_config($running_cfg, $config, 'vnets');
> + } elsif ($param->{running}) {
> + my $running_cfg = PVE::Network::SDN::config();
> + $cfg = $running_cfg->{vnets};
> + } else {
> + $cfg = PVE::Network::SDN::Vnets::config();
> + }
>
> return $api_sdn_vnets_config->($cfg, $param->{vnet});
> }});
More information about the pve-devel
mailing list