[pve-devel] [PATCH manager v3 2/6] Scan.pm: add mdev scan api call

Dominik Csapak d.csapak at proxmox.com
Thu Nov 22 11:35:42 CET 2018


this is for the gui to be able to select mediated devices
path ist /node/NODE/scan/pci/PCIID/mdev

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
changes from v2:
* new path for mdev  -> pci/ID/mdev
* fixed pci regex '.' -> '\.'

 PVE/API2/Scan.pm | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 84 insertions(+), 1 deletion(-)

diff --git a/PVE/API2/Scan.pm b/PVE/API2/Scan.pm
index 15c8b48a..f6b8ea18 100644
--- a/PVE/API2/Scan.pm
+++ b/PVE/API2/Scan.pm
@@ -1,5 +1,4 @@
 package PVE::API2::Scan;
-
 use strict;
 use warnings;
 
@@ -461,6 +460,7 @@ __PACKAGE__->register_method ({
 	},
     },
     returns => {
+	links => [ { rel => 'child', href => "{id}" } ],
 	type => 'array',
 	items => {
 	    type => "object",
@@ -546,4 +546,87 @@ __PACKAGE__->register_method ({
 	return PVE::SysFSTools::lspci($filter, $verbose);
     }});
 
+__PACKAGE__->register_method ({
+    name => 'pciindex',
+    path => 'pci/{pciid}',
+    method => 'GET',
+    description => "Index of available pci methods",
+    permissions => {
+	user => 'all',
+    },
+    parameters => {
+	additionalProperties => 0,
+	properties => {
+	    node => get_standard_option('pve-node'),
+	    pciid => {
+		type => 'string',
+		pattern => '(?:[0-9a-fA-F]{4}:)?[0-9a-fA-F]{2}:[0-9a-fA-F]{2}\.[0-9a-fA-F]',
+	    },
+	},
+    },
+    returns => {
+	type => 'array',
+	items => {
+	    type => "object",
+	    properties => { method => { type => 'string'} },
+	},
+	links => [ { rel => 'child', href => "{method}" } ],
+    },
+    code => sub {
+	my ($param) = @_;
+
+	my $res = [
+	    { method => 'mdev' },
+	    ];
+
+	return $res;
+    }});
+
+__PACKAGE__->register_method ({
+    name => 'mdevscan',
+    path => 'pci/{pciid}/mdev',
+    method => 'GET',
+    description => "List mediated device types for given PCI device.",
+    protected => 1,
+    proxyto => "node",
+    permissions => {
+	check => ['perm', '/', ['Sys.Modify']],
+    },
+    parameters => {
+	additionalProperties => 0,
+	properties => {
+	    node => get_standard_option('pve-node'),
+	    pciid => {
+		type => 'string',
+		pattern => '(?:[0-9a-fA-F]{4}:)?[0-9a-fA-F]{2}:[0-9a-fA-F]{2}\.[0-9a-fA-F]',
+		description => "The PCI ID to list the mdev types for."
+	    },
+	},
+    },
+    returns => {
+	type => 'array',
+	items => {
+	    type => "object",
+	    properties => {
+		type => {
+		    type => 'string',
+		    description => "The name of the mdev type.",
+		},
+		available => {
+		    type => 'integer',
+		    description => "The number of still available instances of"
+				  ." this type.",
+		},
+		description => {
+		    type => 'string',
+		},
+	    },
+	},
+    },
+    code => sub {
+	my ($param) = @_;
+
+	return PVE::SysFSTools::get_mdev_types($param->{pciid});
+    }});
+
 1;
-- 
2.11.0





More information about the pve-devel mailing list