[pve-devel] r5143 - in qemu-server/pve2: . PVE/API2 PVE/API2/Qemu

svn-commits at proxmox.com svn-commits at proxmox.com
Tue Sep 14 11:22:31 CEST 2010


Author: dietmar
Date: 2010-09-14 09:22:31 +0000 (Tue, 14 Sep 2010)
New Revision: 5143

Added:
   qemu-server/pve2/PVE/API2/Qemu/
   qemu-server/pve2/PVE/API2/Qemu/Config.pm
   qemu-server/pve2/PVE/API2/Qemu/Makefile
   qemu-server/pve2/PVE/API2/Qemu/Status.pm
   qemu-server/pve2/PVE/API2/Qemu/VNC.pm
Removed:
   qemu-server/pve2/PVE/API2/QemuServer.pm
   qemu-server/pve2/PVE/API2/QemuServerStatus.pm
Modified:
   qemu-server/pve2/ChangeLog
   qemu-server/pve2/PVE/API2/Makefile
   qemu-server/pve2/nqm
Log:
 use better class names


Modified: qemu-server/pve2/ChangeLog
===================================================================
--- qemu-server/pve2/ChangeLog	2010-09-14 09:19:49 UTC (rev 5142)
+++ qemu-server/pve2/ChangeLog	2010-09-14 09:22:31 UTC (rev 5143)
@@ -1,3 +1,9 @@
+2010-09-14  Proxmox Support Team  <support at proxmox.com>
+
+	* PVE/API2/Qemu/Status.pm: use better class name
+
+	* PVE/API2/Qemu/Config.pm: use better class name
+
 2010-09-13  Proxmox Support Team  <support at proxmox.com>
 
 	* nqm: implement vncticket

Modified: qemu-server/pve2/PVE/API2/Makefile
===================================================================
--- qemu-server/pve2/PVE/API2/Makefile	2010-09-14 09:19:49 UTC (rev 5142)
+++ qemu-server/pve2/PVE/API2/Makefile	2010-09-14 09:22:31 UTC (rev 5143)
@@ -1,5 +1,4 @@
 
 .PHONY: install
 install:
-	install -D -m 0644 QemuServer.pm ${DESTDIR}${PERLDIR}/PVE/API2/QemuServer.pm
-	install -D -m 0644 QemuServerStatus.pm ${DESTDIR}${PERLDIR}/PVE/API2/QemuServerStatus.pm
+	make -C Qemu install

