[PATCH pve-network v5 29/46] api2: add route map entry module

Stefan Hanreich
2026-05-05T15:44:19Z

This module contains the following API endpoints:

GET /route-maps/<id>/<order> - gets the order'th entry in route map
<id>
PUT /route-maps/<id>/<order> - updates the order'th entry in
route map <id>
DELETE /route-maps/<id>/<order> - deletes the order'th
entry in route map <id>

Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
---
src/PVE/API2/Network/SDN/RouteMaps/Makefile | 1 +
.../API2/Network/SDN/RouteMaps/RouteMap.pm | 6 +
.../Network/SDN/RouteMaps/RouteMapEntry.pm | 139 ++++++++++++++++++
3 files changed, 146 insertions(+)
create mode 100644 src/PVE/API2/Network/SDN/RouteMaps/RouteMapEntry.pm

diff --git a/src/PVE/API2/Network/SDN/RouteMaps/Makefile b/src/PVE/API2/Network/SDN/RouteMaps/Makefile
index 3d0a928..07b45e9 100644
--- a/src/PVE/API2/Network/SDN/RouteMaps/Makefile
+++ b/src/PVE/API2/Network/SDN/RouteMaps/Makefile
@@ -1,4 +1,5 @@
SOURCES=RouteMap.pm\
+ RouteMapEntry.pm

PERL5DIR=${DESTDIR}/usr/share/perl5
diff --git a/src/PVE/API2/Network/SDN/RouteMaps/RouteMap.pm b/src/PVE/API2/Network/SDN/RouteMaps/RouteMap.pm
index 2dbea09..a6be28d 100644
--- a/src/PVE/API2/Network/SDN/RouteMaps/RouteMap.pm
+++ b/src/PVE/API2/Network/SDN/RouteMaps/RouteMap.pm
@@ -3,6 +3,7 @@ package PVE::API2::Network::SDN::RouteMaps::RouteMap;
use strict;
use warnings;

+use PVE::API2::Network::SDN::RouteMaps::RouteMapEntry;
use PVE::JSONSchema qw(get_standard_option);
use PVE::Exception qw(raise_param_exc);
use PVE::Tools qw(extract_param);
@@ -10,6 +11,11 @@ use PVE::Tools qw(extract_param);
use PVE::RESTHandler;
use base qw(PVE::RESTHandler);

+__PACKAGE__->register_method({
+ subclass => "PVE::API2::Network::SDN::RouteMaps::RouteMapEntry",
+ path => '{order}',
+});
+
__PACKAGE__->register_method({
name => 'list_route_map_entries',
path => '',
diff --git a/src/PVE/API2/Network/SDN/RouteMaps/RouteMapEntry.pm b/src/PVE/API2/Network/SDN/RouteMaps/RouteMapEntry.pm
new file mode 100644
index 0000000..6cede04
--- /dev/null
+++ b/src/PVE/API2/Network/SDN/RouteMaps/RouteMapEntry.pm
@@ -0,0 +1,139 @@
+package PVE::API2::Network::SDN::RouteMaps::RouteMapEntry;
+
+use strict;
+use warnings;
+
+use PVE::Exception qw(raise_param_exc);
+use PVE::JSONSchema qw(get_standard_option);
+use PVE::Tools qw(extract_param);
+
+use PVE::RESTHandler;
+use base qw(PVE::RESTHandler);
+
+__PACKAGE__->register_method({
+ name => 'get_route_map_entry',
+ path => '',
+ method => 'GET',
+ permissions => {
+ check =>
+ ['perm', '/sdn/route-maps/{route-map-id}', ['SDN.Audit', 'SDN.Allocate'], any => 1],
+ },
+ description => "Get Route Map Entry",
+ parameters => {
+ properties => {
+ 'route-map-id' => get_standard_option('pve-sdn-route-map-id'),
+ 'order' => get_standard_option('pve-sdn-route-map-order'),
+ },
+ },
+ returns => {
+ type => "object",
+ properties => PVE::Network::SDN::RouteMaps::route_map_properties(0),
+ },
+ code => sub {
+ my ($param) = @_;
+
+ my $route_map_id = extract_param($param, 'route-map-id');
+ my $order = extract_param($param, 'order');
+
+ my $route_map_entry =
+ PVE::Network::SDN::RouteMaps::config()->get($route_map_id, $order);
+
+ raise_param_exc({ 'route-map-id' => "${route_map_id}_${order} doesn't exist" })
+ if !$route_map_entry;
+
+ return $route_map_entry;
+ },
+});
+
+__PACKAGE__->register_method({
+ name => 'update_route_map_entry',
+ path => '',
+ method => 'PUT',
+ protected => 1,
+ permissions => {
+ check => ['perm', '/sdn/route-maps/{route-map-id}', ['SDN.Allocate']],
+ },
+ description => "Update Route Map Entry",
+ parameters => {
+ properties => {
+ digest => get_standard_option('pve-config-digest'),
+ 'lock-token' => get_standard_option('pve-sdn-lock-token'),
+ PVE::Network::SDN::RouteMaps::route_map_properties(1)->%*,
+ },
+ },
+ returns => {
+ type => "null",
+ },
+ code => sub {
+ my ($param) = @_;
+
+ my $lock_token = extract_param($param, 'lock-token');
+
+ PVE::Network::SDN::lock_sdn_config(
+ sub {
+ my $config = PVE::Network::SDN::RouteMaps::config();
+
+ my $digest = extract_param($param, 'digest');
+ PVE::Tools::assert_if_modified($config->digest(), $digest) if $digest;
+
+ my $route_map_id = extract_param($param, 'route-map-id');
+ my $order = extract_param($param, 'order');
+ my $delete = extract_param($param, 'delete');
+
+ $config->update($route_map_id, $order, $param, $delete);
+ PVE::Network::SDN::RouteMaps::write_config($config);
+ },
+ "updating route map entry failed",
+ $lock_token,
+ );
+
+ return;
+ },
+});
+
+__PACKAGE__->register_method({
+ name => 'delete_route_map_entry',
+ path => '',
+ method => 'DELETE',
+ protected => 1,
+ permissions => {
+ check => ['perm', '/sdn/route-maps/{route-map-id}', ['SDN.Allocate']],
+ },
+ description => "Delete Route Map Entry",
+ parameters => {
+ properties => {
+ 'route-map-id' => get_standard_option('pve-sdn-route-map-id'),
+ 'order' => get_standard_option('pve-sdn-route-map-order'),
+ 'lock-token' => get_standard_option('pve-sdn-lock-token'),
+ },
+ },
+ returns => {
+ type => "null",
+ },
+ code => sub {
+ my ($param) = @_;
+
+ my $lock_token = extract_param($param, 'lock-token');
+
+ PVE::Network::SDN::lock_sdn_config(
+ sub {
+ my $config = PVE::Network::SDN::RouteMaps::config();
+
+ my $digest = extract_param($param, 'digest');
+ PVE::Tools::assert_if_modified($config->digest(), $digest) if $digest;
+
+ my $route_map_id = extract_param($param, 'route-map-id');
+ my $order = extract_param($param, 'order');
+
+ $config->delete($route_map_id, $order);
+ PVE::Network::SDN::RouteMaps::write_config($config);
+ },
+ "deleting route map entry failed",
+ $lock_token,
+ );
+
+ return;
+ },
+});
+
+1;
--
2.47.3