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