Copied: qemu-server/pve2/PVE/API2/Qemu/Config.pm (from rev 5140, qemu-server/pve2/PVE/API2/QemuServer.pm)
===================================================================
--- qemu-server/pve2/PVE/API2/Qemu/Config.pm	                        (rev 0)
+++ qemu-server/pve2/PVE/API2/Qemu/Config.pm	2010-09-14 09:22:31 UTC (rev 5143)
@@ -0,0 +1,288 @@
+package PVE::API2::Qemu::Config;
+
+use strict;
+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;
+use PVE::RPCEnvironment;
+
+use Data::Dumper; # fixme: remove
+
+# API URLs
+#
+## GET    /vms/
+## GET    /vms/index  status of all VMs (cluster wide)
+
+# GET    /vms/config/qm/{node}/  list of all Qemu VMs (per node)
+# POST   /vms/config/qm/{node}/  create VM
+# GET    /vms/config/qm/{node}/{vmid}  get VM config
+# PUT    /vms/config/qm/{node}/{vmid}  set VM config
+# DELETE /vms/config/qm/{node}/{vmid}  destroy VM
+
+# GET    /vms/status/qm  status of all Qemu VMs (cluster wide)
+# GET    /vms/status/qm/{node}/  status of all Qemu VMs (per node)
+# GET    /vms/status/qm/{node}/{vmid}  get VM status
+# PUT    /vms/status/qm/{node}/{vmid}  set VM status
+
+# POST    /vms/vncproxy/qm  create vnc proxy
+
+use base qw(PVE::RESTHandler);
+
+__PACKAGE__->register_method ({
+    name => 'vmlist', 
+    path => '{node}', 
+    method => 'GET',
+    description => "Virtual machine index.",
+    parameters => {
+    	additionalProperties => 0,
+	properties => {
+	    node => get_standard_option('pve-node'),
+	},
+    },
+    returns => {
+	type => 'array',
+	items => {
+	    type => "object",
+	    properties => {},
+	},
+	links => [ { rel => 'child', href => "{vmid}" } ],
+    },
+    code => sub {
+	my ($param) = @_;
+
+	my $vmstatus =  PVE::QemuServer::vmstatus();
+
+	return PVE::RESTHandler::hash_to_array($vmstatus, 'vmid');
+
+    }});
+
+__PACKAGE__->register_method ({
+    name => 'create_vm', 
+    path => '{node}', 
+    method => 'POST',
+    description => "Create new virtual machine.",
+    parameters => {
+    	additionalProperties => 0,
+	properties => PVE::QemuServer::json_config_properties(
+	    {
+		node => get_standard_option('pve-node'),
+		vmid => get_standard_option('pve-vmid'),
+	    }),
+    },
+    returns => { type => 'null'},
+    code => sub {
+	my ($param) = @_;
+
+	my $node = extract_param($param, 'node');
+
+	# fixme: proxy to correct node
+	# fixme: fork worker?
+
+	my $vmid = extract_param($param, 'vmid');
+
+	my $filename = PVE::QemuServer::config_file ($vmid);
+	# first test (befor locking)
+	die "unable to create vm $vmid: config file already exists\n" 
+	    if -f $filename;
+	
+
+	my $storecfg = read_file('storagecfg');
+
+	my $opts = PVE::QemuServer::parse_options_new($storecfg, $param->{vmid}, $param, 1);
+
+	PVE::QemuServer::add_random_macs ($opts);
+
+	#fixme: ? syslog ('info', "VM $vmid creating new virtual machine");
+	
+	my $vollist = [];
+
+	my $createfn = sub {
+
+	    # second test (after locking test is accurate)
+	    die "unable to create vm $vmid: config file already exists\n" 
+		if -f $filename;
+
+	    $vollist = PVE::QemuServer::create_disks ($storecfg, $vmid, $opts);
+
+	    # try to be smart about bootdisk
+	    my @disks = PVE::QemuServer::disknames();
+	    my $firstdisk;
+	    foreach my $ds (reverse @disks) {
+		next if !$opts->{$ds};
+		my $disk = PVE::QemuServer::parse_drive ($ds, $opts->{$ds});
+		next if PVE::QemuServer::drive_is_cdrom ($disk);
+		$firstdisk = $ds;
+	    }
+
+	    if (!$opts->{bootdisk} && $firstdisk) {
+		$opts->{bootdisk} = $firstdisk; 
+	    }
+
+	    PVE::QemuServer::create_conf_nolock($vmid, $opts);
+	};
+
+	eval { PVE::QemuServer::lock_config ($vmid, $createfn); };
+	my $err = $@;
+
+	if ($err) {
+	    # fixme ? syslog ('err', "VM $vmid create failed - $err");
+	    foreach my $volid (@$vollist) {
+		eval { PVE::Storage::vdisk_free ($storecfg, $volid); };
+		warn $@ if $@;
+	    }
+	    die "create failed - $err";
+	}
+
+	return undef;
+    }});
+
+__PACKAGE__->register_method ({
+    name => 'update_vm', 
+    path => '{node}/{vmid}', 
+    method => 'PUT',
+    description => "Set virtual machine options.",
+    parameters => {
+    	additionalProperties => 0,
+	properties => PVE::QemuServer::json_config_properties(
+	    {
+		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', 
+		    optional => 1,
+		},
+		delete => {
+		    type => 'string', format => 'pve-configid-list',
+		    description => "A list of settings you want to delete.",
+		    optional => 1,
+		},
+	    }),
+    },
+    returns => { type => 'null'},
+    code => sub {
+	my ($param) = @_;
+
+	my $rpcenv = PVE::RPCEnvironment::get();
+
+	my $user = $rpcenv->get_user();
+
+	my $node = extract_param($param, 'node');
+
+	# fixme: proxy to correct node
+	# fixme: fork worker?
+
+	my $vmid = extract_param($param, 'vmid');
+
+	my $skiplock = extract_param($param, 'skiplock');
+	raise_param_exc({ skiplock => "Only root may use this option." }) if $user ne 'root';
+
+	my $delete = extract_param($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);
+
+	my $updatefn =  sub {
+
+	    my $conf = PVE::QemuServer::load_config ($vmid);
+
+	    PVE::QemuServer::check_lock($conf) if !$skiplock;
+
+	    my $unset = {};
+
+	    foreach my $opt (PVE::Tools::split_list($delete)) {
+		if (!PVE::QemuServer::option_exists($opt)) {
+		    raise_param_exc({ delete => "unknown option '$opt'" });
+		} 
+		next if !defined ($conf->{$opt});
+		if (PVE::QemuServer::valid_drivename($opt)) {
+		    my $disk = $conf->{diskinfo}->{$opt};
+		    if ($disk && !PVE::QemuServer::drive_is_cdrom ($disk)) {
+			PVE::QemuServer::unlink_image($storecfg, $vmid, $disk->{file});
+		    }
+		}
+		$unset->{$opt} = 1;
+	    }
+
+	    PVE::QemuServer::add_random_macs ($opts);
+
+	    PVE::QemuServer::create_disks ($storecfg, $vmid, $opts);
+
+	    PVE::QemuServer::change_config_nolock  ($vmid, $opts, $unset, 1);
+	};
+
+	PVE::QemuServer::lock_config ($vmid, $updatefn);
+
+	return undef;
+    }});
+
+
+__PACKAGE__->register_method ({
+    name => 'vm_config', 
+    path => '{node}/{vmid}', 
+    method => 'GET',
+    description => "Get virtual machine configuration.",
+    parameters => {
+    	additionalProperties => 0,
+	properties => {
+	    node => get_standard_option('pve-node'),
+	    vmid => get_standard_option('pve-vmid'),
+	},
+    },
+    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;
+    }});
+
+__PACKAGE__->register_method ({
+    name => 'destroy_vm', 
+    path => '{node}/{vmid}', 
+    method => 'DELETE',
+    description => "Destroy the vm (also delete all used/owned volumes).",
+    parameters => {
+    	additionalProperties => 0,
+	properties => {
+	    node => get_standard_option('pve-node'),
+	    vmid => get_standard_option('pve-vmid'),
+	},
+    },
+    returns => { type => 'null' },
+    code => sub {
+	my ($param) = @_;
+
+	my $rpcenv = PVE::RPCEnvironment::get();
+
+	my $user = $rpcenv->get_user();
+
+	my $vmid = $param->{vmid};
+
+	my $skiplock = $param->{skiplock};
+	raise_param_exc({ skiplock => "Only root may use this option." }) 
+	    if $user ne 'root';
+
+	my $storecfg = read_file('storagecfg');
+
+	PVE::QemuServer::vm_destroy ($storecfg, $vmid, $skiplock);
+
+	return undef;
+    }});
+
+1;

