summaryrefslogtreecommitdiff
path: root/src/PVE/API2/Network/SDN/Subnets.pm
diff options
context:
space:
mode:
authorThomas Lamprecht <t.lamprecht@proxmox.com>2025-06-16 22:28:00 +0200
committerThomas Lamprecht <t.lamprecht@proxmox.com>2025-06-16 22:39:01 +0200
commitd6ca483c5bde56367dde0a9715a55e0a3a1de4d9 (patch)
treee380fbdd93f1589a70bcb9d8a6638e53ef138ef1 /src/PVE/API2/Network/SDN/Subnets.pm
parent33aab51365bffc21b840c121a7673c9a2a30921a (diff)
auto-format code using perltidy with Proxmox style guide
using the new top-level `make tidy` target, which calls perltidy via our wrapper to enforce the desired style as closely as possible. Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
Diffstat (limited to 'src/PVE/API2/Network/SDN/Subnets.pm')
-rw-r--r--src/PVE/API2/Network/SDN/Subnets.pm360
1 files changed, 189 insertions, 171 deletions
diff --git a/src/PVE/API2/Network/SDN/Subnets.pm b/src/PVE/API2/Network/SDN/Subnets.pm
index 7a4c331..c9f5452 100644
--- a/src/PVE/API2/Network/SDN/Subnets.pm
+++ b/src/PVE/API2/Network/SDN/Subnets.pm
@@ -55,291 +55,309 @@ my $check_vnet_access = sub {
$rpcenv->check_any($authuser, "/sdn/zones/$zoneid/$vnet", $privs);
};
-__PACKAGE__->register_method ({
+__PACKAGE__->register_method({
name => 'index',
path => '',
method => 'GET',
description => "SDN subnets index.",
permissions => {
- description => "Only list entries where you have 'SDN.Audit' or 'SDN.Allocate' permissions on '/sdn/zones/<zone>/<vnet>'",
- user => 'all',
+ description =>
+ "Only list entries where you have 'SDN.Audit' or 'SDN.Allocate' permissions on '/sdn/zones/<zone>/<vnet>'",
+ user => 'all',
},
parameters => {
- additionalProperties => 0,
- properties => {
- vnet => get_standard_option('pve-sdn-vnet-id'),
- running => {
- type => 'boolean',
- optional => 1,
- description => "Display running config.",
- },
- pending => {
- type => 'boolean',
- optional => 1,
- description => "Display pending config.",
- },
+ additionalProperties => 0,
+ properties => {
+ vnet => get_standard_option('pve-sdn-vnet-id'),
+ running => {
+ type => 'boolean',
+ optional => 1,
+ description => "Display running config.",
+ },
+ pending => {
+ type => 'boolean',
+ optional => 1,
+ description => "Display pending config.",
+ },
},
},
returns => {
- type => 'array',
- items => {
- type => "object",
- properties => {},
- },
- links => [ { rel => 'child', href => "{subnet}" } ],
+ type => 'array',
+ items => {
+ type => "object",
+ properties => {},
+ },
+ links => [{ rel => 'child', href => "{subnet}" }],
},
code => sub {
- my ($param) = @_;
+ my ($param) = @_;
- my $vnetid = $param->{vnet};
- my $privs = [ 'SDN.Audit', 'SDN.Allocate' ];
- &$check_vnet_access($vnetid, $privs);
+ my $vnetid = $param->{vnet};
+ my $privs = ['SDN.Audit', 'SDN.Allocate'];
+ &$check_vnet_access($vnetid, $privs);
my $cfg = {};
- if($param->{pending}) {
- my $running_cfg = PVE::Network::SDN::running_config();
- my $config = PVE::Network::SDN::Subnets::config();
- $cfg = PVE::Network::SDN::pending_config($running_cfg, $config, 'subnets');
+ if ($param->{pending}) {
+ my $running_cfg = PVE::Network::SDN::running_config();
+ my $config = PVE::Network::SDN::Subnets::config();
+ $cfg = PVE::Network::SDN::pending_config($running_cfg, $config, 'subnets');
} elsif ($param->{running}) {
- my $running_cfg = PVE::Network::SDN::running_config();
- $cfg = $running_cfg->{subnets};
+ my $running_cfg = PVE::Network::SDN::running_config();
+ $cfg = $running_cfg->{subnets};
} else {
- $cfg = PVE::Network::SDN::Subnets::config();
+ $cfg = PVE::Network::SDN::Subnets::config();
}
- my @sids = PVE::Network::SDN::Subnets::sdn_subnets_ids($cfg);
- my $res = [];
- foreach my $id (@sids) {
- my $scfg = &$api_sdn_subnets_config($cfg, $id);
- next if !$scfg->{vnet} || $scfg->{vnet} ne $vnetid;
- push @$res, $scfg;
- }
+ my @sids = PVE::Network::SDN::Subnets::sdn_subnets_ids($cfg);
+ my $res = [];
+ foreach my $id (@sids) {
+ my $scfg = &$api_sdn_subnets_config($cfg, $id);
+ next if !$scfg->{vnet} || $scfg->{vnet} ne $vnetid;
+ push @$res, $scfg;
+ }
- return $res;
- }});
+ return $res;
+ },
+});
-__PACKAGE__->register_method ({
+__PACKAGE__->register_method({
name => 'read',
path => '{subnet}',
method => 'GET',
description => "Read sdn subnet configuration.",
permissions => {
- description => "Require 'SDN.Audit' or 'SDN.Allocate' permissions on '/sdn/zones/<zone>/<vnet>'",
- user => 'all',
+ description =>
+ "Require 'SDN.Audit' or 'SDN.Allocate' permissions on '/sdn/zones/<zone>/<vnet>'",
+ user => 'all',
},
parameters => {
- additionalProperties => 0,
- properties => {
- vnet => get_standard_option('pve-sdn-vnet-id'),
- subnet => get_standard_option('pve-sdn-subnet-id', {
- completion => \&PVE::Network::SDN::Subnets::complete_sdn_subnets,
- }),
- running => {
- type => 'boolean',
- optional => 1,
- description => "Display running config.",
- },
- pending => {
- type => 'boolean',
- optional => 1,
- description => "Display pending config.",
- },
+ additionalProperties => 0,
+ properties => {
+ vnet => get_standard_option('pve-sdn-vnet-id'),
+ subnet => get_standard_option(
+ 'pve-sdn-subnet-id',
+ {
+ completion => \&PVE::Network::SDN::Subnets::complete_sdn_subnets,
+ },
+ ),
+ 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 ($param) = @_;
- my $vnet = extract_param($param, 'vnet');
- my $privs = [ 'SDN.Audit', 'SDN.Allocate' ];
- &$check_vnet_access($vnet, $privs);
+ my $vnet = extract_param($param, 'vnet');
+ my $privs = ['SDN.Audit', 'SDN.Allocate'];
+ &$check_vnet_access($vnet, $privs);
my $cfg = {};
- if($param->{pending}) {
- my $running_cfg = PVE::Network::SDN::running_config();
- my $config = PVE::Network::SDN::Subnets::config();
- $cfg = PVE::Network::SDN::pending_config($running_cfg, $config, 'subnets');
+ if ($param->{pending}) {
+ my $running_cfg = PVE::Network::SDN::running_config();
+ my $config = PVE::Network::SDN::Subnets::config();
+ $cfg = PVE::Network::SDN::pending_config($running_cfg, $config, 'subnets');
} elsif ($param->{running}) {
- my $running_cfg = PVE::Network::SDN::running_config();
- $cfg = $running_cfg->{subnets};
+ my $running_cfg = PVE::Network::SDN::running_config();
+ $cfg = $running_cfg->{subnets};
} else {
- $cfg = PVE::Network::SDN::Subnets::config();
+ $cfg = PVE::Network::SDN::Subnets::config();
}
my $scfg = &$api_sdn_subnets_config($cfg, $param->{subnet});
- raise_param_exc({ vnet => "wrong vnet"}) if $vnet ne $scfg->{vnet};
+ raise_param_exc({ vnet => "wrong vnet" }) if $vnet ne $scfg->{vnet};
- return $scfg;
- }});
+ return $scfg;
+ },
+});
-__PACKAGE__->register_method ({
+__PACKAGE__->register_method({
name => 'create',
protected => 1,
path => '',
method => 'POST',
description => "Create a new sdn subnet object.",
permissions => {
- description => "Require 'SDN.Allocate' permission on '/sdn/zones/<zone>/<vnet>'",
- user => 'all',
+ description => "Require 'SDN.Allocate' permission on '/sdn/zones/<zone>/<vnet>'",
+ user => 'all',
},
parameters => PVE::Network::SDN::SubnetPlugin->createSchema(),
returns => { type => 'null' },
code => sub {
- my ($param) = @_;
+ my ($param) = @_;
- my $type = extract_param($param, 'type');
- my $cidr = extract_param($param, 'subnet');
+ my $type = extract_param($param, 'type');
+ my $cidr = extract_param($param, 'subnet');
- my $vnet = $param->{vnet};
- my $privs = [ 'SDN.Allocate' ];
- &$check_vnet_access($vnet, $privs);
+ my $vnet = $param->{vnet};
+ my $privs = ['SDN.Allocate'];
+ &$check_vnet_access($vnet, $privs);
- # create /etc/pve/sdn directory
- PVE::Cluster::check_cfs_quorum();
- mkdir("/etc/pve/sdn") if ! -d '/etc/pve/sdn';
+ # create /etc/pve/sdn directory
+ PVE::Cluster::check_cfs_quorum();
+ mkdir("/etc/pve/sdn") if !-d '/etc/pve/sdn';
PVE::Network::SDN::lock_sdn_config(
- sub {
+ sub {
- my $cfg = PVE::Network::SDN::Subnets::config();
- my $zone_cfg = PVE::Network::SDN::Zones::config();
- my $vnet_cfg = PVE::Network::SDN::Vnets::config();
- my $vnet = $param->{vnet};
- my $zoneid = $vnet_cfg->{ids}->{$vnet}->{zone};
- my $zone = $zone_cfg->{ids}->{$zoneid};
- my $id = $cidr =~ s/\//-/r;
- $id = "$zoneid-$id";
-
- my $opts = PVE::Network::SDN::SubnetPlugin->check_config($id, $param, 1, 1);
+ my $cfg = PVE::Network::SDN::Subnets::config();
+ my $zone_cfg = PVE::Network::SDN::Zones::config();
+ my $vnet_cfg = PVE::Network::SDN::Vnets::config();
+ my $vnet = $param->{vnet};
+ my $zoneid = $vnet_cfg->{ids}->{$vnet}->{zone};
+ my $zone = $zone_cfg->{ids}->{$zoneid};
+ my $id = $cidr =~ s/\//-/r;
+ $id = "$zoneid-$id";
- my $scfg = undef;
- if ($scfg = PVE::Network::SDN::Subnets::sdn_subnets_config($cfg, $id, 1)) {
- die "sdn subnet object ID '$id' already defined\n";
- }
+ my $opts = PVE::Network::SDN::SubnetPlugin->check_config($id, $param, 1, 1);
- $cfg->{ids}->{$id} = $opts;
+ my $scfg = undef;
+ if ($scfg = PVE::Network::SDN::Subnets::sdn_subnets_config($cfg, $id, 1)) {
+ die "sdn subnet object ID '$id' already defined\n";
+ }
- my $subnet = PVE::Network::SDN::Subnets::sdn_subnets_config($cfg, $id);
- PVE::Network::SDN::SubnetPlugin->on_update_hook($zone, $id, $subnet);
+ $cfg->{ids}->{$id} = $opts;
- PVE::Network::SDN::Subnets::write_config($cfg);
+ my $subnet = PVE::Network::SDN::Subnets::sdn_subnets_config($cfg, $id);
+ PVE::Network::SDN::SubnetPlugin->on_update_hook($zone, $id, $subnet);
- }, "create sdn subnet object failed");
+ PVE::Network::SDN::Subnets::write_config($cfg);
- return undef;
- }});
+ },
+ "create sdn subnet object failed",
+ );
-__PACKAGE__->register_method ({
+ return undef;
+ },
+});
+
+__PACKAGE__->register_method({
name => 'update',
protected => 1,
path => '{subnet}',
method => 'PUT',
description => "Update sdn subnet object configuration.",
permissions => {
- description => "Require 'SDN.Allocate' permission on '/sdn/zones/<zone>/<vnet>'",
- user => 'all',
+ description => "Require 'SDN.Allocate' permission on '/sdn/zones/<zone>/<vnet>'",
+ user => 'all',
},
parameters => PVE::Network::SDN::SubnetPlugin->updateSchema(),
returns => { type => 'null' },
code => sub {
- my ($param) = @_;
+ my ($param) = @_;
- my $id = extract_param($param, 'subnet');
- my $digest = extract_param($param, 'digest');
- my $delete = extract_param($param, 'delete');
+ my $id = extract_param($param, 'subnet');
+ my $digest = extract_param($param, 'digest');
+ my $delete = extract_param($param, 'delete');
- my $vnet = $param->{vnet};
+ my $vnet = $param->{vnet};
- my $privs = [ 'SDN.Allocate' ];
- &$check_vnet_access($vnet, $privs);
+ my $privs = ['SDN.Allocate'];
+ &$check_vnet_access($vnet, $privs);
PVE::Network::SDN::lock_sdn_config(
- sub {
+ sub {
- my $cfg = PVE::Network::SDN::Subnets::config();
- my $zone_cfg = PVE::Network::SDN::Zones::config();
- my $vnet_cfg = PVE::Network::SDN::Vnets::config();
- my $zoneid = $vnet_cfg->{ids}->{$vnet}->{zone};
- my $zone = $zone_cfg->{ids}->{$zoneid};
+ my $cfg = PVE::Network::SDN::Subnets::config();
+ my $zone_cfg = PVE::Network::SDN::Zones::config();
+ my $vnet_cfg = PVE::Network::SDN::Vnets::config();
+ my $zoneid = $vnet_cfg->{ids}->{$vnet}->{zone};
+ my $zone = $zone_cfg->{ids}->{$zoneid};
- my $scfg = &$api_sdn_subnets_config($cfg, $id);
+ my $scfg = &$api_sdn_subnets_config($cfg, $id);
- PVE::SectionConfig::assert_if_modified($cfg, $digest);
+ PVE::SectionConfig::assert_if_modified($cfg, $digest);
- my $opts = PVE::Network::SDN::SubnetPlugin->check_config($id, $param, 0, 1);
+ my $opts = PVE::Network::SDN::SubnetPlugin->check_config($id, $param, 0, 1);
- my $data = $cfg->{ids}->{$id};
- if ($delete) {
- $delete = [ PVE::Tools::split_list($delete) ];
- my $options =
- PVE::Network::SDN::SubnetPlugin->private()->{options}->{$data->{type}};
- PVE::SectionConfig::delete_from_config($data, $options, $opts, $delete);
- }
- $data->{$_} = $opts->{$_} for keys $opts->%*;
+ my $data = $cfg->{ids}->{$id};
+ if ($delete) {
+ $delete = [PVE::Tools::split_list($delete)];
+ my $options =
+ PVE::Network::SDN::SubnetPlugin->private()->{options}->{ $data->{type} };
+ PVE::SectionConfig::delete_from_config($data, $options, $opts, $delete);
+ }
+ $data->{$_} = $opts->{$_} for keys $opts->%*;
- my $subnet = PVE::Network::SDN::Subnets::sdn_subnets_config($cfg, $id);
- PVE::Network::SDN::SubnetPlugin->on_update_hook($zone, $id, $subnet, $scfg);
+ my $subnet = PVE::Network::SDN::Subnets::sdn_subnets_config($cfg, $id);
+ PVE::Network::SDN::SubnetPlugin->on_update_hook($zone, $id, $subnet, $scfg);
- PVE::Network::SDN::Subnets::write_config($cfg);
+ PVE::Network::SDN::Subnets::write_config($cfg);
- }, "update sdn subnet object failed");
+ },
+ "update sdn subnet object failed",
+ );
- return undef;
- }});
+ return undef;
+ },
+});
-__PACKAGE__->register_method ({
+__PACKAGE__->register_method({
name => 'delete',
protected => 1,
path => '{subnet}',
method => 'DELETE',
description => "Delete sdn subnet object configuration.",
permissions => {
- description => "Require 'SDN.Allocate' permission on '/sdn/zones/<zone>/<vnet>'",
- user => 'all',
+ description => "Require 'SDN.Allocate' permission on '/sdn/zones/<zone>/<vnet>'",
+ user => 'all',
},
parameters => {
- additionalProperties => 0,
- properties => {
+ additionalProperties => 0,
+ properties => {
vnet => get_standard_option('pve-sdn-vnet-id'),
- subnet => get_standard_option('pve-sdn-subnet-id', {
- completion => \&PVE::Network::SDN::Subnets::complete_sdn_subnets,
- }),
- },
+ subnet => get_standard_option(
+ 'pve-sdn-subnet-id',
+ {
+ completion => \&PVE::Network::SDN::Subnets::complete_sdn_subnets,
+ },
+ ),
+ },
},
returns => { type => 'null' },
code => sub {
- my ($param) = @_;
+ my ($param) = @_;
- my $id = extract_param($param, 'subnet');
- my $vnet = extract_param($param, 'vnet');
- my $privs = [ 'SDN.Allocate' ];
- &$check_vnet_access($vnet, $privs);
+ my $id = extract_param($param, 'subnet');
+ my $vnet = extract_param($param, 'vnet');
+ my $privs = ['SDN.Allocate'];
+ &$check_vnet_access($vnet, $privs);
PVE::Network::SDN::lock_sdn_config(
- sub {
- my $cfg = PVE::Network::SDN::Subnets::config();
-
- my $scfg = PVE::Network::SDN::Subnets::sdn_subnets_config($cfg, $id, 1);
+ sub {
+ my $cfg = PVE::Network::SDN::Subnets::config();
- my $vnets_cfg = PVE::Network::SDN::Vnets::config();
+ my $scfg = PVE::Network::SDN::Subnets::sdn_subnets_config($cfg, $id, 1);
- PVE::Network::SDN::SubnetPlugin->on_delete_hook($id, $cfg, $vnets_cfg);
+ my $vnets_cfg = PVE::Network::SDN::Vnets::config();
- my $zone_cfg = PVE::Network::SDN::Zones::config();
- my $zoneid = $vnets_cfg->{ids}->{$vnet}->{zone};
- my $zone = $zone_cfg->{ids}->{$zoneid};
+ PVE::Network::SDN::SubnetPlugin->on_delete_hook($id, $cfg, $vnets_cfg);
- PVE::Network::SDN::Subnets::del_subnet($zone, $id, $scfg);
+ my $zone_cfg = PVE::Network::SDN::Zones::config();
+ my $zoneid = $vnets_cfg->{ids}->{$vnet}->{zone};
+ my $zone = $zone_cfg->{ids}->{$zoneid};
- delete $cfg->{ids}->{$id};
+ PVE::Network::SDN::Subnets::del_subnet($zone, $id, $scfg);
- PVE::Network::SDN::Subnets::write_config($cfg);
+ delete $cfg->{ids}->{$id};
- }, "delete sdn subnet object failed");
+ PVE::Network::SDN::Subnets::write_config($cfg);
+ },
+ "delete sdn subnet object failed",
+ );
- return undef;
- }});
+ return undef;
+ },
+});
1;