[pve-devel] [PATCH v2 pve-network 03/13] api2: add local endpoint for listing content of a transportzone
Alexandre Derumier
aderumier at odiso.com
Thu Aug 29 12:32:44 CEST 2019
pveset get /nodes/<node>/sdn/<transportzone>/content
┌─────────┬────────┐
│ vnet │ status │
├─────────┼────────┤
│ vnet100 │ error │
├─────────┼────────┤
│ vnet101 │ error │
└─────────┴────────┘
Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
PVE/API2/Network/Makefile | 2 +
PVE/API2/Network/SDN/Content.pm | 80 +++++++++++++++++++++++++++++++++
PVE/API2/Network/SDN/Makefile | 8 ++++
3 files changed, 90 insertions(+)
create mode 100644 PVE/API2/Network/SDN/Content.pm
create mode 100644 PVE/API2/Network/SDN/Makefile
diff --git a/PVE/API2/Network/Makefile b/PVE/API2/Network/Makefile
index 4b2fda3..80a3b25 100644
--- a/PVE/API2/Network/Makefile
+++ b/PVE/API2/Network/Makefile
@@ -6,3 +6,5 @@ PERL5DIR=${DESTDIR}/usr/share/perl5
.PHONY: install
install:
for i in ${SOURCES}; do install -D -m 0644 $$i ${PERL5DIR}/PVE/API2/Network/$$i; done
+ make -C SDN install
+
diff --git a/PVE/API2/Network/SDN/Content.pm b/PVE/API2/Network/SDN/Content.pm
new file mode 100644
index 0000000..f6b59ec
--- /dev/null
+++ b/PVE/API2/Network/SDN/Content.pm
@@ -0,0 +1,80 @@
+package PVE::API2::Network::SDN::Content;
+
+use strict;
+use warnings;
+use Data::Dumper;
+
+use PVE::SafeSyslog;
+use PVE::Cluster;
+use PVE::Storage;
+use PVE::INotify;
+use PVE::Exception qw(raise_param_exc);
+use PVE::RPCEnvironment;
+use PVE::RESTHandler;
+use PVE::JSONSchema qw(get_standard_option);
+use PVE::Network::SDN;
+
+use base qw(PVE::RESTHandler);
+
+__PACKAGE__->register_method ({
+ name => 'index',
+ path => '',
+ method => 'GET',
+ description => "List transportzone content.",
+# permissions => {
+# check => ['perm', '/sdn/{sdn}', ['SDN.Audit'], any => 1],
+# },
+ protected => 1,
+ proxyto => 'node',
+ parameters => {
+ additionalProperties => 0,
+ properties => {
+ node => get_standard_option('pve-node'),
+ sdn => get_standard_option('pve-sdn-id', {
+ completion => \&PVE::Network::SDN::complete_sdn,
+ }),
+ },
+ },
+ returns => {
+ type => 'array',
+ items => {
+ type => "object",
+ properties => {
+ vnet => {
+ description => "Vnet identifier.",
+ type => 'string',
+ },
+ status => {
+ description => "Status.",
+ type => 'string',
+ optional => 1,
+ },
+ },
+ },
+ links => [ { rel => 'child', href => "{vnet}" } ],
+ },
+ code => sub {
+ my ($param) = @_;
+
+ my $rpcenv = PVE::RPCEnvironment::get();
+
+ my $authuser = $rpcenv->get_user();
+
+ my $transportid = $param->{sdn};
+
+ my $res = [];
+
+ my ($transport_status, $vnet_status) = PVE::Network::SDN::status();
+
+ foreach my $id (keys %{$vnet_status}) {
+ if ($vnet_status->{$id}->{transportzone} eq $transportid) {
+ my $item->{vnet} = $id;
+ $item->{status} = $vnet_status->{$id}->{'status'};
+ push @$res,$item;
+ }
+ }
+
+ return $res;
+ }});
+
+1;
diff --git a/PVE/API2/Network/SDN/Makefile b/PVE/API2/Network/SDN/Makefile
new file mode 100644
index 0000000..85448a5
--- /dev/null
+++ b/PVE/API2/Network/SDN/Makefile
@@ -0,0 +1,8 @@
+SOURCES=Content.pm
+
+
+PERL5DIR=${DESTDIR}/usr/share/perl5
+
+.PHONY: install
+install:
+ for i in ${SOURCES}; do install -D -m 0644 $$i ${PERL5DIR}/PVE/API2/Network/SDN/$$i; done
--
2.20.1
More information about the pve-devel
mailing list