]> git.proxmox.com Git - pve-network.git/commitdiff
api2: add local endpoint for listing transportzones status
authorAlexandre Derumier <aderumier@odiso.com>
Thu, 29 Aug 2019 10:32:45 +0000 (12:32 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 3 Sep 2019 06:22:56 +0000 (08:22 +0200)
pvesh get /nodes/<node>/sdn/
┌─────────────────┬───────────┐
│ sdn             │ status    │
├─────────────────┼───────────┤
│ transportzone10 │ error     │
├─────────────────┼───────────┤
│ zone1           │ available │
├─────────────────┼───────────┤
│ zone4           │ available │
└─────────────────┴───────────┘

Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
PVE/API2/Network/SDN/Makefile
PVE/API2/Network/SDN/Status.pm [new file with mode: 0644]

index 85448a5816ef3344bebbe1c7789359a2de283974..9fa8cb0d2131cb2cbce9d3604f5ef0c96336417f 100644 (file)
@@ -1,4 +1,4 @@
-SOURCES=Content.pm
+SOURCES=Content.pm Status.pm
 
 
 PERL5DIR=${DESTDIR}/usr/share/perl5
diff --git a/PVE/API2/Network/SDN/Status.pm b/PVE/API2/Network/SDN/Status.pm
new file mode 100644 (file)
index 0000000..073b18a
--- /dev/null
@@ -0,0 +1,110 @@
+package PVE::API2::Network::SDN::Status;
+
+use strict;
+use warnings;
+
+use File::Path;
+use File::Basename;
+use PVE::Tools;
+use PVE::INotify;
+use PVE::Cluster;
+use PVE::API2::Network::SDN::Content;
+use PVE::RESTHandler;
+use PVE::RPCEnvironment;
+use PVE::JSONSchema qw(get_standard_option);
+use PVE::Exception qw(raise_param_exc);
+
+use base qw(PVE::RESTHandler);
+
+__PACKAGE__->register_method ({
+    subclass => "PVE::API2::Network::SDN::Content", 
+    path => '{sdn}/content',
+});
+
+__PACKAGE__->register_method ({
+    name => 'index', 
+    path => '',
+    method => 'GET',
+    description => "Get status for all transportzones.",
+    permissions => { 
+       description => "Only list entries where you have 'SDN.Audit'",
+       user => 'all',
+    },
+    protected => 1,
+    proxyto => 'node',
+    parameters => {
+       additionalProperties => 0,
+       properties => {
+           node => get_standard_option('pve-node')
+       },
+    },
+    returns => {
+       type => 'array',
+       items => {
+           type => "object",
+           properties => {
+               sdn => get_standard_option('pve-sdn-id'),
+               status => {
+                   description => "Status of transportzone",
+                   type => 'string',
+               },
+           },
+       },
+       links => [ { rel => 'child', href => "{sdn}" } ],
+    },
+    code => sub {
+       my ($param) = @_;
+
+       my $rpcenv = PVE::RPCEnvironment::get();
+       my $authuser = $rpcenv->get_user();
+
+       my $localnode = PVE::INotify::nodename();
+
+       my $res = [];
+
+        my ($transport_status, $vnet_status) = PVE::Network::SDN::status();
+
+        foreach my $id (keys %{$transport_status}) {
+           my $item->{sdn} = $id;
+           $item->{status} = $transport_status->{$id}->{'status'};
+           push @$res,$item;
+        }
+
+       return $res;
+    }});
+
+__PACKAGE__->register_method ({
+    name => 'diridx',
+    path => '{sdn}', 
+    method => 'GET',
+    description => "",
+#    permissions => { 
+#      check => ['perm', '/sdn/{sdn}', ['SDN.Audit'], any => 1],
+#    },
+    parameters => {
+       additionalProperties => 0,
+       properties => {
+           node => get_standard_option('pve-node'),
+           sdn => get_standard_option('pve-sdn-id'),
+       },
+    },
+    returns => {
+       type => 'array',
+       items => {
+           type => "object",
+           properties => {
+               subdir => { type => 'string' },
+           },
+       },
+       links => [ { rel => 'child', href => "{subdir}" } ],
+    },
+    code => sub {
+       my ($param) = @_;
+       my $res = [
+           { subdir => 'content' },
+           ];
+       
+       return $res;
+    }});
+
+1;