]>
git.proxmox.com Git - pve-network.git/blob - PVE/Network/Network.pm
1 package PVE
::Network
::Network
;
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
::Network
::Plugin
;
12 use PVE
::Network
::Network
::VnetPlugin
;
13 use PVE
::Network
::Network
::VlanPlugin
;
14 use PVE
::Network
::Network
::VxlanMulticastPlugin
;
16 PVE
::Network
::Network
::VnetPlugin-
>register();
17 PVE
::Network
::Network
::VlanPlugin-
>register();
18 PVE
::Network
::Network
::VxlanMulticastPlugin-
>register();
19 PVE
::Network
::Network
::Plugin-
>init();
23 my ($cfg, $networkid, $noerr) = @_;
25 die "no network ID specified\n" if !$networkid;
27 my $scfg = $cfg->{ids
}->{$networkid};
28 die "network '$networkid' does not exists\n" if (!$noerr && !$scfg);
34 my $config = cfs_read_file
("networks.cfg.new");
35 $config = cfs_read_file
("networks.cfg") if !keys %{$config->{ids
}};
42 cfs_write_file
("networks.cfg.new", $cfg);
45 sub lock_network_config
{
46 my ($code, $errmsg) = @_;
48 cfs_lock_file
("networks.cfg.new", undef, $code);
50 $errmsg ?
die "$errmsg: $err" : die $err;
57 return keys %{$cfg->{ids
}};
60 sub complete_network
{
61 my ($cmdname, $pname, $cvalue) = @_;
63 my $cfg = PVE
::Network
::Network
::config
();
65 return $cmdname eq 'add' ?
[] : [ PVE
::Network
::Network
::networks_ids
($cfg) ];
70 my $cmd = ['ifquery', '-a', '-c', '-o','json'];
73 my $reader = sub { $result .= shift };
76 run_command
($cmd, outfunc
=> $reader);
79 my $resultjson = decode_json
($result);
82 foreach my $interface (@$resultjson) {
83 my $name = $interface->{name
};
84 $interfaces->{$name} = {
85 status
=> $interface->{status
},
86 config
=> $interface->{config
},
87 config_status
=> $interface->{config_status
},