]> git.proxmox.com Git - pve-network.git/blob - PVE/Network/SDN/Ipams.pm
add IPAMs plugins
[pve-network.git] / PVE / Network / SDN / Ipams.pm
1 package PVE::Network::SDN::Ipams;
2
3 use strict;
4 use warnings;
5
6 use Data::Dumper;
7 use JSON;
8
9 use PVE::Tools qw(extract_param dir_glob_regex run_command);
10 use PVE::Cluster qw(cfs_read_file cfs_write_file cfs_lock_file);
11 use PVE::Network;
12
13 use PVE::Network::SDN::Ipams::PVEPlugin;
14 use PVE::Network::SDN::Ipams::NetboxPlugin;
15 use PVE::Network::SDN::Ipams::PhpIpamPlugin;
16 use PVE::Network::SDN::Ipams::Plugin;
17
18 PVE::Network::SDN::Ipams::PVEPlugin->register();
19 PVE::Network::SDN::Ipams::NetboxPlugin->register();
20 PVE::Network::SDN::Ipams::PhpIpamPlugin->register();
21 PVE::Network::SDN::Ipams::Plugin->init();
22
23
24 sub sdn_ipams_config {
25 my ($cfg, $id, $noerr) = @_;
26
27 die "no sdn ipam ID specified\n" if !$id;
28
29 my $scfg = $cfg->{ids}->{$id};
30 die "sdn '$id' does not exist\n" if (!$noerr && !$scfg);
31
32 return $scfg;
33 }
34
35 sub config {
36 my $config = cfs_read_file("sdn/ipams.cfg");
37 return $config;
38 }
39
40 sub get_plugin_config {
41 my ($vnet) = @_;
42 my $ipamid = $vnet->{ipam};
43 my $ipam_cfg = PVE::Network::SDN::Ipams::config();
44 return $ipam_cfg->{ids}->{$ipamid};
45 }
46
47 sub write_config {
48 my ($cfg) = @_;
49
50 cfs_write_file("sdn/ipams.cfg", $cfg);
51 }
52
53 sub sdn_ipams_ids {
54 my ($cfg) = @_;
55
56 return keys %{$cfg->{ids}};
57 }
58
59 sub complete_sdn_vnet {
60 my ($cmdname, $pname, $cvalue) = @_;
61
62 my $cfg = PVE::Network::SDN::Ipams::config();
63
64 return $cmdname eq 'add' ? [] : [ PVE::Network::SDN::Vnets::sdn_ipams_ids($cfg) ];
65 }
66
67 1;
68