]> git.proxmox.com Git - pve-network.git/blob - PVE/Network/SDN/Ipams.pm
zones: plugin : readd encode/decode value
[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 #add default internal pve
38 $config->{ids}->{pve}->{type} = 'pve';
39 return $config;
40 }
41
42 sub get_plugin_config {
43 my ($vnet) = @_;
44 my $ipamid = $vnet->{ipam};
45 my $ipam_cfg = PVE::Network::SDN::Ipams::config();
46 return $ipam_cfg->{ids}->{$ipamid};
47 }
48
49 sub write_config {
50 my ($cfg) = @_;
51
52 cfs_write_file("sdn/ipams.cfg", $cfg);
53 }
54
55 sub sdn_ipams_ids {
56 my ($cfg) = @_;
57
58 return keys %{$cfg->{ids}};
59 }
60
61 sub complete_sdn_vnet {
62 my ($cmdname, $pname, $cvalue) = @_;
63
64 my $cfg = PVE::Network::SDN::Ipams::config();
65
66 return $cmdname eq 'add' ? [] : [ PVE::Network::SDN::Vnets::sdn_ipams_ids($cfg) ];
67 }
68
69 1;
70