use PVE::SafeSyslog;
use PVE::Tools qw(extract_param);
use PVE::Cluster qw(cfs_read_file cfs_write_file);
+use PVE::Network::SDN;
use PVE::Network::SDN::Vnets;
use PVE::Network::SDN::Zones;
+use PVE::Network::SDN::Subnets;
+use PVE::Network::SDN::Dns;
use PVE::Network::SDN::Zones::Plugin;
use PVE::Network::SDN::Zones::VlanPlugin;
use PVE::Network::SDN::Zones::QinQPlugin;
use PVE::Network::SDN::Zones::VxlanPlugin;
use PVE::Network::SDN::Zones::EvpnPlugin;
use PVE::Network::SDN::Zones::FaucetPlugin;
+use PVE::Network::SDN::Zones::SimplePlugin;
use Storable qw(dclone);
use PVE::JSONSchema qw(get_standard_option);
use PVE::RPCEnvironment;
+use PVE::Exception qw(raise raise_param_exc);
use PVE::RESTHandler;
$scfg->{zone} = $id;
$scfg->{digest} = $cfg->{digest};
+ if ($scfg->{nodes}) {
+ $scfg->{nodes} = PVE::Network::SDN::Zones::Plugin->encode_value($scfg->{type}, 'nodes', $scfg->{nodes});
+ }
+
+ my $pending = $scfg->{pending};
+ if ($pending->{nodes}) {
+ $pending->{nodes} = PVE::Network::SDN::Zones::Plugin->encode_value($scfg->{type}, 'nodes', $pending->{nodes});
+ }
+
return $scfg;
};
method => 'GET',
description => "SDN zones index.",
permissions => {
- description => "Only list entries where you have 'SDN.Audit' or 'SDN.Allocate' permissions on '/cluster/sdn/zones/<zone>'",
+ description => "Only list entries where you have 'SDN.Audit' or 'SDN.Allocate' permissions on '/sdn/zones/<zone>'",
user => 'all',
},
parameters => {
enum => $sdn_zones_type_enum,
optional => 1,
},
+ 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 => { zone => { type => 'string'},
+ properties => { zone => { type => 'string'},
type => { type => 'string'},
+ mtu => { type => 'integer', optional => 1 },
+ dns => { type => 'string', optional => 1},
+ reversedns => { type => 'string', optional => 1},
+ dnszone => { type => 'string', optional => 1},
+ ipam => { type => 'string', optional => 1},
+ pending => { optional => 1},
+ state => { type => 'string', optional => 1},
+ nodes => { type => 'string', optional => 1},
},
},
links => [ { rel => 'child', href => "{zone}" } ],
my $rpcenv = PVE::RPCEnvironment::get();
my $authuser = $rpcenv->get_user();
-
- my $cfg = PVE::Network::SDN::Zones::config();
+ my $cfg = {};
+ if($param->{pending}) {
+ my $running_cfg = PVE::Network::SDN::config();
+ my $config = PVE::Network::SDN::Zones::config();
+ $cfg = PVE::Network::SDN::pending_config($running_cfg, $config, 'zones');
+ } elsif ($param->{running}) {
+ my $running_cfg = PVE::Network::SDN::config();
+ $cfg = $running_cfg->{zones};
+ } else {
+ $cfg = PVE::Network::SDN::Zones::config();
+ }
my @sids = PVE::Network::SDN::Zones::sdn_zones_ids($cfg);
my $res = [];
foreach my $id (@sids) {
-# my $privs = [ 'SDN.Audit', 'SDN.Allocate' ];
-# next if !$rpcenv->check_any($authuser, "/cluster/sdn/zones/$id", $privs, 1);
+ my $privs = [ 'SDN.Audit', 'SDN.Allocate' ];
+ next if !$rpcenv->check_any($authuser, "/sdn/zones/$id", $privs, 1);
my $scfg = &$api_sdn_zones_config($cfg, $id);
next if $param->{type} && $param->{type} ne $scfg->{type};
path => '{zone}',
method => 'GET',
description => "Read sdn zone configuration.",
-# permissions => {
-# check => ['perm', '/cluster/sdn/zones/{zone}', ['SDN.Allocate']],
-# },
+ permissions => {
+ check => ['perm', '/sdn/zones/{zone}', ['SDN.Allocate']],
+ },
parameters => {
additionalProperties => 0,
properties => {
zone => get_standard_option('pve-sdn-zone-id'),
+ 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::Zones::config();
+ my $cfg = {};
+ if($param->{pending}) {
+ my $running_cfg = PVE::Network::SDN::config();
+ my $config = PVE::Network::SDN::Zones::config();
+ $cfg = PVE::Network::SDN::pending_config($running_cfg, $config, 'zones');
+ } elsif ($param->{running}) {
+ my $running_cfg = PVE::Network::SDN::config();
+ $cfg = $running_cfg->{zones};
+ } else {
+ $cfg = PVE::Network::SDN::Zones::config();
+ }
return &$api_sdn_zones_config($cfg, $param->{zone});
}});
path => '',
method => 'POST',
description => "Create a new sdn zone object.",
-# permissions => {
-# check => ['perm', '/cluster/sdn/zones', ['SDN.Allocate']],
-# },
+ permissions => {
+ check => ['perm', '/sdn/zones', ['SDN.Allocate']],
+ },
parameters => PVE::Network::SDN::Zones::Plugin->createSchema(),
returns => { type => 'null' },
code => sub {
my $plugin = PVE::Network::SDN::Zones::Plugin->lookup($type);
my $opts = $plugin->check_config($id, $param, 1, 1);
- PVE::Network::SDN::Zones::lock_sdn_zones_config(
+ # create /etc/pve/sdn directory
+ PVE::Cluster::check_cfs_quorum();
+ mkdir("/etc/pve/sdn");
+
+ PVE::Network::SDN::lock_sdn_config(
sub {
- my $cfg = PVE::Network::SDN::Zones::config();
+ my $zone_cfg = PVE::Network::SDN::Zones::config();
+ my $controller_cfg = PVE::Network::SDN::Controllers::config();
+ my $dns_cfg = PVE::Network::SDN::Dns::config();
my $scfg = undef;
- if ($scfg = PVE::Network::SDN::Zones::sdn_zones_config($cfg, $id, 1)) {
+ if ($scfg = PVE::Network::SDN::Zones::sdn_zones_config($zone_cfg, $id, 1)) {
die "sdn zone object ID '$id' already defined\n";
}
+
+ my $dnsserver = $opts->{dns};
+ my $reversednsserver = $opts->{reversedns};
+ my $dnszone = $opts->{dnszone};
+ raise_param_exc({ dns => "$dnsserver don't exist"}) if $dnsserver && !$dns_cfg->{ids}->{$dnsserver};
+ raise_param_exc({ reversedns => "$reversednsserver don't exist"}) if $reversednsserver && !$dns_cfg->{ids}->{$reversednsserver};
+ raise_param_exc({ dnszone => "missing dns server"}) if $dnszone && !$dnsserver;
- $cfg->{ids}->{$id} = $opts;
- $plugin->on_update_hook($id, $cfg);
+ my $ipam = $opts->{ipam};
+ my $ipam_cfg = PVE::Network::SDN::Ipams::config();
+ raise_param_exc({ ipam => "$ipam not existing"}) if $ipam && !$ipam_cfg->{ids}->{$ipam};
- PVE::Network::SDN::Zones::write_config($cfg);
+ $zone_cfg->{ids}->{$id} = $opts;
+ $plugin->on_update_hook($id, $zone_cfg, $controller_cfg);
- }, "create sdn zone object failed");
+ PVE::Network::SDN::Zones::write_config($zone_cfg);
- return undef;
- }});
-
-__PACKAGE__->register_method ({
- name => 'apply_configuration',
- protected => 1,
- path => '',
- method => 'PUT',
- description => "Apply sdn zone changes.",
-# permissions => {
-# check => ['perm', '/cluster/sdn/zones', ['SDN.Allocate']],
-# },
- parameters => {
- additionalProperties => 0,
- },
- returns => { type => 'null' },
- code => sub {
- my ($param) = @_;
-
- die "no sdn zone changes to apply" if !-e "/etc/pve/sdn/zones.cfg.new";
- rename("/etc/pve/sdn/zones.cfg.new", "/etc/pve/sdn/zones.cfg")
- || die "applying sdn/zones.cfg changes failed - $!\n";
-
-
- return undef;
- }});
-
-__PACKAGE__->register_method ({
- name => 'revert_configuration',
- protected => 1,
- path => '',
- method => 'DELETE',
- description => "Revert sdn zone changes.",
-# permissions => {
-# check => ['perm', '/cluster/sdn/zones', ['SDN.Allocate']],
-# },
- parameters => {
- additionalProperties => 0,
- },
- returns => { type => 'null' },
- code => sub {
- my ($param) = @_;
-
- die "no sdn zones changes to revert" if !-e "/etc/pve/sdn/zones.cfg.new";
- unlink "/etc/pve/sdn/zones.cfg.new";
+ }, "create sdn zone object failed");
return undef;
}});
path => '{zone}',
method => 'PUT',
description => "Update sdn zone object configuration.",
-# permissions => {
-# check => ['perm', '/cluster/sdn/zones', ['SDN.Allocate']],
-# },
+ permissions => {
+ check => ['perm', '/sdn/zones', ['SDN.Allocate']],
+ },
parameters => PVE::Network::SDN::Zones::Plugin->updateSchema(),
returns => { type => 'null' },
code => sub {
my $id = extract_param($param, 'zone');
my $digest = extract_param($param, 'digest');
- PVE::Network::SDN::Zones::lock_sdn_zones_config(
+ PVE::Network::SDN::lock_sdn_config(
sub {
- my $cfg = PVE::Network::SDN::Zones::config();
+ my $zone_cfg = PVE::Network::SDN::Zones::config();
+ my $controller_cfg = PVE::Network::SDN::Controllers::config();
+ my $dns_cfg = PVE::Network::SDN::Dns::config();
- PVE::SectionConfig::assert_if_modified($cfg, $digest);
+ PVE::SectionConfig::assert_if_modified($zone_cfg, $digest);
- my $scfg = PVE::Network::SDN::Zones::sdn_zones_config($cfg, $id);
+ my $scfg = PVE::Network::SDN::Zones::sdn_zones_config($zone_cfg, $id);
my $plugin = PVE::Network::SDN::Zones::Plugin->lookup($scfg->{type});
my $opts = $plugin->check_config($id, $param, 0, 1);
+ if($opts->{ipam} ne $scfg->{ipam}) {
+
+ #don't allow ipam change if subnet are defined
+ my $subnets_cfg = PVE::Network::SDN::Subnets::config();
+ foreach my $subnetid (sort keys %{$subnets_cfg->{ids}}) {
+ my $subnet = PVE::Network::SDN::Subnets::sdn_subnets_config($subnets_cfg, $subnetid);
+ raise_param_exc({ ipam => "can't change ipam if subnet if already defined for this zone"}) if $subnet->{zone} eq $id;
+ }
+ }
+
foreach my $k (%$opts) {
$scfg->{$k} = $opts->{$k};
}
- $plugin->on_update_hook($id, $cfg);
+ my $dnsserver = $opts->{dns};
+ my $reversednsserver = $opts->{reversedns};
+ my $dnszone = $opts->{dnszone};
+ raise_param_exc({ dns => "$dnsserver don't exist"}) if $dnsserver && !$dns_cfg->{ids}->{$dnsserver};
+ raise_param_exc({ reversedns => "$reversednsserver don't exist"}) if $reversednsserver && !$dns_cfg->{ids}->{$reversednsserver};
+ raise_param_exc({ dnszone => "missing dns server"}) if $dnszone && !$dnsserver;
+
+ my $ipam = $opts->{ipam};
+ my $ipam_cfg = PVE::Network::SDN::Ipams::config();
+ raise_param_exc({ ipam => "$ipam not existing"}) if $ipam && !$ipam_cfg->{ids}->{$ipam};
- PVE::Network::SDN::Zones::write_config($cfg);
+ $plugin->on_update_hook($id, $zone_cfg, $controller_cfg);
+
+ PVE::Network::SDN::Zones::write_config($zone_cfg);
}, "update sdn zone object failed");
path => '{zone}',
method => 'DELETE',
description => "Delete sdn zone object configuration.",
-# permissions => {
-# check => ['perm', '/cluster/sdn/zones', ['SDN.Allocate']],
-# },
+ permissions => {
+ check => ['perm', '/sdn/zones', ['SDN.Allocate']],
+ },
parameters => {
additionalProperties => 0,
properties => {
my $id = extract_param($param, 'zone');
- PVE::Network::SDN::Zones::lock_sdn_zones_config(
+ PVE::Network::SDN::lock_sdn_config(
sub {
my $cfg = PVE::Network::SDN::Zones::config();