[pve-devel] [PATCH qemu-server 3/7] api: add Machine module to query machine types
Stefan Reiter
s.reiter at proxmox.com
Thu Mar 4 13:52:05 CET 2021
The file is provided by pve-qemu-kvm.
Signed-off-by: Stefan Reiter <s.reiter at proxmox.com>
---
PVE/API2/Qemu/Machine.pm | 49 ++++++++++++++++++++++++++++++++++++++++
PVE/API2/Qemu/Makefile | 2 +-
2 files changed, 50 insertions(+), 1 deletion(-)
create mode 100644 PVE/API2/Qemu/Machine.pm
diff --git a/PVE/API2/Qemu/Machine.pm b/PVE/API2/Qemu/Machine.pm
new file mode 100644
index 0000000..c0a8c57
--- /dev/null
+++ b/PVE/API2/Qemu/Machine.pm
@@ -0,0 +1,49 @@
+package PVE::API2::Qemu::Machine;
+
+use strict;
+use warnings;
+
+use PVE::RESTHandler;
+use PVE::JSONSchema qw(get_standard_option);
+use PVE::Tools qw(file_get_contents);
+
+use base qw(PVE::RESTHandler);
+
+__PACKAGE__->register_method({
+ name => 'types',
+ path => '',
+ method => 'GET',
+ proxyto => 'node',
+ description => "Get available QEMU/KVM machine types.",
+ permissions => {
+ user => 'all',
+ },
+ parameters => {
+ additionalProperties => 0,
+ properties => {
+ node => get_standard_option('pve-node'),
+ },
+ },
+ returns => {
+ type => 'array',
+ items => {
+ type => 'object',
+ properties => {
+ name => {
+ type => 'string',
+ description => "Name of machine type.",
+ },
+ },
+ },
+ },
+ code => sub {
+ my $content = eval {
+ file_get_contents("/usr/share/kvm/machine-versions-x86_64");
+ };
+ die "could not get supported machine versions (try updating 'pve-qemu-kvm') - $@" if $@;
+ my @data = split(m/\n/, $content);
+ @data = map { { name => $_ } } @data;
+ return \@data;
+ }});
+
+1;
diff --git a/PVE/API2/Qemu/Makefile b/PVE/API2/Qemu/Makefile
index f4b7be6..5d4abda 100644
--- a/PVE/API2/Qemu/Makefile
+++ b/PVE/API2/Qemu/Makefile
@@ -1,4 +1,4 @@
-SOURCES=Agent.pm CPU.pm
+SOURCES=Agent.pm CPU.pm Machine.pm
.PHONY: install
install:
--
2.20.1
More information about the pve-devel
mailing list