2020-10-05 17:08:47 +02:00
|
|
|
package PVE::Network::SDN::Ipams::Plugin;
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
use PVE::Tools qw(run_command);
|
|
|
|
use PVE::JSONSchema;
|
|
|
|
use PVE::Cluster;
|
|
|
|
use HTTP::Request;
|
|
|
|
use LWP::UserAgent;
|
|
|
|
use JSON;
|
|
|
|
|
|
|
|
use PVE::JSONSchema qw(get_standard_option);
|
|
|
|
use base qw(PVE::SectionConfig);
|
|
|
|
|
2024-11-18 14:40:37 +01:00
|
|
|
PVE::Cluster::cfs_register_file(
|
|
|
|
'sdn/ipams.cfg',
|
|
|
|
sub { __PACKAGE__->parse_config(@_); },
|
|
|
|
sub { __PACKAGE__->write_config(@_); },
|
|
|
|
);
|
2020-10-05 17:08:47 +02:00
|
|
|
|
|
|
|
PVE::JSONSchema::register_standard_option('pve-sdn-ipam-id', {
|
|
|
|
description => "The SDN ipam object identifier.",
|
|
|
|
type => 'string', format => 'pve-sdn-ipam-id',
|
|
|
|
});
|
|
|
|
|
|
|
|
PVE::JSONSchema::register_format('pve-sdn-ipam-id', \&parse_sdn_ipam_id);
|
|
|
|
sub parse_sdn_ipam_id {
|
|
|
|
my ($id, $noerr) = @_;
|
|
|
|
|
|
|
|
if ($id !~ m/^[a-z][a-z0-9]*[a-z0-9]$/i) {
|
|
|
|
return undef if $noerr;
|
|
|
|
die "ipam ID '$id' contains illegal characters\n";
|
|
|
|
}
|
|
|
|
return $id;
|
|
|
|
}
|
|
|
|
|
|
|
|
my $defaultData = {
|
|
|
|
|
|
|
|
propertyList => {
|
|
|
|
type => {
|
|
|
|
description => "Plugin type.",
|
|
|
|
type => 'string', format => 'pve-configid',
|
|
|
|
type => 'string',
|
|
|
|
},
|
2024-11-18 14:40:37 +01:00
|
|
|
ipam => get_standard_option('pve-sdn-ipam-id', {
|
|
|
|
completion => \&PVE::Network::SDN::Ipams::complete_sdn_ipam,
|
|
|
|
}),
|
2020-10-05 17:08:47 +02:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
sub private {
|
|
|
|
return $defaultData;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub parse_section_header {
|
|
|
|
my ($class, $line) = @_;
|
|
|
|
|
|
|
|
if ($line =~ m/^(\S+):\s*(\S+)\s*$/) {
|
|
|
|
my ($type, $id) = (lc($1), $2);
|
|
|
|
my $errmsg = undef; # set if you want to skip whole section
|
|
|
|
eval { PVE::JSONSchema::pve_verify_configid($type); };
|
|
|
|
$errmsg = $@ if $@;
|
|
|
|
my $config = {}; # to return additional attributes
|
|
|
|
return ($type, $id, $errmsg, $config);
|
|
|
|
}
|
|
|
|
return undef;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sub add_subnet {
|
2021-01-05 10:35:29 +01:00
|
|
|
my ($class, $plugin_config, $subnetid, $subnet, $noerr) = @_;
|
2021-01-05 10:35:24 +01:00
|
|
|
|
|
|
|
die "please implement inside plugin";
|
2020-10-05 17:08:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sub del_subnet {
|
2021-01-05 10:35:29 +01:00
|
|
|
my ($class, $plugin_config, $subnetid, $subnet, $noerr) = @_;
|
2021-01-05 10:35:24 +01:00
|
|
|
|
|
|
|
die "please implement inside plugin";
|
2020-10-05 17:08:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sub add_ip {
|
2023-11-17 12:39:43 +01:00
|
|
|
my ($class, $plugin_config, $subnetid, $subnet, $ip, $hostname, $mac, $vmid, $is_gateway, $noerr) = @_;
|
2020-10-05 17:08:47 +02:00
|
|
|
|
2021-01-05 10:35:24 +01:00
|
|
|
die "please implement inside plugin";
|
|
|
|
}
|
|
|
|
|
|
|
|
sub update_ip {
|
2023-11-17 12:39:43 +01:00
|
|
|
my ($class, $plugin_config, $subnetid, $subnet, $ip, $hostname, $mac, $vmid, $is_gateway, $noerr) = @_;
|
2021-01-05 10:35:24 +01:00
|
|
|
# only update ip attributes (mac,hostname,..). Don't change the ip addresses itself, as some ipam
|
|
|
|
# don't allow ip address change without del/add
|
|
|
|
|
|
|
|
die "please implement inside plugin";
|
2020-10-05 17:08:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sub add_next_freeip {
|
2023-11-17 12:39:43 +01:00
|
|
|
my ($class, $plugin_config, $subnetid, $subnet, $hostname, $mac, $vmid, $noerr) = @_;
|
|
|
|
|
|
|
|
die "please implement inside plugin";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sub add_range_next_freeip {
|
|
|
|
my ($class, $plugin_config, $subnet, $range, $data, $noerr) = @_;
|
2021-01-05 10:35:24 +01:00
|
|
|
|
|
|
|
die "please implement inside plugin";
|
2020-10-05 17:08:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sub del_ip {
|
2021-01-05 10:35:29 +01:00
|
|
|
my ($class, $plugin_config, $subnetid, $subnet, $ip, $noerr) = @_;
|
2021-01-05 10:35:24 +01:00
|
|
|
|
|
|
|
die "please implement inside plugin";
|
2020-10-05 17:08:47 +02:00
|
|
|
}
|
|
|
|
|
2023-11-17 12:39:43 +01:00
|
|
|
sub get_ips_from_mac {
|
|
|
|
my ($class, $plugin_config, $mac, $zone) = @_;
|
|
|
|
|
|
|
|
die "please implement inside plugin";
|
|
|
|
}
|
|
|
|
|
2020-10-05 17:08:47 +02:00
|
|
|
sub on_update_hook {
|
|
|
|
my ($class, $plugin_config) = @_;
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|