5
0
mirror of git://git.proxmox.com/git/qemu-server.git synced 2025-01-25 06:03:52 +03:00

75 Commits

Author SHA1 Message Date
Thomas Lamprecht
aa6ebf6a4b qm nbdstop: cope graceful with errors
as the nbd server could have been stopped by something else.
Further, it makes no sense to die and mark the migration thus as
failed, just because of a NBD server stop issue.

At this point the migration hand off to the target was done already,
so normally we're good, if it fails we have other (followup) problems
anyway.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2020-04-29 16:22:33 +02:00
Fabian Ebner
e0fd2b2f84 Create Drive.pm and move drive-related code there
The initialization for the drive keys in $confdesc is changed
to be a single for-loop iterating over the keys of $drivedesc_hash and
the initialization of the unusedN keys is move to directly below it.

To avoid the need to change all the call sites, functions with more than
a few callers are exported from the submodule and imported into QemuServer.pm.

For callers of the now imported functions within QemuServer.pm, the prefix
PVE::QemuServer is dropped, because it is unnecessary and now even confusing.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
2020-03-07 18:23:57 +01:00
Thomas Lamprecht
109a095068 QGA exec: note limits explicit in CLI and API
The http-server has a 64KB payload limit for post requests, so note
that explicit even if it's a theoretical maximum as the reamainig
params also need some space in the request

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2020-03-06 17:57:46 +01:00
Stefan Reiter
d8f61794f6 fix #2612: allow input-data in guest exec and make command optional
'input-data' can be used to pass arbitrary data to a guest when running
an agent command with 'guest-exec'. Most guest-agent implementations
treat this as STDIN to the command given by "path"/"arg", but some go as
far as relying solely on this parameter, and even fail if "path" or
"arg" are set (e.g. Mikrotik Cloud Hosted Router) - thus "command" needs
to be made optional.

Via the API, an arbitrary string can be passed, on the command line ('qm
guest exec'), an additional '--pass-stdin' flag allows to forward STDIN
of the qm process to 'input-data', with a size limitation of 1 MiB to
not overwhelm QMP.

Without 'input-data' (API) or '--pass-stdin' (CLI) behaviour is unchanged.

Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
2020-03-03 14:34:02 +01:00
Stefan Reiter
0a13e08ec2 refactor: create QemuServer::Monitor for high-level QMP access
QMP and monitor helpers are moved from QemuServer.pm.

By using only vm_running_locally instead of check_running, a cyclic
dependency to QemuConfig is avoided. This also means that the $nocheck
parameter serves no more purpose, and has thus been removed along with
vm_mon_cmd_nocheck.

Care has been taken to avoid errors resulting from this, and
occasionally a manual check for a VM's existance inserted on the
callsite.

Methods have been renamed to avoid redundant naming:
* vm_qmp_command -> qmp_cmd
* vm_mon_cmd -> mon_cmd
* vm_human_monitor_command -> hmp_cmd

mon_cmd is exported since it has many users. This patch also changes all
non-package users of vm_qmp_command to use the mon_cmd helper. Includes
mocking for tests.

Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
2019-11-20 16:29:23 +01:00
Stefan Reiter
d036e418a8 refactor: create QemuServer::Helpers and move file/dir code
Also remove unused $confdir variable in QemuConfig, but leave it and
$lock_dir there, since those paths should only be used with
cfs_config_path anyway.

nodename() is still called in multiple places, but since it's cached by
INotify it doesn't really matter.

Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
2019-11-20 16:29:23 +01:00
Thomas Lamprecht
b04ea58453 destroy_vm: allow to pass new config and lock instead
This brings qemu more in line with containers, and it's nicer to
allow passing the replacement config if we want to keep it, instead
of setting a "memory: 128" config.

Use that to lock it on removal before final deletion, and on legacy
tar archive restore, in between old VM destruction and new
restoration.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2019-11-08 17:03:30 +01:00
Thomas Lamprecht
73a4470a8f followup: nit-pick code cleanup
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2019-10-29 19:11:21 +01:00
Thomas Lamprecht
c75bf16117 qm importdisk: tell user to what VM disk we actually imported
as else one has no idea what the imported disk is, especially if
multiple unused disks are already present..

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2019-10-29 19:11:21 +01:00
Thomas Lamprecht
5600c5b22f cleanup do_import, s/optional/params/ and move skiplock into params
mixed with indentation changes a whole lot of other changes which
should normally not mixed to much together, but this is all a bit
tangled and I'm not sure if splitting it into two or three parts
would help anybody.. just use "-w" (ignore whitespace changes) when
looking at the diff..

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2019-10-29 19:11:21 +01:00
Dominic Jäger
439390e868 Import OVF: Lock config with "lock" property
Previously a VMID conflict was possible when creating a VM on another node
between locking the config with lock_config_full and writing to it for the
first time with write_config.

Using create_and_lock_config eliminates this possibility. This means that now
the "lock" property is set in the config instead of using flock only.

$param was empty when it was assigned the three values "name", "memory" and
"cores" before being assigned to $conf later on. Assigning those values
directly to $conf avoids confusion about what the two variables contain.

Signed-off-by: Dominic Jäger <d.jaeger@proxmox.com>
2019-10-29 19:11:21 +01:00
Dominic Jäger
7f384190de Add skiplock to do_import
Functions like qm importovf can now set the "lock" property in a config file
before calling do_import.

Signed-off-by: Dominic Jäger <d.jaeger@proxmox.com>
2019-10-29 19:11:21 +01:00
Dominic Jäger
b406ab6342 replace remaining vm_destroy call-sites with destroy_vm
This function has been used in one place only into which we inlined its
functionality. Removing it avoids confusion between vm_destroy and vm_destroy.

The whole $importfn is executed in a lock_config_full.
As a consequence, for the inlined code:
1. lock_config is redundant
2. it is not possible that the VM has been started (check_running) in the
    meanwhile
Additionally, it is not possible that the "lock" property has been written into
the VM's config file (check_lock) in the meanwhile

Add warning after eval so that it does not go unnoticed if it ever comes into
action.

Signed-off-by: Dominic Jäger <d.jaeger@proxmox.com>
2019-10-29 19:11:02 +01:00
Thomas Lamprecht
7c2d9b4089 [no-change] sort and group module use
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2019-10-29 15:59:10 +01:00
Oguz Bektas
5c39708eb3 cli: use guesthelper for pending
use the shared format_pending method from guesthelpers

Signed-off-by: Oguz Bektas <o.bektas@proxmox.com>
2019-10-18 18:45:27 +02:00
Oguz Bektas
90ec74eac1 use print_snapshot_tree guest helper for qm listsnapshot
moved code to GuestHelpers for feature parity with pct

Signed-off-by: Oguz Bektas <o.bektas@proxmox.com>
2019-10-18 11:30:41 +02:00
Aaron Lauterer
a022e3fdab tree-wide trailing whitespace cleanup
Signed-off-by: Aaron Lauterer <a.lauterer@proxmox.com>
2019-09-25 16:55:53 +02:00
Dominik Csapak
165411f0c2 api: add reboot api call
this creates a reboot request file (inspired by pve-container)
and relies on the 'qm cleanup' call by the qmeventd to detect
and restart the vm afterwards

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
2019-09-11 14:13:35 +02:00
Dominik Csapak
64457ed4aa qm: cleanup: detect and handle reboot trigger
if the reboot trigger file was set, start the vm again
also cleanup the reboot trigger on vm startup, to prevent
leftover files to trigger a reboot at the next shutdown

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
2019-09-11 14:13:35 +02:00
Mira Limbeck
1e1763e9c8 add qm command for cloudinit config dump
Adds the command 'qm cloudinit dump <vmid> <type>' where type is either
'user', 'network' or 'meta' as specified in the API.

Signed-off-by: Mira Limbeck <m.limbeck@proxmox.com>
2019-06-06 14:34:11 +02:00
Thomas Lamprecht
dc62a7fafc drop vnc x509 param, deprecated in 2.5 removed in 4.0
while we have 3.0.1 for now, 4.x will come sooner or later so do this
now already..

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2019-06-06 09:52:44 +02:00
Rhonda D'Vine
3e494a3ca7 Fix #1999: cli: listsnapshot: handle multiple roots and mark orphaned as root
This commit addresses the following things:

* There can be multiple independent snapshot tree roots, display them
  all
* If a snapshot defines a parent that doesn't exist, it is now
  considered a snapshot root

There is a potential issue (which was also before and also affects the
GUI): circular snapshot trees.  That plays into the second mentioned
issue above.  If you manage to have a snapshot that defines a
non-existing root in the config, and then create a snapshot with that
exact name as a child of that snapshot, it would create a circular
dependency.  This would have to get addressed in the GUI too.

Signed-off-by: Rhonda D'Vine <rhonda@proxmox.com>
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2019-06-05 19:22:30 +02:00
Thomas Lamprecht
9e05909534 fixup: correct initial prefix
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2019-05-13 06:05:51 +00:00
Thomas Lamprecht
e85263a20e minor followup cleanups
remove now out of date commen about 'our', left over from previous
revision

Pass firs $prefix directly to function and some other small stuff

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2019-05-13 05:50:37 +00:00
Rhonda D'Vine
5f1dc9af73 fix #1999: create a tree view for qm listsnapshot
The look of the tree is based on the GUI variant, so that we have a
consistent output when run multiple times, too.

Signed-off-by: Rhonda D'Vine <rhonda@proxmox.com>
2019-05-13 05:38:36 +00:00
Dominik Csapak
9e784b1154 add pre- start/stop hookscripts to VMs
this adds a new config option for it, and executes it on four
points in time:

'pre-start'
'post-start'
'pre-stop'
'post-stop'

on pre-start we abort if the script fails
and pre-stop will not be called if the vm crashes or if
the vm gets powered off from inside the guest

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
2019-02-01 12:58:37 +01:00
Rhonda D'Vine
b14477e718 Fix #1924: add snapshot parameter
The qm CLI command offer the config and showcmd functions. Both of those
outputs may vary with respect to a given snapshot. This adds a switch
that shows the corresponding snapshot's config and command line.

The code needs a newer libpve-guest-common-perl, thus bumping the
dependency.

Signed-off-by: Rhonda D'Vine <rhonda@proxmox.com>
2019-01-30 14:56:43 +01:00
Dominik Csapak
0f56fff292 better cleanup logging for migration
if we migrate a vm we call cleanup but the logging looks like:

Starting cleanup for 101
trying to acquire lock...
 OK
Configuration file 'nodes/pve-ceph-01/qemu-server/101.conf' does not exist

with this patch, we omit any logging in the case we do not have the config,
since we cannot know what to clean up

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
2018-11-28 11:04:46 +01:00
Dominik Csapak
3ea84aeb7c add 'qm cleanup'
this is intended to be used with qmeventd, to do
the necessary cleanups when qemu crashes or is being
shut down from within the guest

this can also be the point where we could introduce
shutdown/stop/reboot hooks

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
2018-11-14 15:29:59 +01:00
Dominik Csapak
6ee499fff8 fix #1908: add vmgenid config/device
this adds a VM Generation ID device uses by Windows (Server) to determine
some specific actions that may have happened with the vm
such as rollback, restore, etc.

see:

https://docs.microsoft.com/en-us/windows/desktop/hyperv_v2/virtual-machine-generation-identifier

for details on how it works and when it should change

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
2018-09-19 12:23:24 +02:00
Thomas Lamprecht
dc02254ec9 qm rescan: fix typo in dryrun description
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2018-08-21 09:21:41 +02:00
Thomas Lamprecht
bf744e94f3 qm: move 'agent' command into 'guest' comand group
with a backwards compatible alias

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2018-07-17 11:01:55 +02:00
Thomas Lamprecht
34e4c0aa6c qm: rename 'ga' command group to 'guest'
https://pve.proxmox.com/pipermail/pve-devel/2018-July/033010.html

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2018-07-17 11:01:55 +02:00
Dominik Csapak
520884deca add exec(-status) to qm
on the commandline the implementation for exec is a bit different
because there we want (by default) to wait for the result,
as opposed to the api, where it is enough to return the pid and
let the client handle the polling

this behaviour is optional and can be turned off, as well as the
timeout of 30 seconds

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
2018-07-11 10:29:45 +02:00
Dominik Csapak
8593cbe41c add 'passwd' to qm
this adds a command 'qm ga passwd' so that we can reuse
'qm ga' for future guest agent calls

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
2018-07-11 10:29:45 +02:00
Thomas Lamprecht
9224dceefe qm rescan: add dryrun option
tells an user what would get touched, so he has a chance to fix
unwanted things before changes are actually made.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2018-07-11 09:35:45 +02:00
Thomas Lamprecht
6982113858 qm: PVE::PTY is not used anymore 2018-06-27 13:58:42 +02:00
Dominik Csapak
3dba118c89 use get_standard_mapping for cipassword_map
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
2018-06-27 13:39:53 +02:00
Thomas Lamprecht
eb84566b49 sync bwlimit description with the container one 2018-03-21 11:15:35 +01:00
Wolfgang Bumiller
7c536e11c4 restore: implement rate limiting
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2018-03-21 11:15:35 +01:00
Wolfgang Bumiller
29d1f14708 cloud-init: make cipassword interactive on the CLI
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2018-03-13 11:32:52 +01:00
Wolfgang Bumiller
3351aacc70 cloud-init: sshkeys are now files on the CLI
This requires a pve-common patch since we need to not only
load the file but also url-encode it.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2018-03-07 09:11:31 +01:00
Dominik Csapak
b8158701aa move guest agent api call to its own file
so we do not pollute the Qemu.pm too much

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
2018-02-20 09:55:15 +01:00
Thomas Lamprecht
e5caa02e05 avoid harmful '<>' pattern, explicitly read from STDIN
Fixes problems in CLIHandler using the code pattern:

while (my $line = <>) {
    ...
}

For why this causes only _now_ problems lets first look how <>
behaves:

"The null filehandle <> is special: [...] Input from <> comes either
from standard input, or from each file listed on the command line.
Here's how it works: the first time <> is evaluated, the @ARGV array
is checked, and if it is empty, $ARGV[0] is set to "-" , which when
opened gives you standard input.  The @ARGV array is then processed
as a list of filenames." - 'perldoc perlop'

Recent changes in the CLIHandler code changed how we modfiied @ARGV
Earlier we assumed that the first argument must be the command and
thus shifted it out of @ARGV, now we can have multiple levels of
(sub)commands. This change also changed how we handle @ARGV, we do
not unshift anything but go through the arguments until we got to
the final command and copy the rest of @ARGV as we know that this
must be the commandos arguments.

For '<>' this means that ARGV was still fully populated and perl
tried to open element as a file, which naturally failed.
Thus the change in pve-common only exposed this 'dangerous' code
pattern.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2018-01-22 14:56:27 +01:00
Wolfgang Bumiller
108899b48f qm showcmd --pretty: indent new lines by 2 spaces
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2018-01-10 15:48:59 +01:00
Thomas Lamprecht
16a01738cb qm showcmd: add simple 'pretty' parameter
Shows each parameter value pair in a new line with a backslash at the
end, so it's still possible to copy, paste and execute it, while
being easier to read and edit by humans. This is opt in.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2018-01-10 15:47:05 +01:00
Wolfgang Bumiller
aa320bcd16 qm terminal: add --escape option
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Reviewed-by: Dominik Csapak <d.csapak@proxmox.com>
2017-12-13 14:52:28 +01:00
Emmanuel Kasper
5d942f5aff importovf: explicitly returns undef
We set the returns value to  { type => 'null' } but we returned an empty
string, which was confusing the cli handler.
2017-09-27 14:54:56 +02:00
Wolfgang Bumiller
0f80f1ab6d qm importovf: --dryrun: use json output format 2017-09-25 13:51:53 +02:00
Wolfgang Bumiller
b533b99534 qm importovf: set return type to null 2017-09-25 13:51:53 +02:00