]> git.proxmox.com Git - pve-network.git/commitdiff
add ifquery compare status
authorAlexandre Derumier <aderumier@odiso.com>
Mon, 3 Jun 2019 15:57:38 +0000 (17:57 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Tue, 4 Jun 2019 04:07:47 +0000 (06:07 +0200)
PVE/Network/Network.pm

index ee0b9733ce5c6ef7eb4e54bd7e66de7bb62c4f65..3a33ecd830822abf62bf0fbd2b9e83045d331a84 100644 (file)
@@ -3,6 +3,8 @@ package PVE::Network::Network;
 use strict;
 use warnings;
 use Data::Dumper;
+use JSON;
+use PVE::Tools qw(extract_param dir_glob_regex);
 use PVE::Cluster qw(cfs_read_file cfs_write_file cfs_lock_file);
 use PVE::Network::Network::Plugin;
 use PVE::Network::Network::VnetPlugin;
@@ -62,4 +64,30 @@ sub complete_network {
     return  $cmdname eq 'add' ? [] : [ PVE::Network::Network::networks_ids($cfg) ];
 }
 
+sub status {
+
+    my $cmd = ['ifquery', '-a', '-c', '-o','json'];
+    my $result;;
+
+    my $code = sub {
+        my $line = shift;
+       $result .= $line;
+    };
+
+    eval {
+       PVE::Tools::run_command($cmd, outfunc => $code, errfunc => $code);
+    };
+
+    my $resultjson = JSON::decode_json($result);
+    my $interfaces = {};
+
+    foreach my $interface (@$resultjson) {
+       $interfaces->{$interface->{'name'}}->{status} = $interface->{'status'};
+       $interfaces->{$interface->{'name'}}->{config} = $interface->{'config'};
+       $interfaces->{$interface->{'name'}}->{config_status} = $interface->{'config_status'};
+    }
+
+    return $interfaces;
+}
+
 1;