]> git.proxmox.com Git - pve-network.git/blame - PVE/Network/SDN/Subnets.pm
add subnet plugin
[pve-network.git] / PVE / Network / SDN / Subnets.pm
CommitLineData
c33dd818
AD
1package PVE::Network::SDN::Subnets;
2
3use strict;
4use warnings;
5
6use PVE::Cluster qw(cfs_read_file cfs_write_file cfs_lock_file);
7
8use PVE::Network::SDN::SubnetPlugin;
9PVE::Network::SDN::SubnetPlugin->register();
10PVE::Network::SDN::SubnetPlugin->init();
11
12sub sdn_subnets_config {
13 my ($cfg, $id, $noerr) = @_;
14
15 die "no sdn subnet ID specified\n" if !$id;
16
17 my $scfg = $cfg->{ids}->{$id};
18 die "sdn subnet '$id' does not exist\n" if (!$noerr && !$scfg);
19
20 return $scfg;
21}
22
23sub config {
24 my $config = cfs_read_file("sdn/subnets.cfg");
25}
26
27sub write_config {
28 my ($cfg) = @_;
29
30 cfs_write_file("sdn/subnets.cfg", $cfg);
31}
32
33sub sdn_subnets_ids {
34 my ($cfg) = @_;
35
36 return keys %{$cfg->{ids}};
37}
38
39sub complete_sdn_subnet {
40 my ($cmdname, $pname, $cvalue) = @_;
41
42 my $cfg = PVE::Network::SDN::Subnets::config();
43
44 return $cmdname eq 'add' ? [] : [ PVE::Network::SDN::Subnets::sdn_subnets_ids($cfg) ];
45}
46
47sub get_subnet {
48 my ($subnetid) = @_;
49
50 my $cfg = PVE::Network::SDN::Subnets::config();
51 my $subnet = PVE::Network::SDN::Subnets::sdn_subnets_config($cfg, $subnetid, 1);
52 return $subnet;
53}
54
551;