[pve-devel] r5115 - in qemu-server/pve2: . PVE/API2
svn-commits at proxmox.com
svn-commits at proxmox.com
Fri Sep 10 15:03:10 CEST 2010
Author: dietmar
Date: 2010-09-10 13:03:10 +0000 (Fri, 10 Sep 2010)
New Revision: 5115
Modified:
qemu-server/pve2/ChangeLog
qemu-server/pve2/PVE/API2/QemuServer.pm
qemu-server/pve2/QemuServer.pm
qemu-server/pve2/nqm
Log:
Modified: qemu-server/pve2/ChangeLog
===================================================================
--- qemu-server/pve2/ChangeLog 2010-09-10 12:58:46 UTC (rev 5114)
+++ qemu-server/pve2/ChangeLog 2010-09-10 13:03:10 UTC (rev 5115)
@@ -1,5 +1,8 @@
2010-09-10 Proxmox Support Team <support at proxmox.com>
+ * QemuServer.pm: register all options with
+ PVE::JSONSchema::register_standard_option()
+
* PVE/API2/QemuServer.pm: implement 'update_vm'
* QemuServer.pm: use a JSON Schema to describe all options. We can
Modified: qemu-server/pve2/PVE/API2/QemuServer.pm
===================================================================
--- qemu-server/pve2/PVE/API2/QemuServer.pm 2010-09-10 12:58:46 UTC (rev 5114)
+++ qemu-server/pve2/PVE/API2/QemuServer.pm 2010-09-10 13:03:10 UTC (rev 5115)
@@ -4,8 +4,10 @@
use warnings;
use PVE::SafeSyslog;
+use PVE::Tools qw(extract_param);
use PVE::Exception qw(raise raise_param_exc);
use PVE::INotify qw(read_file);
+use PVE::JSONSchema qw(get_standard_option);
use PVE::RESTHandler;
use PVE::QemuServer;
@@ -73,7 +75,7 @@
parameters => {
additionalProperties => 0,
properties => {
- node => { type => 'string', format => 'pve-node' },
+ node => get_standard_option('pve-node'),
},
},
returns => {
@@ -102,26 +104,20 @@
additionalProperties => 0,
properties => PVE::QemuServer::json_config_properties(
{
- node => { type => 'string', format => 'pve-node' },
- vmid => {
- description => "The (unique) ID of the VM.",
- type => 'integer', format => 'pve-vmid',
- minimum => 1,
- },
+ node => get_standard_option('pve-node'),
+ vmid => get_standard_option('pve-vmid'),
}),
},
returns => { type => 'null'},
code => sub {
my ($param) = @_;
- my $node = $param->{node};
- delete $param->{node};
+ my $node = extract_param($param, 'node');
# fixme: proxy to correct node
# fixme: fork worker?
- my $vmid = $param->{vmid};
- delete $param->{vmid};
+ my $vmid = extract_param($param, 'vmid');
my $filename = PVE::QemuServer::config_file ($vmid);
# first test (befor locking)
@@ -188,12 +184,8 @@
additionalProperties => 0,
properties => PVE::QemuServer::json_config_properties(
{
- node => { type => 'string', format => 'pve-node' },
- vmid => {
- description => "The (unique) ID of the VM.",
- type => 'integer', format => 'pve-vmid',
- minimum => 1,
- },
+ node => get_standard_option('pve-node'),
+ vmid => get_standard_option('pve-vmid'),
skiplock => {
description => "Ignore locks - only root is allowed to use this option.",
type => 'boolean',
@@ -210,29 +202,22 @@
code => sub {
my ($param) = @_;
- my $node = $param->{node};
- delete $param->{node};
+ my $node = extract_param($param, 'node');
+
# fixme: proxy to correct node
# fixme: fork worker?
- my $vmid = $param->{vmid};
- delete $param->{vmid};
+ my $vmid = extract_param($param, 'vmid');
+ my $skiplock = extract_param($param, 'skiplock');
+ my $delete = extract_param($param, 'delete');
- my $skiplock = $param->{skiplock};
- delete $param->{skiplock};
-
- my $delete = $param->{delete};
- delete $param->{delete};
-
die "no options specified\n" if !$delete && !scalar(keys %$param);
my $storecfg = read_file('storagecfg');
my $opts = PVE::QemuServer::parse_options_new($storecfg, $param->{vmid}, $param, 1);
- print Dumper($opts);
-
my $updatefn = sub {
my $conf = PVE::QemuServer::load_config ($vmid);
@@ -268,4 +253,34 @@
}});
+__PACKAGE__->register_method ({
+ name => 'vm_config',
+ path => '{node}/{vmid}',
+ method => 'GET',
+ description => "Get virtual machine configuration.",
+ parameters => {
+ additionalProperties => 0,
+ properties => {
+ node => { type => 'string', format => 'pve-node' },
+ vmid => {
+ description => "The (unique) ID of the VM.",
+ type => 'integer', format => 'pve-vmid',
+ minimum => 1,
+ },
+ },
+ },
+ returns => {},
+ code => sub {
+ my ($param) = @_;
+
+ my $conf = PVE::QemuServer::load_config ($param->{vmid});
+
+ # fixme: that should not be added to the config
+ delete $conf->{disksize};
+ delete $conf->{disktype};
+ delete $conf->{diskinfo};
+
+ return $conf;
+ }});
+
1;
Modified: qemu-server/pve2/QemuServer.pm
===================================================================
--- qemu-server/pve2/QemuServer.pm 2010-09-10 12:58:46 UTC (rev 5114)
+++ qemu-server/pve2/QemuServer.pm 2010-09-10 13:03:10 UTC (rev 5115)
@@ -391,6 +391,9 @@
#initrd => 'file',
##soundhw => 'string',
+while (my ($k, $v) = each %$confdesc) {
+ PVE::JSONSchema::register_standard_option("pve-qm-$k", $v);
+}
my $MAX_IDE_DISKS = 4;
my $MAX_SCSI_DISKS = 16;
@@ -413,6 +416,7 @@
XX:XX:XX:XX:XX:XX should be an unique MAC address
EODESCR
};
+PVE::JSONSchema::register_standard_option("pve-qm-vlan", $vlandesc);
for (my $i = 0; $i < $MAX_VLANS; $i++) {
$confdesc->{"vlan$i"} = $vlandesc;
@@ -426,6 +430,7 @@
typetext => '[volume=]volume,] [,media=cdrom|disk] [,cyls=c,heads=h,secs=s[,trans=t]] [,snapshot=on|off] [,cache=none|writethrough|writeback] [,format=f]',
description => "Use volume as IDE hard disk or CD-ROM (n is 0 to 3).",
};
+PVE::JSONSchema::register_standard_option("pve-qm-ide", $idedesc);
my $scsidesc = {
optional => 1,
@@ -433,6 +438,7 @@
typetext => '[volume=]volume,] [,media=cdrom|disk] [,cyls=c,heads=h,secs=s[,trans=t]] [,snapshot=on|off] [,cache=none|writethrough|writeback] [,format=f]',
description => "Use volume as SCSI hard disk or CD-ROM (n is 0 to 15).",
};
+PVE::JSONSchema::register_standard_option("pve-qm-scsi", $scsidesc);
my $virtiodesc = {
optional => 1,
@@ -440,6 +446,7 @@
typetext => '[volume=]volume,] [,media=cdrom|disk] [,cyls=c,heads=h,secs=s[,trans=t]] [,snapshot=on|off] [,cache=none|writethrough|writeback] [,format=f]',
description => "Use volume as VIRTIO hard disk (n is 0 to 15).",
};
+PVE::JSONSchema::register_standard_option("pve-qm-virtio", $virtiodesc);
for (my $i = 0; $i < $MAX_IDE_DISKS; $i++) {
$drivename_hash->{"ide$i"} = 1;
Modified: qemu-server/pve2/nqm
===================================================================
--- qemu-server/pve2/nqm 2010-09-10 12:58:46 UTC (rev 5114)
+++ qemu-server/pve2/nqm 2010-09-10 13:03:10 UTC (rev 5115)
@@ -49,6 +49,15 @@
create => [ "PVE::API2::QemuServer", 'create_vm', ['vmid'], { node => $hostname } ],
set => [ "PVE::API2::QemuServer", 'update_vm', ['vmid'], { node => $hostname } ],
+
+ config => [ "PVE::API2::QemuServer", 'vm_config', ['vmid'],
+ { node => $hostname }, sub {
+ my $config = shift;
+ foreach my $k (sort (keys %$config)) {
+ my $v = $config->{$k};
+ print "$k: $v\n";
+ }
+ }],
};
More information about the pve-devel
mailing list