Added: qemu-server/pve2/PVE/API2/Qemu/Makefile
===================================================================
--- qemu-server/pve2/PVE/API2/Qemu/Makefile	                        (rev 0)
+++ qemu-server/pve2/PVE/API2/Qemu/Makefile	2010-09-14 09:22:31 UTC (rev 5143)
@@ -0,0 +1,8 @@
+SOURCES=           \
+	Config.pm  \
+	Status.pm \
+	VNC.pm
+
+.PHONY: install
+install:
+	for i in ${SOURCES}; do install -D -m 0644 $$i ${DESTDIR}${PERLDIR}/PVE/API2/Qemu/$$i; done

Copied: qemu-server/pve2/PVE/API2/Qemu/Status.pm (from rev 5140, qemu-server/pve2/PVE/API2/QemuServerStatus.pm)
===================================================================
--- qemu-server/pve2/PVE/API2/Qemu/Status.pm	                        (rev 0)
+++ qemu-server/pve2/PVE/API2/Qemu/Status.pm	2010-09-14 09:22:31 UTC (rev 5143)
@@ -0,0 +1,151 @@
+package PVE::API2::Qemu::Status;
+
+use strict;
+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;
+use PVE::RPCEnvironment;
+
+use Data::Dumper; # fixme: remove
+
+use base qw(PVE::RESTHandler);
+
+
+__PACKAGE__->register_method ({
+    name => 'vmlist', 
+    path => '{node}', 
+    method => 'GET',
+    description => "Virtual machine index.",
+    parameters => {
+    	additionalProperties => 0,
+	properties => {
+	    node => get_standard_option('pve-node'),
+	},
+    },
+    returns => {
+	type => 'array',
+	items => {
+	    type => "object",
+	    properties => {},
+	},
+	links => [ { rel => 'child', href => "{vmid}" } ],
+    },
+    code => sub {
+	my ($param) = @_;
+
+	my $vmstatus =  PVE::QemuServer::vmstatus();
+
+	return PVE::RESTHandler::hash_to_array($vmstatus, 'vmid');
+
+    }});
+
+__PACKAGE__->register_method ({
+    name => 'vm_command', 
+    path => '{node}/{vmid}', 
+    method => 'PUT',
+    description => "Set virtual machine status.",
+    parameters => {
+    	additionalProperties => 0,
+	properties => {
+	    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', 
+		optional => 1,
+	    },
+	    command => { 
+		type => 'string',
+		enum => [qw(start stop reset shutdown cad suspend resume vncticket) ],
+	    },
+	    ticket => { 
+		description => "Secret VNC ticket (required by vncticket command).",
+		type => 'string',
+		optional => 1,
+		minLength => 8, # just to improve security
+		pattern => '[A-Za-z0-9\+\/\=]+', # base64 characters
+	    },
+	},
+    },
+    returns => { type => 'null'},
+    code => sub {
+	my ($param) = @_;
+
+	my $rpcenv = PVE::RPCEnvironment::get();
+
+	my $user = $rpcenv->get_user();
+
+	my $node = extract_param($param, 'node');
+
+	# fixme: proxy to correct node
+	# fixme: fork worker?
+
+	my $vmid = extract_param($param, 'vmid');
+
+	my $skiplock = extract_param($param, 'skiplock');
+	raise_param_exc({ skiplock => "Only root may use this option." }) 
+	    if $user ne 'root';
+
+	my $command = $param->{command};
+
+	my $storecfg = read_file('storagecfg');
+	
+	if ($command eq 'start') {
+	    my $statefile = undef; # fixme: --incoming parameter
+	    PVE::QemuServer::vm_start($storecfg, $vmid, $statefile, $skiplock);
+	} elsif ($command eq 'stop') {
+	    PVE::QemuServer::vm_stop($vmid, $skiplock);
+	} elsif ($command eq 'reset') {
+	    PVE::QemuServer::vm_reset($vmid, $skiplock);
+	} elsif ($command eq 'shutdown') {
+	    PVE::QemuServer::vm_shutdown($vmid, $skiplock);
+	} elsif ($command eq 'suspend') {
+	    PVE::QemuServer::vm_suspend($vmid, $skiplock);
+	} elsif ($command eq 'resume') {
+	    PVE::QemuServer::vm_resume($vmid, $skiplock);
+	} elsif ($command eq 'cad') {
+	    PVE::QemuServer::vm_cad($vmid, $skiplock);
+	} elsif ($command eq 'vncticket') {
+	    my $ticket = $param->{ticket};
+	    PVE::QemuServer::vm_monitor_command ($vmid, "change vnc ticket $ticket", 1);
+	} else {
+	    raise_param_exc({ command => "unknown command '$command'" }) 
+	}
+
+	return undef;
+    }});
+
+
+__PACKAGE__->register_method ({
+    name => 'vm_status', 
+    path => '{node}/{vmid}', 
+    method => 'GET',
+    description => "Get virtual machine status.",
+    parameters => {
+    	additionalProperties => 0,
+	properties => {
+	    node => get_standard_option('pve-node'),
+	    vmid => get_standard_option('pve-vmid'),
+	},
+    },
+    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;

Added: qemu-server/pve2/PVE/API2/Qemu/VNC.pm
===================================================================
--- qemu-server/pve2/PVE/API2/Qemu/VNC.pm	                        (rev 0)
+++ qemu-server/pve2/PVE/API2/Qemu/VNC.pm	2010-09-14 09:22:31 UTC (rev 5143)
@@ -0,0 +1,21 @@
+package PVE::API2::Qemu::VNC;
+
+use strict;
+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;
+use PVE::RPCEnvironment;
+
+use Data::Dumper; # fixme: remove
+
+
+use base qw(PVE::RESTHandler);
+
+
+1;

Deleted: qemu-server/pve2/PVE/API2/QemuServer.pm
===================================================================
--- qemu-server/pve2/PVE/API2/QemuServer.pm	2010-09-14 09:19:49 UTC (rev 5142)
+++ qemu-server/pve2/PVE/API2/QemuServer.pm	2010-09-14 09:22:31 UTC (rev 5143)
@@ -1,286 +0,0 @@
-package PVE::API2::QemuServer;
-
-use strict;
-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;
-use PVE::RPCEnvironment;
-
-use Data::Dumper; # fixme: remove
-
-# API URLs
-#
-## GET    /vms/
-## GET    /vms/index  status of all VMs (cluster wide)
-
-# GET    /vms/config/qm/{node}/  list of all Qemu VMs (per node)
-# POST   /vms/config/qm/{node}/  create VM
-# GET    /vms/config/qm/{node}/{vmid}  get VM config
-# PUT    /vms/config/qm/{node}/{vmid}  set VM config
-# DELETE /vms/config/qm/{node}/{vmid}  destroy VM
-
-# GET    /vms/status/qm  status of all Qemu VMs (cluster wide)
-# GET    /vms/status/qm/{node}/  status of all Qemu VMs (per node)
-# GET    /vms/status/qm/{node}/{vmid}  get VM status
-# PUT    /vms/status/qm/{node}/{vmid}  set VM status
-
-use base qw(PVE::RESTHandler);
-
-__PACKAGE__->register_method ({
-    name => 'vmlist', 
-    path => '{node}', 
-    method => 'GET',
-    description => "Virtual machine index.",
-    parameters => {
-    	additionalProperties => 0,
-	properties => {
-	    node => get_standard_option('pve-node'),
-	},
-    },
-    returns => {
-	type => 'array',
-	items => {
-	    type => "object",
-	    properties => {},
-	},
-	links => [ { rel => 'child', href => "{vmid}" } ],
-    },
-    code => sub {
-	my ($param) = @_;
-
-	my $vmstatus =  PVE::QemuServer::vmstatus();
-
-	return PVE::RESTHandler::hash_to_array($vmstatus, 'vmid');
-
-    }});
-
-__PACKAGE__->register_method ({
-    name => 'create_vm', 
-    path => '{node}', 
-    method => 'POST',
-    description => "Create new virtual machine.",
-    parameters => {
-    	additionalProperties => 0,
-	properties => PVE::QemuServer::json_config_properties(
-	    {
-		node => get_standard_option('pve-node'),
-		vmid => get_standard_option('pve-vmid'),
-	    }),
-    },
-    returns => { type => 'null'},
-    code => sub {
-	my ($param) = @_;
-
-	my $node = extract_param($param, 'node');
-
-	# fixme: proxy to correct node
-	# fixme: fork worker?
-
-	my $vmid = extract_param($param, 'vmid');
-
-	my $filename = PVE::QemuServer::config_file ($vmid);
-	# first test (befor locking)
-	die "unable to create vm $vmid: config file already exists\n" 
-	    if -f $filename;
-	
-
-	my $storecfg = read_file('storagecfg');
-
-	my $opts = PVE::QemuServer::parse_options_new($storecfg, $param->{vmid}, $param, 1);
-
-	PVE::QemuServer::add_random_macs ($opts);
-
-	#fixme: ? syslog ('info', "VM $vmid creating new virtual machine");
-	
-	my $vollist = [];
-
-	my $createfn = sub {
-
-	    # second test (after locking test is accurate)
-	    die "unable to create vm $vmid: config file already exists\n" 
-		if -f $filename;
-
-	    $vollist = PVE::QemuServer::create_disks ($storecfg, $vmid, $opts);
-
-	    # try to be smart about bootdisk
-	    my @disks = PVE::QemuServer::disknames();
-	    my $firstdisk;
-	    foreach my $ds (reverse @disks) {
-		next if !$opts->{$ds};
-		my $disk = PVE::QemuServer::parse_drive ($ds, $opts->{$ds});
-		next if PVE::QemuServer::drive_is_cdrom ($disk);
-		$firstdisk = $ds;
-	    }
-
-	    if (!$opts->{bootdisk} && $firstdisk) {
-		$opts->{bootdisk} = $firstdisk; 
-	    }
-
-	    PVE::QemuServer::create_conf_nolock($vmid, $opts);
-	};
-
-	eval { PVE::QemuServer::lock_config ($vmid, $createfn); };
-	my $err = $@;
-
-	if ($err) {
-	    # fixme ? syslog ('err', "VM $vmid create failed - $err");
-	    foreach my $volid (@$vollist) {
-		eval { PVE::Storage::vdisk_free ($storecfg, $volid); };
-		warn $@ if $@;
-	    }
-	    die "create failed - $err";
-	}
-
-	return undef;
-    }});
-
-__PACKAGE__->register_method ({
-    name => 'update_vm', 
-    path => '{node}/{vmid}', 
-    method => 'PUT',
-    description => "Set virtual machine options.",
-    parameters => {
-    	additionalProperties => 0,
-	properties => PVE::QemuServer::json_config_properties(
-	    {
-		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', 
-		    optional => 1,
-		},
-		delete => {
-		    type => 'string', format => 'pve-configid-list',
-		    description => "A list of settings you want to delete.",
-		    optional => 1,
-		},
-	    }),
-    },
-    returns => { type => 'null'},
-    code => sub {
-	my ($param) = @_;
-
-	my $rpcenv = PVE::RPCEnvironment::get();
-
-	my $user = $rpcenv->get_user();
-
-	my $node = extract_param($param, 'node');
-
-	# fixme: proxy to correct node
-	# fixme: fork worker?
-
-	my $vmid = extract_param($param, 'vmid');
-
-	my $skiplock = extract_param($param, 'skiplock');
-	raise_param_exc({ skiplock => "Only root may use this option." }) if $user ne 'root';
-
-	my $delete = extract_param($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);
-
-	my $updatefn =  sub {
-
-	    my $conf = PVE::QemuServer::load_config ($vmid);
-
-	    PVE::QemuServer::check_lock($conf) if !$skiplock;
-
-	    my $unset = {};
-
-	    foreach my $opt (PVE::Tools::split_list($delete)) {
-		if (!PVE::QemuServer::option_exists($opt)) {
-		    raise_param_exc({ delete => "unknown option '$opt'" });
-		} 
-		next if !defined ($conf->{$opt});
-		if (PVE::QemuServer::valid_drivename($opt)) {
-		    my $disk = $conf->{diskinfo}->{$opt};
-		    if ($disk && !PVE::QemuServer::drive_is_cdrom ($disk)) {
-			PVE::QemuServer::unlink_image($storecfg, $vmid, $disk->{file});
-		    }
-		}
-		$unset->{$opt} = 1;
-	    }
-
-	    PVE::QemuServer::add_random_macs ($opts);
-
-	    PVE::QemuServer::create_disks ($storecfg, $vmid, $opts);
-
-	    PVE::QemuServer::change_config_nolock  ($vmid, $opts, $unset, 1);
-	};
-
-	PVE::QemuServer::lock_config ($vmid, $updatefn);
-
-	return undef;
-    }});
-
-
-__PACKAGE__->register_method ({
-    name => 'vm_config', 
-    path => '{node}/{vmid}', 
-    method => 'GET',
-    description => "Get virtual machine configuration.",
-    parameters => {
-    	additionalProperties => 0,
-	properties => {
-	    node => get_standard_option('pve-node'),
-	    vmid => get_standard_option('pve-vmid'),
-	},
-    },
-    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;
-    }});
-
-__PACKAGE__->register_method ({
-    name => 'destroy_vm', 
-    path => '{node}/{vmid}', 
-    method => 'DELETE',
-    description => "Destroy the vm (also delete all used/owned volumes).",
-    parameters => {
-    	additionalProperties => 0,
-	properties => {
-	    node => get_standard_option('pve-node'),
-	    vmid => get_standard_option('pve-vmid'),
-	},
-    },
-    returns => { type => 'null' },
-    code => sub {
-	my ($param) = @_;
-
-	my $rpcenv = PVE::RPCEnvironment::get();
-
-	my $user = $rpcenv->get_user();
-
-	my $vmid = $param->{vmid};
-
-	my $skiplock = $param->{skiplock};
-	raise_param_exc({ skiplock => "Only root may use this option." }) 
-	    if $user ne 'root';
-
-	my $storecfg = read_file('storagecfg');
-
-	PVE::QemuServer::vm_destroy ($storecfg, $vmid, $skiplock);
-
-	return undef;
-    }});
-
-1;

