[pve-devel] [PATCH v3 qemu-server 1/7] api2 : add migrate_vm_external
David Limbeck
d.limbeck at proxmox.com
Wed Dec 19 11:36:41 CET 2018
On 11/27/18 4:38 PM, Alexandre Derumier wrote:
> qm migrate_external <vmid> <targetremotenode> [--targetstorage otherstorage] [--targetbridge otherbridge]
> ---
> PVE/API2/Qemu.pm | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> PVE/CLI/qm.pm | 2 ++
> 2 files changed, 81 insertions(+)
>
> diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
> index c82e2fa..b23db56 100644
> --- a/PVE/API2/Qemu.pm
> +++ b/PVE/API2/Qemu.pm
> @@ -3162,6 +3162,85 @@ __PACKAGE__->register_method({
> }});
>
> __PACKAGE__->register_method({
> + name => 'migrate_vm_external',
> + path => '{vmid}/migrate_external',
> + method => 'POST',
> + protected => 1,
> + proxyto => 'node',
> + description => "Migrate virtual machine to an external cluster. Creates a new migration task.",
> + permissions => {
> + check => ['perm', '/vms/{vmid}', [ 'VM.Migrate' ]],
> + },
> + parameters => {
> + additionalProperties => 0,
> + properties => {
> + node => get_standard_option('pve-node'),
> + vmid => get_standard_option('pve-vmid', { completion => \&PVE::QemuServer::complete_vmid }),
> + target => get_standard_option('pve-node', {
> + description => "Target node.",
> + }),
> + targetstorage => get_standard_option('pve-storage-id', {
> + description => "Target remote storage.",
> + optional => 1,
> + }),
> + targetbridge => {
> + type => 'string',
> + description => "Target remote bridge.",
> + format_description => 'bridge',
> + optional => 1,
> + },
optional targetvmid with the current fallback of /cluster/nextid if not
specified would be a great addition.
an override for the private key name might be nice to have as well, e.g.
--targetkey 'external.cluster2' which uses
/etc/pve/priv/migrate_external/external.cluster2 with the fallback to
the current /etc/pve/priv/migrate_external/id_rsa_external.cluster2
What do you think?
> + },
> + },
> + returns => {
> + type => 'string',
> + description => "the task ID.",
> + },
> + code => sub {
> + my ($param) = @_;
> +
> + my $rpcenv = PVE::RPCEnvironment::get();
> +
> + my $authuser = $rpcenv->get_user();
> +
> + die "Only root can do external migration." if $authuser ne 'root at pam';
> +
> + my $target = extract_param($param, 'target');
> +
> + my $vmid = extract_param($param, 'vmid');
> +
> + PVE::Cluster::check_cfs_quorum();
> +
> + raise_param_exc({ target => "target is member of local cluster."}) if PVE::Cluster::check_node_exists($target, 1);
> +
> + die "HA must be disable for external migration." if PVE::HA::Config::vm_is_ha_managed($vmid);
> +
> + my $targetip = PVE::Network::get_ip_from_hostname($target, 1);
> +
> + # test if VM exists
> + my $conf = PVE::QemuConfig->load_config($vmid);
> +
> + # try to detect errors early
> +
> + PVE::QemuConfig->check_lock($conf);
> +
> + die "VM need to be online for external migration" if !PVE::QemuServer::check_running($vmid);
> +
> + $param->{online} = 1;
> + $param->{migration_external} = 1;
> +
> + my $realcmd = sub {
> + PVE::QemuMigrate->migrate($target, $targetip, $vmid, $param);
> + };
> +
> + my $worker = sub {
> + return PVE::GuestHelpers::guest_migration_lock($vmid, 10, $realcmd);
> + };
> +
> + return $rpcenv->fork_worker('qmigrate', $vmid, $authuser, $worker);
> +
> + }});
> +
> +__PACKAGE__->register_method({
> name => 'monitor',
> path => '{vmid}/monitor',
> method => 'POST',
> diff --git a/PVE/CLI/qm.pm b/PVE/CLI/qm.pm
> index eceb9b3..5aa1d48 100755
> --- a/PVE/CLI/qm.pm
> +++ b/PVE/CLI/qm.pm
> @@ -850,6 +850,8 @@ our $cmddef = {
>
> migrate => [ "PVE::API2::Qemu", 'migrate_vm', ['vmid', 'target'], { node => $nodename }, $upid_exit ],
>
> + migrate_external => [ "PVE::API2::Qemu", 'migrate_vm_external', ['vmid', 'target'], { node => $nodename }, $upid_exit ],
> +
> set => [ "PVE::API2::Qemu", 'update_vm', ['vmid'], { node => $nodename } ],
>
> resize => [ "PVE::API2::Qemu", 'resize_vm', ['vmid', 'disk', 'size'], { node => $nodename } ],
More information about the pve-devel
mailing list