* [pve-devel] unify storage scan API, complete separating local hardware list
@ 2020-12-02 10:51 Thomas Lamprecht
2020-12-02 10:51 ` [pve-devel] applied: [PATCH storage 1/6] factor out scan CLI definition to real API module Thomas Lamprecht
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: Thomas Lamprecht @ 2020-12-02 10:51 UTC (permalink / raw)
To: pve-devel
Finishes the thoughts we had two years ago[0], add usb endpoint in the existing
hardware/ api directory, along side PCI, and use it. This then allows
sunsetting the one in the storage scan api (which never should have been added
there in the first place), and unifying of the pvesm CLI and API definitions,
which had already some small minor fixes applied only in one side of the copy.
IMO, this issues stem mostly from a misunderstanding what pve-storage should be,
i.e., an access API for existing storages, not a management one for creating or
changing the underlying storages or devices.
[0]: https://lists.proxmox.com/pipermail/pve-devel/2018-November/034694.html
^ permalink raw reply [flat|nested] 7+ messages in thread
* [pve-devel] applied: [PATCH storage 1/6] factor out scan CLI definition to real API module
2020-12-02 10:51 [pve-devel] unify storage scan API, complete separating local hardware list Thomas Lamprecht
@ 2020-12-02 10:51 ` Thomas Lamprecht
2020-12-02 10:51 ` [pve-devel] applied: [PATCH storage 2/6] api: scan cifs: port over NT_STATUS filter from pve-manager Thomas Lamprecht
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Thomas Lamprecht @ 2020-12-02 10:51 UTC (permalink / raw)
To: pve-devel
we have a 1:1 copy of that code in pve-manager's PVE::API2::Scan,
which we can avoid by using a common module form pvesm CLI and the
API.
This is the first basic step of dropping the code duplication in
pve-manager.
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
---
some very minor differences between both, CLI and pve-manager one, got already
resolved here.
PVE/API2/Storage/Makefile | 2 +-
PVE/API2/Storage/Scan.pm | 341 +++++++++++++++++++++++++++++++++++++
PVE/CLI/pvesm.pm | 342 +-------------------------------------
3 files changed, 350 insertions(+), 335 deletions(-)
create mode 100644 PVE/API2/Storage/Scan.pm
diff --git a/PVE/API2/Storage/Makefile b/PVE/API2/Storage/Makefile
index 3f667e8..690b437 100644
--- a/PVE/API2/Storage/Makefile
+++ b/PVE/API2/Storage/Makefile
@@ -1,5 +1,5 @@
-SOURCES= Content.pm Status.pm Config.pm PruneBackups.pm
+SOURCES= Content.pm Status.pm Config.pm PruneBackups.pm Scan.pm
.PHONY: install
install:
diff --git a/PVE/API2/Storage/Scan.pm b/PVE/API2/Storage/Scan.pm
new file mode 100644
index 0000000..0e6fd9a
--- /dev/null
+++ b/PVE/API2/Storage/Scan.pm
@@ -0,0 +1,341 @@
+package PVE::API2::Storage::Scan;
+
+use strict;
+use warnings;
+
+# NOTE: This API endpoints are mounted by pve-manager's API2::Node module and pvesm CLI
+
+use PVE::JSONSchema qw(get_standard_option);
+use PVE::RESTHandler;
+use PVE::SafeSyslog;
+use PVE::Storage::LVMPlugin;
+use PVE::Storage;
+use PVE::SysFSTools;
+
+use base qw(PVE::RESTHandler);
+
+__PACKAGE__->register_method({
+ name => 'nfsscan',
+ path => 'nfs',
+ method => 'GET',
+ description => "Scan remote NFS server.",
+ protected => 1,
+ proxyto => "node",
+ permissions => {
+ check => ['perm', '/storage', ['Datastore.Allocate']],
+ },
+ parameters => {
+ additionalProperties => 0,
+ properties => {
+ node => get_standard_option('pve-node'),
+ server => {
+ description => "The server address (name or IP).",
+ type => 'string', format => 'pve-storage-server',
+ },
+ },
+ },
+ returns => {
+ type => 'array',
+ items => {
+ type => "object",
+ properties => {
+ path => {
+ description => "The exported path.",
+ type => 'string',
+ },
+ options => {
+ description => "NFS export options.",
+ type => 'string',
+ },
+ },
+ },
+ },
+ code => sub {
+ my ($param) = @_;
+
+ my $server = $param->{server};
+ my $res = PVE::Storage::scan_nfs($server);
+
+ my $data = [];
+ foreach my $k (sort keys %$res) {
+ push @$data, { path => $k, options => $res->{$k} };
+ }
+ return $data;
+ }});
+
+__PACKAGE__->register_method({
+ name => 'cifsscan',
+ path => 'cifs',
+ method => 'GET',
+ description => "Scan remote CIFS server.",
+ protected => 1,
+ proxyto => "node",
+ permissions => {
+ check => ['perm', '/storage', ['Datastore.Allocate']],
+ },
+ parameters => {
+ additionalProperties => 0,
+ properties => {
+ node => get_standard_option('pve-node'),
+ server => {
+ description => "The server address (name or IP).",
+ type => 'string', format => 'pve-storage-server',
+ },
+ username => {
+ description => "User name.",
+ type => 'string',
+ optional => 1,
+ },
+ password => {
+ description => "User password.",
+ type => 'string',
+ optional => 1,
+ },
+ domain => {
+ description => "SMB domain (Workgroup).",
+ type => 'string',
+ optional => 1,
+ },
+ },
+ },
+ returns => {
+ type => 'array',
+ items => {
+ type => "object",
+ properties => {
+ share => {
+ description => "The cifs share name.",
+ type => 'string',
+ },
+ description => {
+ description => "Descriptive text from server.",
+ type => 'string',
+ },
+ },
+ },
+ },
+ code => sub {
+ my ($param) = @_;
+
+ my $server = $param->{server};
+
+ my $username = $param->{username};
+ my $password = $param->{password};
+ my $domain = $param->{domain};
+
+ my $res = PVE::Storage::scan_cifs($server, $username, $password, $domain);
+
+ my $data = [];
+ foreach my $k (sort keys %$res) {
+ push @$data, { share => $k, description => $res->{$k} };
+ }
+
+ return $data;
+ }});
+
+# Note: GlusterFS currently does not have an equivalent of showmount.
+# As workaround, we simply use nfs showmount.
+# see http://www.gluster.org/category/volumes/
+__PACKAGE__->register_method({
+ name => 'glusterfsscan',
+ path => 'glusterfs',
+ method => 'GET',
+ description => "Scan remote GlusterFS server.",
+ protected => 1,
+ proxyto => "node",
+ permissions => {
+ check => ['perm', '/storage', ['Datastore.Allocate']],
+ },
+ parameters => {
+ additionalProperties => 0,
+ properties => {
+ node => get_standard_option('pve-node'),
+ server => {
+ description => "The server address (name or IP).",
+ type => 'string', format => 'pve-storage-server',
+ },
+ },
+ },
+ returns => {
+ type => 'array',
+ items => {
+ type => "object",
+ properties => {
+ volname => {
+ description => "The volume name.",
+ type => 'string',
+ },
+ },
+ },
+ },
+ code => sub {
+ my ($param) = @_;
+
+ my $server = $param->{server};
+ my $res = PVE::Storage::scan_nfs($server);
+
+ my $data = [];
+ foreach my $path (sort keys %$res) {
+ if ($path =~ m!^/([^\s/]+)$!) {
+ push @$data, { volname => $1 };
+ }
+ }
+ return $data;
+ }});
+
+__PACKAGE__->register_method({
+ name => 'iscsiscan',
+ path => 'iscsi',
+ method => 'GET',
+ description => "Scan remote iSCSI server.",
+ protected => 1,
+ proxyto => "node",
+ permissions => {
+ check => ['perm', '/storage', ['Datastore.Allocate']],
+ },
+ parameters => {
+ additionalProperties => 0,
+ properties => {
+ node => get_standard_option('pve-node'),
+ portal => {
+ description => "The iSCSI portal (IP or DNS name with optional port).",
+ type => 'string', format => 'pve-storage-portal-dns',
+ },
+ },
+ },
+ returns => {
+ type => 'array',
+ items => {
+ type => "object",
+ properties => {
+ target => {
+ description => "The iSCSI target name.",
+ type => 'string',
+ },
+ portal => {
+ description => "The iSCSI portal name.",
+ type => 'string',
+ },
+ },
+ },
+ },
+ code => sub {
+ my ($param) = @_;
+
+ my $res = PVE::Storage::scan_iscsi($param->{portal});
+
+ my $data = [];
+ foreach my $k (sort keys %$res) {
+ push @$data, { target => $k, portal => join(',', @{$res->{$k}}) };
+ }
+
+ return $data;
+ }});
+
+__PACKAGE__->register_method({
+ name => 'lvmscan',
+ path => 'lvm',
+ method => 'GET',
+ description => "List local LVM volume groups.",
+ protected => 1,
+ proxyto => "node",
+ permissions => {
+ check => ['perm', '/storage', ['Datastore.Allocate']],
+ },
+ parameters => {
+ additionalProperties => 0,
+ properties => {
+ node => get_standard_option('pve-node'),
+ },
+ },
+ returns => {
+ type => 'array',
+ items => {
+ type => "object",
+ properties => {
+ vg => {
+ description => "The LVM logical volume group name.",
+ type => 'string',
+ },
+ },
+ },
+ },
+ code => sub {
+ my ($param) = @_;
+
+ my $res = PVE::Storage::LVMPlugin::lvm_vgs();
+ return PVE::RESTHandler::hash_to_array($res, 'vg');
+ }});
+
+__PACKAGE__->register_method({
+ name => 'lvmthinscan',
+ path => 'lvmthin',
+ method => 'GET',
+ description => "List local LVM Thin Pools.",
+ protected => 1,
+ proxyto => "node",
+ permissions => {
+ check => ['perm', '/storage', ['Datastore.Allocate']],
+ },
+ parameters => {
+ additionalProperties => 0,
+ properties => {
+ node => get_standard_option('pve-node'),
+ vg => {
+ type => 'string',
+ pattern => '[a-zA-Z0-9\.\+\_][a-zA-Z0-9\.\+\_\-]+', # see lvm(8) manpage
+ maxLength => 100,
+ },
+ },
+ },
+ returns => {
+ type => 'array',
+ items => {
+ type => "object",
+ properties => {
+ lv => {
+ description => "The LVM Thin Pool name (LVM logical volume).",
+ type => 'string',
+ },
+ },
+ },
+ },
+ code => sub {
+ my ($param) = @_;
+
+ return PVE::Storage::LvmThinPlugin::list_thinpools($param->{vg});
+ }});
+
+__PACKAGE__->register_method({
+ name => 'zfsscan',
+ path => 'zfs',
+ method => 'GET',
+ description => "Scan zfs pool list on local node.",
+ protected => 1,
+ proxyto => "node",
+ permissions => {
+ check => ['perm', '/storage', ['Datastore.Allocate']],
+ },
+ parameters => {
+ additionalProperties => 0,
+ properties => {
+ node => get_standard_option('pve-node'),
+ },
+ },
+ returns => {
+ type => 'array',
+ items => {
+ type => "object",
+ properties => {
+ pool => {
+ description => "ZFS pool name.",
+ type => 'string',
+ },
+ },
+ },
+ },
+ code => sub {
+ my ($param) = @_;
+
+ return PVE::Storage::scan_zfs();
+ }});
diff --git a/PVE/CLI/pvesm.pm b/PVE/CLI/pvesm.pm
index a2246cc..bc48617 100755
--- a/PVE/CLI/pvesm.pm
+++ b/PVE/CLI/pvesm.pm
@@ -16,6 +16,7 @@ use PVE::Tools qw(extract_param);
use PVE::API2::Storage::Config;
use PVE::API2::Storage::Content;
use PVE::API2::Storage::PruneBackups;
+use PVE::API2::Storage::Scan;
use PVE::API2::Storage::Status;
use PVE::JSONSchema qw(get_standard_option);
use PVE::PTY;
@@ -406,333 +407,6 @@ __PACKAGE__->register_method ({
}
});
-__PACKAGE__->register_method ({
- name => 'nfsscan',
- path => 'nfs',
- method => 'GET',
- description => "Scan remote NFS server.",
- protected => 1,
- proxyto => "node",
- permissions => {
- check => ['perm', '/storage', ['Datastore.Allocate']],
- },
- parameters => {
- additionalProperties => 0,
- properties => {
- node => get_standard_option('pve-node'),
- server => {
- description => "The server address (name or IP).",
- type => 'string', format => 'pve-storage-server',
- },
- },
- },
- returns => {
- type => 'array',
- items => {
- type => "object",
- properties => {
- path => {
- description => "The exported path.",
- type => 'string',
- },
- options => {
- description => "NFS export options.",
- type => 'string',
- },
- },
- },
- },
- code => sub {
- my ($param) = @_;
-
- my $server = $param->{server};
- my $res = PVE::Storage::scan_nfs($server);
-
- my $data = [];
- foreach my $k (sort keys %$res) {
- push @$data, { path => $k, options => $res->{$k} };
- }
- return $data;
- }});
-
-__PACKAGE__->register_method ({
- name => 'cifsscan',
- path => 'cifs',
- method => 'GET',
- description => "Scan remote CIFS server.",
- protected => 1,
- proxyto => "node",
- permissions => {
- check => ['perm', '/storage', ['Datastore.Allocate']],
- },
- parameters => {
- additionalProperties => 0,
- properties => {
- node => get_standard_option('pve-node'),
- server => {
- description => "The server address (name or IP).",
- type => 'string', format => 'pve-storage-server',
- },
- username => {
- description => "User name.",
- type => 'string',
- optional => 1,
- },
- password => {
- description => "User password.",
- type => 'string',
- optional => 1,
- },
- domain => {
- description => "SMB domain (Workgroup).",
- type => 'string',
- optional => 1,
- },
- },
- },
- returns => {
- type => 'array',
- items => {
- type => "object",
- properties => {
- share => {
- description => "The cifs share name.",
- type => 'string',
- },
- description => {
- description => "Descriptive text from server.",
- type => 'string',
- },
- },
- },
- },
- code => sub {
- my ($param) = @_;
-
- my $server = $param->{server};
-
- my $username = $param->{username};
- my $password = $param->{password};
- my $domain = $param->{domain};
-
- my $res = PVE::Storage::scan_cifs($server, $username, $password, $domain);
-
- my $data = [];
- foreach my $k (sort keys %$res) {
- push @$data, { share => $k, description => $res->{$k} };
- }
-
- return $data;
- }});
-
-# Note: GlusterFS currently does not have an equivalent of showmount.
-# As workaround, we simply use nfs showmount.
-# see http://www.gluster.org/category/volumes/
-
-__PACKAGE__->register_method ({
- name => 'glusterfsscan',
- path => 'glusterfs',
- method => 'GET',
- description => "Scan remote GlusterFS server.",
- protected => 1,
- proxyto => "node",
- permissions => {
- check => ['perm', '/storage', ['Datastore.Allocate']],
- },
- parameters => {
- additionalProperties => 0,
- properties => {
- node => get_standard_option('pve-node'),
- server => {
- description => "The server address (name or IP).",
- type => 'string', format => 'pve-storage-server',
- },
- },
- },
- returns => {
- type => 'array',
- items => {
- type => "object",
- properties => {
- volname => {
- description => "The volume name.",
- type => 'string',
- },
- },
- },
- },
- code => sub {
- my ($param) = @_;
-
- my $server = $param->{server};
- my $res = PVE::Storage::scan_nfs($server);
-
- my $data = [];
- foreach my $path (sort keys %$res) {
- if ($path =~ m!^/([^\s/]+)$!) {
- push @$data, { volname => $1 };
- }
- }
- return $data;
- }});
-
-__PACKAGE__->register_method ({
- name => 'iscsiscan',
- path => 'iscsi',
- method => 'GET',
- description => "Scan remote iSCSI server.",
- protected => 1,
- proxyto => "node",
- permissions => {
- check => ['perm', '/storage', ['Datastore.Allocate']],
- },
- parameters => {
- additionalProperties => 0,
- properties => {
- node => get_standard_option('pve-node'),
- portal => {
- description => "The iSCSI portal (IP or DNS name with optional port).",
- type => 'string', format => 'pve-storage-portal-dns',
- },
- },
- },
- returns => {
- type => 'array',
- items => {
- type => "object",
- properties => {
- target => {
- description => "The iSCSI target name.",
- type => 'string',
- },
- portal => {
- description => "The iSCSI portal name.",
- type => 'string',
- },
- },
- },
- },
- code => sub {
- my ($param) = @_;
-
- my $res = PVE::Storage::scan_iscsi($param->{portal});
-
- my $data = [];
- foreach my $k (sort keys %$res) {
- push @$data, { target => $k, portal => join(',', @{$res->{$k}}) };
- }
-
- return $data;
- }});
-
-__PACKAGE__->register_method ({
- name => 'lvmscan',
- path => 'lvm',
- method => 'GET',
- description => "List local LVM volume groups.",
- protected => 1,
- proxyto => "node",
- permissions => {
- check => ['perm', '/storage', ['Datastore.Allocate']],
- },
- parameters => {
- additionalProperties => 0,
- properties => {
- node => get_standard_option('pve-node'),
- },
- },
- returns => {
- type => 'array',
- items => {
- type => "object",
- properties => {
- vg => {
- description => "The LVM logical volume group name.",
- type => 'string',
- },
- },
- },
- },
- code => sub {
- my ($param) = @_;
-
- my $res = PVE::Storage::LVMPlugin::lvm_vgs();
- return PVE::RESTHandler::hash_to_array($res, 'vg');
- }});
-
-__PACKAGE__->register_method ({
- name => 'lvmthinscan',
- path => 'lvmthin',
- method => 'GET',
- description => "List local LVM Thin Pools.",
- protected => 1,
- proxyto => "node",
- permissions => {
- check => ['perm', '/storage', ['Datastore.Allocate']],
- },
- parameters => {
- additionalProperties => 0,
- properties => {
- node => get_standard_option('pve-node'),
- vg => {
- type => 'string',
- pattern => '[a-zA-Z0-9\.\+\_][a-zA-Z0-9\.\+\_\-]+', # see lvm(8) manpage
- maxLength => 100,
- },
- },
- },
- returns => {
- type => 'array',
- items => {
- type => "object",
- properties => {
- lv => {
- description => "The LVM Thin Pool name (LVM logical volume).",
- type => 'string',
- },
- },
- },
- },
- code => sub {
- my ($param) = @_;
-
- return PVE::Storage::LvmThinPlugin::list_thinpools($param->{vg});
- }});
-
-__PACKAGE__->register_method ({
- name => 'zfsscan',
- path => 'zfs',
- method => 'GET',
- description => "Scan zfs pool list on local node.",
- protected => 1,
- proxyto => "node",
- permissions => {
- check => ['perm', '/storage', ['Datastore.Allocate']],
- },
- parameters => {
- additionalProperties => 0,
- properties => {
- node => get_standard_option('pve-node'),
- },
- },
- returns => {
- type => 'array',
- items => {
- type => "object",
- properties => {
- pool => {
- description => "ZFS pool name.",
- type => 'string',
- },
- },
- },
- },
- code => sub {
- my ($param) = @_;
-
- return PVE::Storage::scan_zfs();
- }});
-
__PACKAGE__->register_method ({
name => 'prunebackups',
path => 'prunebackups',
@@ -847,7 +521,7 @@ our $cmddef = {
free => [ "PVE::API2::Storage::Content", 'delete', ['volume'],
{ node => $nodename } ],
scan => {
- nfs => [ __PACKAGE__, 'nfsscan', ['server'], { node => $nodename }, sub {
+ nfs => [ "PVE::API2::Storage::Scan", 'nfsscan', ['server'], { node => $nodename }, sub {
my $res = shift;
my $maxlen = 0;
@@ -859,7 +533,7 @@ our $cmddef = {
printf "%-${maxlen}s %s\n", $rec->{path}, $rec->{options};
}
}],
- cifs => [ __PACKAGE__, 'cifsscan', ['server'], { node => $nodename }, sub {
+ cifs => [ "PVE::API2::Storage::Scan", 'cifsscan', ['server'], { node => $nodename }, sub {
my $res = shift;
my $maxlen = 0;
@@ -871,14 +545,14 @@ our $cmddef = {
printf "%-${maxlen}s %s\n", $rec->{share}, $rec->{description};
}
}],
- glusterfs => [ __PACKAGE__, 'glusterfsscan', ['server'], { node => $nodename }, sub {
+ glusterfs => [ "PVE::API2::Storage::Scan", 'glusterfsscan', ['server'], { node => $nodename }, sub {
my $res = shift;
foreach my $rec (@$res) {
printf "%s\n", $rec->{volname};
}
}],
- iscsi => [ __PACKAGE__, 'iscsiscan', ['portal'], { node => $nodename }, sub {
+ iscsi => [ "PVE::API2::Storage::Scan", 'iscsiscan', ['portal'], { node => $nodename }, sub {
my $res = shift;
my $maxlen = 0;
@@ -890,19 +564,19 @@ our $cmddef = {
printf "%-${maxlen}s %s\n", $rec->{target}, $rec->{portal};
}
}],
- lvm => [ __PACKAGE__, 'lvmscan', [], { node => $nodename }, sub {
+ lvm => [ "PVE::API2::Storage::Scan", 'lvmscan', [], { node => $nodename }, sub {
my $res = shift;
foreach my $rec (@$res) {
printf "$rec->{vg}\n";
}
}],
- lvmthin => [ __PACKAGE__, 'lvmthinscan', ['vg'], { node => $nodename }, sub {
+ lvmthin => [ "PVE::API2::Storage::Scan", 'lvmthinscan', ['vg'], { node => $nodename }, sub {
my $res = shift;
foreach my $rec (@$res) {
printf "$rec->{lv}\n";
}
}],
- zfs => [ __PACKAGE__, 'zfsscan', [], { node => $nodename }, sub {
+ zfs => [ "PVE::API2::Storage::Scan", 'zfsscan', [], { node => $nodename }, sub {
my $res = shift;
foreach my $rec (@$res) {
--
2.20.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* [pve-devel] applied: [PATCH storage 2/6] api: scan cifs: port over NT_STATUS filter from pve-manager
2020-12-02 10:51 [pve-devel] unify storage scan API, complete separating local hardware list Thomas Lamprecht
2020-12-02 10:51 ` [pve-devel] applied: [PATCH storage 1/6] factor out scan CLI definition to real API module Thomas Lamprecht
@ 2020-12-02 10:51 ` Thomas Lamprecht
2020-12-02 10:51 ` [pve-devel] applied: [PATCH storage 3/6] api: scan: move over index and usb scan from manager Thomas Lamprecht
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Thomas Lamprecht @ 2020-12-02 10:51 UTC (permalink / raw)
To: pve-devel
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
---
PVE/API2/Storage/Scan.pm | 1 +
1 file changed, 1 insertion(+)
diff --git a/PVE/API2/Storage/Scan.pm b/PVE/API2/Storage/Scan.pm
index 0e6fd9a..44d6628 100644
--- a/PVE/API2/Storage/Scan.pm
+++ b/PVE/API2/Storage/Scan.pm
@@ -127,6 +127,7 @@ __PACKAGE__->register_method({
my $data = [];
foreach my $k (sort keys %$res) {
+ next if $k =~ m/NT_STATUS_/;
push @$data, { share => $k, description => $res->{$k} };
}
--
2.20.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* [pve-devel] applied: [PATCH storage 3/6] api: scan: move over index and usb scan from manager
2020-12-02 10:51 [pve-devel] unify storage scan API, complete separating local hardware list Thomas Lamprecht
2020-12-02 10:51 ` [pve-devel] applied: [PATCH storage 1/6] factor out scan CLI definition to real API module Thomas Lamprecht
2020-12-02 10:51 ` [pve-devel] applied: [PATCH storage 2/6] api: scan cifs: port over NT_STATUS filter from pve-manager Thomas Lamprecht
@ 2020-12-02 10:51 ` Thomas Lamprecht
2020-12-02 10:51 ` [pve-devel] applied: [PATCH manager 4/6] api: use storage scan module from pve-storage Thomas Lamprecht
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Thomas Lamprecht @ 2020-12-02 10:51 UTC (permalink / raw)
To: pve-devel
Add the missing pieces allowing pve-manager to just point the
/nodes/<node>/scan api directory at this module, dropping it's
duplicated copy.
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
---
PVE/API2/Storage/Scan.pm | 84 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 84 insertions(+)
diff --git a/PVE/API2/Storage/Scan.pm b/PVE/API2/Storage/Scan.pm
index 44d6628..bd6c264 100644
--- a/PVE/API2/Storage/Scan.pm
+++ b/PVE/API2/Storage/Scan.pm
@@ -14,6 +14,46 @@ use PVE::SysFSTools;
use base qw(PVE::RESTHandler);
+__PACKAGE__->register_method({
+ name => 'index',
+ path => '',
+ method => 'GET',
+ description => "Index of available scan methods",
+ permissions => {
+ user => 'all',
+ },
+ parameters => {
+ additionalProperties => 0,
+ properties => {
+ node => get_standard_option('pve-node'),
+ },
+ },
+ returns => {
+ type => 'array',
+ items => {
+ type => "object",
+ properties => {
+ method => { type => 'string'},
+ },
+ },
+ links => [ { rel => 'child', href => "{method}" } ],
+ },
+ code => sub {
+ my ($param) = @_;
+
+ my $res = [
+ { method => 'cifs' },
+ { method => 'glusterfs' },
+ { method => 'iscsi' },
+ { method => 'lvm' },
+ { method => 'nfs' },
+ { method => 'usb' },
+ { method => 'zfs' },
+ ];
+
+ return $res;
+ }});
+
__PACKAGE__->register_method({
name => 'nfsscan',
path => 'nfs',
@@ -340,3 +380,47 @@ __PACKAGE__->register_method({
return PVE::Storage::scan_zfs();
}});
+
+__PACKAGE__->register_method({
+ name => 'usbscan',
+ path => 'usb',
+ method => 'GET',
+ description => "List local USB devices.",
+ protected => 1,
+ proxyto => "node",
+ permissions => {
+ check => ['perm', '/', ['Sys.Modify']],
+ },
+ parameters => {
+ additionalProperties => 0,
+ properties => {
+ node => get_standard_option('pve-node'),
+ },
+ },
+ returns => {
+ type => 'array',
+ items => {
+ type => "object",
+ properties => {
+ busnum => { type => 'integer'},
+ class => { type => 'integer'},
+ devnum => { type => 'integer'},
+ level => { type => 'integer'},
+ manufacturer => { type => 'string', optional => 1 },
+ port => { type => 'integer'},
+ prodid => { type => 'string'},
+ product => { type => 'string', optional => 1 },
+ serial => { type => 'string', optional => 1 },
+ speed => { type => 'string'},
+ usbpath => { type => 'string', optional => 1},
+ vendid => { type => 'string'},
+ },
+ },
+ },
+ code => sub {
+ my ($param) = @_;
+
+ return PVE::SysFSTools::scan_usb();
+ }});
+
+1;
--
2.20.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* [pve-devel] applied: [PATCH manager 4/6] api: use storage scan module from pve-storage
2020-12-02 10:51 [pve-devel] unify storage scan API, complete separating local hardware list Thomas Lamprecht
` (2 preceding siblings ...)
2020-12-02 10:51 ` [pve-devel] applied: [PATCH storage 3/6] api: scan: move over index and usb scan from manager Thomas Lamprecht
@ 2020-12-02 10:51 ` Thomas Lamprecht
2020-12-02 10:51 ` [pve-devel] applied: [PATCH manager 5/6] api: add usb list in hardware endpoint Thomas Lamprecht
2020-12-02 10:51 ` [pve-devel] applied: [PATCH manager 6/6] ui: USB selector: use new API endpoint Thomas Lamprecht
5 siblings, 0 replies; 7+ messages in thread
From: Thomas Lamprecht @ 2020-12-02 10:51 UTC (permalink / raw)
To: pve-devel
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
---
note: I had to do a fixup commit for the first hunk, forgot to add it to
staging area on commit -.- but the actual changes are those showed here.
PVE/API2/Nodes.pm | 4 +-
PVE/API2/Makefile | 1 -
PVE/API2/Scan.pm | 424 ----------------------------------------------
debian/control | 4 +-
4 files changed, 4 insertions(+), 429 deletions(-)
delete mode 100644 PVE/API2/Scan.pm
diff --git a/PVE/API2/Nodes.pm b/PVE/API2/Nodes.pm
index d84c3e73..8172231e 100644
--- a/PVE/API2/Nodes.pm
+++ b/PVE/API2/Nodes.pm
@@ -31,7 +31,7 @@ use PVE::API2::Subscription;
use PVE::API2::Services;
use PVE::API2::Network;
use PVE::API2::Tasks;
-use PVE::API2::Scan;
+use PVE::API2::Storage::Scan;
use PVE::API2::Storage::Status;
use PVE::API2::Qemu;
use PVE::API2::Qemu::CPU;
@@ -107,7 +107,7 @@ __PACKAGE__->register_method ({
});
__PACKAGE__->register_method ({
- subclass => "PVE::API2::Scan",
+ subclass => "PVE::API2::Storage::Scan",
path => 'scan',
});
diff --git a/PVE/API2/Makefile b/PVE/API2/Makefile
index bc5ccc36..116922c6 100644
--- a/PVE/API2/Makefile
+++ b/PVE/API2/Makefile
@@ -22,7 +22,6 @@ PERLSOURCE = \
ACMEAccount.pm \
ACMEPlugin.pm \
NodeConfig.pm \
- Scan.pm \
Hardware.pm \
Services.pm
diff --git a/PVE/API2/Scan.pm b/PVE/API2/Scan.pm
deleted file mode 100644
index c096e8f6..00000000
--- a/PVE/API2/Scan.pm
+++ /dev/null
@@ -1,424 +0,0 @@
-package PVE::API2::Scan;
-
-use strict;
-use warnings;
-
-use PVE::SafeSyslog;
-use PVE::Storage;
-use PVE::Storage::LVMPlugin;
-use PVE::SysFSTools;
-use PVE::JSONSchema qw(get_standard_option);
-use PVE::RESTHandler;
-
-use base qw(PVE::RESTHandler);
-
-__PACKAGE__->register_method ({
- name => 'index',
- path => '',
- method => 'GET',
- description => "Index of available scan methods",
- permissions => {
- user => 'all',
- },
- parameters => {
- additionalProperties => 0,
- properties => {
- node => get_standard_option('pve-node'),
- },
- },
- returns => {
- type => 'array',
- items => {
- type => "object",
- properties => { method => { type => 'string'} },
- },
- links => [ { rel => 'child', href => "{method}" } ],
- },
- code => sub {
- my ($param) = @_;
-
- my $res = [
- { method => 'lvm' },
- { method => 'iscsi' },
- { method => 'nfs' },
- { method => 'glusterfs' },
- { method => 'usb' },
- { method => 'zfs' },
- { method => 'cifs' },
- ];
-
- return $res;
- }});
-
-__PACKAGE__->register_method ({
- name => 'zfsscan',
- path => 'zfs',
- method => 'GET',
- description => "Scan zfs pool list on local node.",
- protected => 1,
- proxyto => "node",
- permissions => {
- check => ['perm', '/storage', ['Datastore.Allocate']],
- },
- parameters => {
- additionalProperties => 0,
- properties => {
- node => get_standard_option('pve-node'),
- },
- },
- returns => {
- type => 'array',
- items => {
- type => "object",
- properties => {
- pool => {
- description => "ZFS pool name.",
- type => 'string',
- },
- },
- },
- },
- code => sub {
- my ($param) = @_;
-
- return PVE::Storage::scan_zfs();
- }});
-
-__PACKAGE__->register_method ({
- name => 'nfsscan',
- path => 'nfs',
- method => 'GET',
- description => "Scan remote NFS server.",
- protected => 1,
- proxyto => "node",
- permissions => {
- check => ['perm', '/storage', ['Datastore.Allocate']],
- },
- parameters => {
- additionalProperties => 0,
- properties => {
- node => get_standard_option('pve-node'),
- server => {
- description => "The server address (name or IP).",
- type => 'string', format => 'pve-storage-server',
- },
- },
- },
- returns => {
- type => 'array',
- items => {
- type => "object",
- properties => {
- path => {
- description => "The exported path.",
- type => 'string',
- },
- options => {
- description => "NFS export options.",
- type => 'string',
- },
- },
- },
- },
- code => sub {
- my ($param) = @_;
-
- my $server = $param->{server};
- my $res = PVE::Storage::scan_nfs($server);
-
- my $data = [];
- foreach my $k (keys %$res) {
- push @$data, { path => $k, options => $res->{$k} };
- }
- return $data;
- }});
-
-__PACKAGE__->register_method ({
- name => 'cifsscan',
- path => 'cifs',
- method => 'GET',
- description => "Scan remote CIFS server.",
- protected => 1,
- proxyto => "node",
- permissions => {
- check => ['perm', '/storage', ['Datastore.Allocate']],
- },
- parameters => {
- additionalProperties => 0,
- properties => {
- node => get_standard_option('pve-node'),
- server => {
- description => "The server address (name or IP).",
- type => 'string', format => 'pve-storage-server',
- },
- username => {
- description => "User name.",
- type => 'string',
- optional => 1,
- },
- password => {
- description => "User password.",
- type => 'string',
- optional => 1,
- },
- domain => {
- description => "SMB domain (Workgroup).",
- type => 'string',
- optional => 1,
- },
- },
- },
- returns => {
- type => 'array',
- items => {
- type => "object",
- properties => {
- share => {
- description => "The cifs share name.",
- type => 'string',
- },
- description => {
- description => "Descriptive text from server.",
- type => 'string',
- },
- },
- },
- },
- code => sub {
- my ($param) = @_;
-
- my $server = $param->{server};
-
- my $username = $param->{username};
- my $password = $param->{password};
- my $domain = $param->{domain};
-
- my $res = PVE::Storage::scan_cifs($server, $username, $password, $domain);
-
- my $data = [];
- foreach my $k (keys %$res) {
- next if $k =~ m/NT_STATUS_/;
- push @$data, { share => $k, description => $res->{$k} };
- }
-
- return $data;
- }});
-
-# Note: GlusterFS currently does not have an equivalent of showmount.
-# As workaround, we simply use nfs showmount.
-# see http://www.gluster.org/category/volumes/
-
-__PACKAGE__->register_method ({
- name => 'glusterfsscan',
- path => 'glusterfs',
- method => 'GET',
- description => "Scan remote GlusterFS server.",
- protected => 1,
- proxyto => "node",
- permissions => {
- check => ['perm', '/storage', ['Datastore.Allocate']],
- },
- parameters => {
- additionalProperties => 0,
- properties => {
- node => get_standard_option('pve-node'),
- server => {
- description => "The server address (name or IP).",
- type => 'string', format => 'pve-storage-server',
- },
- },
- },
- returns => {
- type => 'array',
- items => {
- type => "object",
- properties => {
- volname => {
- description => "The volume name.",
- type => 'string',
- },
- },
- },
- },
- code => sub {
- my ($param) = @_;
-
- my $server = $param->{server};
- my $res = PVE::Storage::scan_nfs($server);
-
- my $data = [];
- foreach my $path (keys %$res) {
- if ($path =~ m!^/([^\s/]+)$!) {
- push @$data, { volname => $1 };
- }
- }
- return $data;
- }});
-
-__PACKAGE__->register_method ({
- name => 'iscsiscan',
- path => 'iscsi',
- method => 'GET',
- description => "Scan remote iSCSI server.",
- protected => 1,
- proxyto => "node",
- permissions => {
- check => ['perm', '/storage', ['Datastore.Allocate']],
- },
- parameters => {
- additionalProperties => 0,
- properties => {
- node => get_standard_option('pve-node'),
- portal => {
- description => "The iSCSI portal (IP or DNS name with optional port).",
- type => 'string', format => 'pve-storage-portal-dns',
- },
- },
- },
- returns => {
- type => 'array',
- items => {
- type => "object",
- properties => {
- target => {
- description => "The iSCSI target name.",
- type => 'string',
- },
- portal => {
- description => "The iSCSI portal name.",
- type => 'string',
- },
- },
- },
- },
- code => sub {
- my ($param) = @_;
-
- my $res = PVE::Storage::scan_iscsi($param->{portal});
-
- my $data = [];
- foreach my $k (keys %$res) {
- push @$data, { target => $k, portal => join(',', @{$res->{$k}}) };
- }
-
- return $data;
- }});
-
-__PACKAGE__->register_method ({
- name => 'lvmscan',
- path => 'lvm',
- method => 'GET',
- description => "List local LVM volume groups.",
- protected => 1,
- proxyto => "node",
- permissions => {
- check => ['perm', '/storage', ['Datastore.Allocate']],
- },
- parameters => {
- additionalProperties => 0,
- properties => {
- node => get_standard_option('pve-node'),
- },
- },
- returns => {
- type => 'array',
- items => {
- type => "object",
- properties => {
- vg => {
- description => "The LVM logical volume group name.",
- type => 'string',
- },
- },
- },
- },
- code => sub {
- my ($param) = @_;
-
- my $res = PVE::Storage::LVMPlugin::lvm_vgs();
- return PVE::RESTHandler::hash_to_array($res, 'vg');
- }});
-
-__PACKAGE__->register_method ({
- name => 'lvmthinscan',
- path => 'lvmthin',
- method => 'GET',
- description => "List local LVM Thin Pools.",
- protected => 1,
- proxyto => "node",
- permissions => {
- check => ['perm', '/storage', ['Datastore.Allocate']],
- },
- parameters => {
- additionalProperties => 0,
- properties => {
- node => get_standard_option('pve-node'),
- vg => {
- type => 'string',
- pattern => '[a-zA-Z0-9\.\+\_][a-zA-Z0-9\.\+\_\-]+', # see lvm(8) manpage
- maxLength => 100,
- },
- },
- },
- returns => {
- type => 'array',
- items => {
- type => "object",
- properties => {
- lv => {
- description => "The LVM Thin Pool name (LVM logical volume).",
- type => 'string',
- },
- },
- },
- },
- code => sub {
- my ($param) = @_;
-
- return PVE::Storage::LvmThinPlugin::list_thinpools($param->{vg});
- }});
-
-__PACKAGE__->register_method ({
- name => 'usbscan',
- path => 'usb',
- method => 'GET',
- description => "List local USB devices.",
- protected => 1,
- proxyto => "node",
- permissions => {
- check => ['perm', '/', ['Sys.Modify']],
- },
- parameters => {
- additionalProperties => 0,
- properties => {
- node => get_standard_option('pve-node'),
- },
- },
- returns => {
- type => 'array',
- items => {
- type => "object",
- properties => {
- busnum => { type => 'integer'},
- devnum => { type => 'integer'},
- port => { type => 'integer'},
- usbpath => { type => 'string', optional => 1},
- level => { type => 'integer'},
- class => { type => 'integer'},
- vendid => { type => 'string'},
- prodid => { type => 'string'},
- speed => { type => 'string'},
-
- product => { type => 'string', optional => 1 },
- serial => { type => 'string', optional => 1 },
- manufacturer => { type => 'string', optional => 1 },
- },
- },
- },
- code => sub {
- my ($param) = @_;
-
- return PVE::SysFSTools::scan_usb();
- }});
-
-1;
diff --git a/debian/control b/debian/control
index cb4977f4..629dfb34 100644
--- a/debian/control
+++ b/debian/control
@@ -13,7 +13,7 @@ Build-Depends: debhelper (>= 11~),
libpve-common-perl,
libpve-guest-common-perl (>= 3.0-8~),
libpve-http-server-perl (>= 2.0-12),
- libpve-storage-perl (>= 6.1-7),
+ libpve-storage-perl (>= 6.3-2),
libtemplate-perl,
libtest-mockmodule-perl,
lintian,
@@ -52,7 +52,7 @@ Depends: apt-transport-https | apt (>= 1.5~),
libpve-common-perl (>= 6.2-2),
libpve-guest-common-perl (>= 3.1-3~),
libpve-http-server-perl (>= 3.0-4),
- libpve-storage-perl (>= 6.2-11),
+ libpve-storage-perl (>= 6.3-2),
librados2-perl,
libtemplate-perl,
libterm-readline-gnu-perl,
--
2.20.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* [pve-devel] applied: [PATCH manager 5/6] api: add usb list in hardware endpoint
2020-12-02 10:51 [pve-devel] unify storage scan API, complete separating local hardware list Thomas Lamprecht
` (3 preceding siblings ...)
2020-12-02 10:51 ` [pve-devel] applied: [PATCH manager 4/6] api: use storage scan module from pve-storage Thomas Lamprecht
@ 2020-12-02 10:51 ` Thomas Lamprecht
2020-12-02 10:51 ` [pve-devel] applied: [PATCH manager 6/6] ui: USB selector: use new API endpoint Thomas Lamprecht
5 siblings, 0 replies; 7+ messages in thread
From: Thomas Lamprecht @ 2020-12-02 10:51 UTC (permalink / raw)
To: pve-devel
As envisioned in[0][1], better late than never.
[0]: commit 3bca5efd9c219d97c2eac5685bf6cac579a3b0f1
[1]: https://lists.proxmox.com/pipermail/pve-devel/2018-November/034694.html
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
---
PVE/API2/Hardware.pm | 9 ++++++-
PVE/API2/Hardware/Makefile | 3 ++-
PVE/API2/Hardware/USB.pm | 53 ++++++++++++++++++++++++++++++++++++++
3 files changed, 63 insertions(+), 2 deletions(-)
create mode 100644 PVE/API2/Hardware/USB.pm
diff --git a/PVE/API2/Hardware.pm b/PVE/API2/Hardware.pm
index d2b8c45a..f59bfbe0 100644
--- a/PVE/API2/Hardware.pm
+++ b/PVE/API2/Hardware.pm
@@ -7,6 +7,7 @@ use PVE::JSONSchema qw(get_standard_option);
use PVE::RESTHandler;
use PVE::API2::Hardware::PCI;
+use PVE::API2::Hardware::USB;
use base qw(PVE::RESTHandler);
@@ -15,6 +16,12 @@ __PACKAGE__->register_method ({
path => 'pci',
});
+__PACKAGE__->register_method ({
+ subclass => "PVE::API2::Hardware::USB",
+ path => 'usb',
+});
+
+
__PACKAGE__->register_method ({
name => 'index',
path => '',
@@ -42,7 +49,7 @@ __PACKAGE__->register_method ({
my $res = [
{ type => 'pci' },
- # TODO: move usb scan here (6.0 api change)
+ { type => 'usb' },
];
return $res;
diff --git a/PVE/API2/Hardware/Makefile b/PVE/API2/Hardware/Makefile
index 2dc824b9..d27d2201 100644
--- a/PVE/API2/Hardware/Makefile
+++ b/PVE/API2/Hardware/Makefile
@@ -1,7 +1,8 @@
include ../../../defines.mk
PERLSOURCE= \
- PCI.pm
+ PCI.pm \
+ USB.pm \
all:
diff --git a/PVE/API2/Hardware/USB.pm b/PVE/API2/Hardware/USB.pm
new file mode 100644
index 00000000..d7cb6607
--- /dev/null
+++ b/PVE/API2/Hardware/USB.pm
@@ -0,0 +1,53 @@
+package PVE::API2::Hardware::USB;
+
+use strict;
+use warnings;
+
+use PVE::JSONSchema qw(get_standard_option);
+
+use PVE::SysFSTools;
+
+use base qw(PVE::RESTHandler);
+
+__PACKAGE__->register_method({
+ name => 'usbscan',
+ path => '',
+ method => 'GET',
+ description => "List local USB devices.",
+ protected => 1,
+ proxyto => "node",
+ permissions => {
+ check => ['perm', '/', ['Sys.Modify']],
+ },
+ parameters => {
+ additionalProperties => 0,
+ properties => {
+ node => get_standard_option('pve-node'),
+ },
+ },
+ returns => {
+ type => 'array',
+ items => {
+ type => "object",
+ properties => {
+ busnum => { type => 'integer'},
+ class => { type => 'integer'},
+ devnum => { type => 'integer'},
+ level => { type => 'integer'},
+ manufacturer => { type => 'string', optional => 1 },
+ port => { type => 'integer'},
+ prodid => { type => 'string'},
+ product => { type => 'string', optional => 1 },
+ serial => { type => 'string', optional => 1 },
+ speed => { type => 'string'},
+ usbpath => { type => 'string', optional => 1},
+ vendid => { type => 'string'},
+ },
+ },
+ },
+ code => sub {
+ my ($param) = @_;
+
+ return PVE::SysFSTools::scan_usb();
+ }
+});
--
2.20.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* [pve-devel] applied: [PATCH manager 6/6] ui: USB selector: use new API endpoint
2020-12-02 10:51 [pve-devel] unify storage scan API, complete separating local hardware list Thomas Lamprecht
` (4 preceding siblings ...)
2020-12-02 10:51 ` [pve-devel] applied: [PATCH manager 5/6] api: add usb list in hardware endpoint Thomas Lamprecht
@ 2020-12-02 10:51 ` Thomas Lamprecht
5 siblings, 0 replies; 7+ messages in thread
From: Thomas Lamprecht @ 2020-12-02 10:51 UTC (permalink / raw)
To: pve-devel
so that we can sunset the usbscan from pve-storage's scan API, which
was never fitting there anyway.
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
---
www/manager6/form/USBSelector.js | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/www/manager6/form/USBSelector.js b/www/manager6/form/USBSelector.js
index 41653cfc..b53880f6 100644
--- a/www/manager6/form/USBSelector.js
+++ b/www/manager6/form/USBSelector.js
@@ -39,8 +39,8 @@ Ext.define('PVE.form.USBSelector', {
var store = new Ext.data.Store({
model: 'pve-usb-' + me.type,
proxy: {
- type: 'proxmox',
- url: "/api2/json/nodes/" + nodename + "/scan/usb"
+ type: 'proxmox',
+ url: `/api2/json/nodes/${nodename}/hardware/usb`,
},
filters: [
function (item) {
--
2.20.1
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2020-12-02 10:52 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-02 10:51 [pve-devel] unify storage scan API, complete separating local hardware list Thomas Lamprecht
2020-12-02 10:51 ` [pve-devel] applied: [PATCH storage 1/6] factor out scan CLI definition to real API module Thomas Lamprecht
2020-12-02 10:51 ` [pve-devel] applied: [PATCH storage 2/6] api: scan cifs: port over NT_STATUS filter from pve-manager Thomas Lamprecht
2020-12-02 10:51 ` [pve-devel] applied: [PATCH storage 3/6] api: scan: move over index and usb scan from manager Thomas Lamprecht
2020-12-02 10:51 ` [pve-devel] applied: [PATCH manager 4/6] api: use storage scan module from pve-storage Thomas Lamprecht
2020-12-02 10:51 ` [pve-devel] applied: [PATCH manager 5/6] api: add usb list in hardware endpoint Thomas Lamprecht
2020-12-02 10:51 ` [pve-devel] applied: [PATCH manager 6/6] ui: USB selector: use new API endpoint Thomas Lamprecht
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox