]> git.proxmox.com Git - qemu-server.git/blobdiff - PVE/API2/Qemu.pm
add scsi disk hotplug/unplug
[qemu-server.git] / PVE / API2 / Qemu.pm
index 9ce84d246b9661201c44609a3944cf27dbaea8f3..518a98244ca1a8596ae39014e7e4124a1b9c9af4 100644 (file)
@@ -533,7 +533,7 @@ __PACKAGE__->register_method({
                } 
                next if !defined($conf->{$opt});
                if (PVE::QemuServer::valid_drivename($opt)) {
-                   PVE::QemuServer::vm_devicedel($vmid, $conf, $opt);
+                   PVE::QemuServer::vm_deviceunplug($vmid, $conf, $opt);
                    my $drive = PVE::QemuServer::parse_drive($opt, $conf->{$opt});
                    if (PVE::QemuServer::drive_is_cdrom($drive)) {
                        $cdchange->{$opt} = undef;
@@ -701,11 +701,14 @@ __PACKAGE__->register_method({
        my $rpcenv = PVE::RPCEnvironment::get();
 
        my $user = $rpcenv->get_user();
-       my $ticket = PVE::AccessControl::assemble_ticket($user);
 
        my $vmid = $param->{vmid};
        my $node = $param->{node};
 
+       my $authpath = "/vms/$vmid";
+
+       my $ticket = PVE::AccessControl::assemble_vnc_ticket($user, $authpath);
+
        $sslcert = PVE::Tools::file_get_contents("/etc/pve/pve-root-ca.pem", 8192)
            if !$sslcert;
 
@@ -812,8 +815,16 @@ __PACKAGE__->register_method({
        my $conf = PVE::QemuServer::load_config($param->{vmid});
 
        my $vmstatus = PVE::QemuServer::vmstatus($param->{vmid});
+       my $status = $vmstatus->{$param->{vmid}};
+
+       my $cc = PVE::Cluster::cfs_read_file('cluster.conf');
+       if (PVE::Cluster::cluster_conf_lookup_pvevm($cc, 0, $param->{vmid}, 1)) {
+           $status->{ha} = 1;
+       } else {
+           $status->{ha} = 0;
+       }
 
-       return $vmstatus->{$param->{vmid}};
+       return $status;
     }});
 
 __PACKAGE__->register_method({
@@ -854,8 +865,6 @@ __PACKAGE__->register_method({
        raise_param_exc({ skiplock => "Only root may use this option." }) 
            if $skiplock && $user ne 'root@pam';
 
-       die "VM $vmid already running\n" if PVE::QemuServer::check_running($vmid);
-
        my $storecfg = PVE::Storage::config(); 
 
        my $realcmd = sub {
@@ -889,6 +898,12 @@ __PACKAGE__->register_method({
                type => 'integer',
                minimum => 0,
                optional => 1,
+           },
+           keepActive => {
+               description => "Do not decativate storage volumes.",
+               type => 'boolean',
+               optional => 1,
+               default => 0,
            }
        },
     },
@@ -910,7 +925,9 @@ __PACKAGE__->register_method({
        raise_param_exc({ skiplock => "Only root may use this option." }) 
            if $skiplock && $user ne 'root@pam';
 
-       die "VM $vmid not running\n" if !PVE::QemuServer::check_running($vmid);
+       my $keepActive = extract_param($param, 'keepActive');
+       raise_param_exc({ keepActive => "Only root may use this option." }) 
+           if $keepActive && $user ne 'root@pam';
 
        my $storecfg = PVE::Storage::config();
 
@@ -919,7 +936,8 @@ __PACKAGE__->register_method({
 
            syslog('info', "stop VM $vmid: $upid\n");
 
-           PVE::QemuServer::vm_stop($storecfg, $vmid, $skiplock, 0, $param->{timeout});
+           PVE::QemuServer::vm_stop($storecfg, $vmid, $skiplock, 0, 
+                                    $param->{timeout}, 0, 1, $keepActive);
 
            return;
        };
@@ -991,6 +1009,18 @@ __PACKAGE__->register_method({
                type => 'integer',
                minimum => 0,
                optional => 1,
+           },
+           forceStop => {
+               description => "Make sure the VM stops.",
+               type => 'boolean',
+               optional => 1,
+               default => 0,
+           },
+           keepActive => {
+               description => "Do not decativate storage volumes.",
+               type => 'boolean',
+               optional => 1,
+               default => 0,
            }
        },
     },
@@ -1012,14 +1042,19 @@ __PACKAGE__->register_method({
        raise_param_exc({ skiplock => "Only root may use this option." }) 
            if $skiplock && $user ne 'root@pam';
 
-       die "VM $vmid not running\n" if !PVE::QemuServer::check_running($vmid);
+       my $keepActive = extract_param($param, 'keepActive');
+       raise_param_exc({ keepActive => "Only root may use this option." }) 
+           if $keepActive && $user ne 'root@pam';
+
+       my $storecfg = PVE::Storage::config();
 
        my $realcmd = sub {
            my $upid = shift;
 
            syslog('info', "shutdown VM $vmid: $upid\n");
 
-           PVE::QemuServer::vm_shutdown($vmid, $skiplock, $param->{timeout});
+           PVE::QemuServer::vm_stop($storecfg, $vmid, $skiplock, 0, $param->{timeout}, 
+                                    1, $param->{forceStop}, $keepActive);
 
            return;
        };
@@ -1230,7 +1265,7 @@ __PACKAGE__->register_method({
        my $realcmd = sub {
            my $upid = shift;
 
-           PVE::QemuMigrate::migrate($target, $targetip, $vmid, $param->{online}, $param->{force});
+           PVE::QemuMigrate->migrate($target, $targetip, $vmid, $param);
        };
 
        my $upid = $rpcenv->fork_worker('qmigrate', $vmid, $user, $realcmd);