]> git.proxmox.com Git - pve-network.git/blob - PVE/Network/SDN/Subnets.pm
add subnet plugin
[pve-network.git] / PVE / Network / SDN / Subnets.pm
1 package PVE::Network::SDN::Subnets;
2
3 use strict;
4 use warnings;
5
6 use PVE::Cluster qw(cfs_read_file cfs_write_file cfs_lock_file);
7
8 use PVE::Network::SDN::SubnetPlugin;
9 PVE::Network::SDN::SubnetPlugin->register();
10 PVE::Network::SDN::SubnetPlugin->init();
11
12 sub 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
23 sub config {
24 my $config = cfs_read_file("sdn/subnets.cfg");
25 }
26
27 sub write_config {
28 my ($cfg) = @_;
29
30 cfs_write_file("sdn/subnets.cfg", $cfg);
31 }
32
33 sub sdn_subnets_ids {
34 my ($cfg) = @_;
35
36 return keys %{$cfg->{ids}};
37 }
38
39 sub 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
47 sub 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
55 1;