summaryrefslogtreecommitdiff
path: root/PVE/API2/Network/SDN/Status.pm
blob: 7f232140be36f5b203f06fe45bb787a473d9d522 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
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;