Deleted: qemu-server/pve2/PVE/API2/QemuServerStatus.pm
===================================================================
--- qemu-server/pve2/PVE/API2/QemuServerStatus.pm	2010-09-14 09:19:49 UTC (rev 5142)
+++ qemu-server/pve2/PVE/API2/QemuServerStatus.pm	2010-09-14 09:22:31 UTC (rev 5143)
@@ -1,151 +0,0 @@
-package PVE::API2::QemuServerStatus;
-
-use strict;
-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;
-use PVE::RPCEnvironment;
-
-use Data::Dumper; # fixme: remove
-
-use base qw(PVE::RESTHandler);
-
-
-__PACKAGE__->register_method ({
-    name => 'vmlist', 
-    path => '{node}', 
-    method => 'GET',
-    description => "Virtual machine index.",
-    parameters => {
-    	additionalProperties => 0,
-	properties => {
-	    node => get_standard_option('pve-node'),
-	},
-    },
-    returns => {
-	type => 'array',
-	items => {
-	    type => "object",
-	    properties => {},
-	},
-	links => [ { rel => 'child', href => "{vmid}" } ],
-    },
-    code => sub {
-	my ($param) = @_;
-
-	my $vmstatus =  PVE::QemuServer::vmstatus();
-
-	return PVE::RESTHandler::hash_to_array($vmstatus, 'vmid');
-
-    }});
-
-__PACKAGE__->register_method ({
-    name => 'vm_command', 
-    path => '{node}/{vmid}', 
-    method => 'PUT',
-    description => "Set virtual machine status.",
-    parameters => {
-    	additionalProperties => 0,
-	properties => {
-	    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', 
-		optional => 1,
-	    },
-	    command => { 
-		type => 'string',
-		enum => [qw(start stop reset shutdown cad suspend resume vncticket) ],
-	    },
-	    ticket => { 
-		description => "Secret VNC ticket (required by vncticket command).",
-		type => 'string',
-		optional => 1,
-		minLength => 8, # just to improve security
-		pattern => '[A-Za-z0-9\+\/\=]+', # base64 characters
-	    },
-	},
-    },
-    returns => { type => 'null'},
-    code => sub {
-	my ($param) = @_;
-
-	my $rpcenv = PVE::RPCEnvironment::get();
-
-	my $user = $rpcenv->get_user();
-
-	my $node = extract_param($param, 'node');
-
-	# fixme: proxy to correct node
-	# fixme: fork worker?
-
-	my $vmid = extract_param($param, 'vmid');
-
-	my $skiplock = extract_param($param, 'skiplock');
-	raise_param_exc({ skiplock => "Only root may use this option." }) 
-	    if $user ne 'root';
-
-	my $command = $param->{command};
-
-	my $storecfg = read_file('storagecfg');
-	
-	if ($command eq 'start') {
-	    my $statefile = undef; # fixme: --incoming parameter
-	    PVE::QemuServer::vm_start($storecfg, $vmid, $statefile, $skiplock);
-	} elsif ($command eq 'stop') {
-	    PVE::QemuServer::vm_stop($vmid, $skiplock);
-	} elsif ($command eq 'reset') {
-	    PVE::QemuServer::vm_reset($vmid, $skiplock);
-	} elsif ($command eq 'shutdown') {
-	    PVE::QemuServer::vm_shutdown($vmid, $skiplock);
-	} elsif ($command eq 'suspend') {
-	    PVE::QemuServer::vm_suspend($vmid, $skiplock);
-	} elsif ($command eq 'resume') {
-	    PVE::QemuServer::vm_resume($vmid, $skiplock);
-	} elsif ($command eq 'cad') {
-	    PVE::QemuServer::vm_cad($vmid, $skiplock);
-	} elsif ($command eq 'vncticket') {
-	    my $ticket = $param->{ticket};
-	    PVE::QemuServer::vm_monitor_command ($vmid, "change vnc ticket $ticket", 1);
-	} else {
-	    raise_param_exc({ command => "unknown command '$command'" }) 
-	}
-
-	return undef;
-    }});
-
-
-__PACKAGE__->register_method ({
-    name => 'vm_status', 
-    path => '{node}/{vmid}', 
-    method => 'GET',
-    description => "Get virtual machine status.",
-    parameters => {
-    	additionalProperties => 0,
-	properties => {
-	    node => get_standard_option('pve-node'),
-	    vmid => get_standard_option('pve-vmid'),
-	},
-    },
-    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/nqm
===================================================================
--- qemu-server/pve2/nqm	2010-09-14 09:19:49 UTC (rev 5142)
+++ qemu-server/pve2/nqm	2010-09-14 09:22:31 UTC (rev 5143)
@@ -10,8 +10,8 @@
 use PVE::INotify qw(read_file);
 use PVE::RPCEnvironment;
 use PVE::QemuServer;
-use PVE::API2::QemuServer;
-use PVE::API2::QemuServerStatus;
+use PVE::API2::Qemu::Config;
+use PVE::API2::Qemu::Status;
 use PVE::JSONSchema qw(get_standard_option);
 use Term::ReadLine;
 
@@ -372,7 +372,7 @@
 # fixme: cdrom
 
 my $cmddef = {
-    list => [ "PVE::API2::QemuServer", 'vmlist', [],
+    list => [ "PVE::API2::Qemu::Config", 'vmlist', [],
 	     { node => $hostname }, sub {
 		 my $vmlist = shift;
 
@@ -389,13 +389,13 @@
 		 
 	      } ],
 
-    create => [ "PVE::API2::QemuServer", 'create_vm', ['vmid'], { node => $hostname } ],
+    create => [ "PVE::API2::Qemu::Config", 'create_vm', ['vmid'], { node => $hostname } ],
 
-    destroy => [ "PVE::API2::QemuServer", 'destroy_vm', ['vmid'], { node => $hostname } ],
+    destroy => [ "PVE::API2::Qemu::Config", 'destroy_vm', ['vmid'], { node => $hostname } ],
 
-    set => [ "PVE::API2::QemuServer", 'update_vm', ['vmid'], { node => $hostname } ],
+    set => [ "PVE::API2::Qemu::Config", 'update_vm', ['vmid'], { node => $hostname } ],
 
-    config => [ "PVE::API2::QemuServer", 'vm_config', ['vmid'], 
+    config => [ "PVE::API2::Qemu::Config", 'vm_config', ['vmid'], 
 		{ node => $hostname }, sub {
 		    my $config = shift;
 		    foreach my $k (sort (keys %$config)) {
@@ -425,24 +425,24 @@
     mtunnel => [ __PACKAGE__, 'mtunnel', []],
 
 
-    start => [ "PVE::API2::QemuServerStatus", 'vm_command', ['vmid'], 
+    start => [ "PVE::API2::Qemu::Status", 'vm_command', ['vmid'], 
 	       { node => $hostname, command => 'start' } ],
-    stop => [ "PVE::API2::QemuServerStatus", 'vm_command', ['vmid'], 
+    stop => [ "PVE::API2::Qemu::Status", 'vm_command', ['vmid'], 
 	      { node => $hostname, command => 'stop' } ],
-    reset => [ "PVE::API2::QemuServerStatus", 'vm_command', ['vmid'], 
+    reset => [ "PVE::API2::Qemu::Status", 'vm_command', ['vmid'], 
 	       { node => $hostname, command => 'reset' } ],
-    suspend => [ "PVE::API2::QemuServerStatus", 'vm_command', ['vmid'], 
+    suspend => [ "PVE::API2::Qemu::Status", 'vm_command', ['vmid'], 
 		 { node => $hostname, command => 'suspend' } ],
-    resume => [ "PVE::API2::QemuServerStatus", 'vm_command', ['vmid'], 
+    resume => [ "PVE::API2::Qemu::Status", 'vm_command', ['vmid'], 
 		{ node => $hostname, command => 'resume' } ],
-    cad => [ "PVE::API2::QemuServerStatus", 'vm_command', ['vmid'], 
+    cad => [ "PVE::API2::Qemu::Status", 'vm_command', ['vmid'], 
 	     { node => $hostname, command => 'cad' } ],
 	
 };
 
 my $cmd = shift;
 
-if ($cmd eq 'verifyapi') {
+if ($cmd && $cmd eq 'verifyapi') {
     PVE::RESTHandler::validate_method_schemas();
     exit 0;
 }




More information about the pve-devel mailing list