On 2/20/19 1:22 AM, Alexandre Derumier wrote:
> qm migrate_external <vmid> <targetremotenode_fqdn_or_ip> [--targetstorage 
> otherstorage]
>    [--net[n] [,firewall=<1|0>] [,link_down=<1|0>][,rate=<number>] 
> [,tag=<integer>] [,trunks=<vlanid[;vlanid...]>]]
> 
> and ssh private key must exist in
> /etc/pve/priv/external_migration/id_rsa_targetremotenode_fqdn_or_ip

looks reasonable as a starting point for this.

> ---
>  PVE/API2/Qemu.pm  | 90 
> +++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  PVE/CLI/qm.pm     |  2 ++
>  PVE/QemuServer.pm | 12 ++++++++
>  3 files changed, 104 insertions(+)
> 
> diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
> index 22f9f6a..1f57643 100644
> --- a/PVE/API2/Qemu.pm
> +++ b/PVE/API2/Qemu.pm
> @@ -21,6 +21,7 @@ use PVE::GuestHelpers;
>  use PVE::QemuConfig;
>  use PVE::QemuServer;
>  use PVE::QemuMigrate;
> +use PVE::QemuMigrateExternal;
>  use PVE::RPCEnvironment;
>  use PVE::AccessControl;
>  use PVE::INotify;
> @@ -3183,6 +3184,95 @@ __PACKAGE__->register_method({
>      }});
>  
>  __PACKAGE__->register_method({
> +    name => 'migrate_vm_external',
> +    path => '{vmid}/migrate_external',
> +    method => 'POST',
> +    protected => 1,
> +    proxyto => 'node',
> +    description => "Experimental! Use at your own risk. Migrate virtual 
> machine to an external cluster. Creates a new migration task.",
> +    permissions => {
> +     check => ['perm', '/vms/{vmid}', [ 'VM.Migrate' ]],
> +    },
> +    parameters => {
> +     additionalProperties => 0,
> +     properties => PVE::QemuServer::json_migrate_external_config_properties({
> +         node => get_standard_option('pve-node'),
> +         vmid => get_standard_option('pve-vmid', { completion => 
> \&PVE::QemuServer::complete_vmid }),
> +         target => {
> +             type => 'string',
> +             description => "Target node fqdn or ip address.",
> +            },
> +         targetstorage => get_standard_option('pve-storage-id', {
> +             description => "Target remote storage.",
> +             optional => 1,
> +         }),
> +         targetvmid => get_standard_option('pve-vmid', {
> +             description => "Target vmid. If not specified the next 
> available vmid will be used.",
> +             optional => 1,
> +         }),
> +         targetkey => {
> +             type => 'string',
> +             description => "Ssh private key file located in 
> /etc/pve/priv/migrate_external/.",
> +             optional => 1,
> +         },
> +     }),
> +    },
> +    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@pam';
> +
> +     my $target = extract_param($param, 'target');
> +
> +     my $vmid = extract_param($param, 'vmid');
> +
> +     my $targetkey = extract_param($param, 'targetkey');
> +
> +     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 $migration_external_sshkey = $targetkey ? 
> "/etc/pve/priv/migrate_external/$targetkey" : 
> "/etc/pve/priv/migrate_external/id_rsa_$target";
> +
> +     die "ssh privatekey is missing for $target" if !-e 
> $migration_external_sshkey;
> +
> +     my $targetip = PVE::Network::get_ip_from_hostname($target, 0);
> +
> +     # 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_sshkey} = $migration_external_sshkey;
> +
> +     my $realcmd = sub {
> +         PVE::QemuMigrateExternal->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 cea2549..5f38c66 100755
> --- a/PVE/CLI/qm.pm
> +++ b/PVE/CLI/qm.pm
> @@ -863,6 +863,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 } ],
> diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
> index 6dc68a4..0665a59 100644
> --- a/PVE/QemuServer.pm
> +++ b/PVE/QemuServer.pm
> @@ -2433,6 +2433,18 @@ sub json_config_properties {
>      return $prop;
>  }
>  
> +# add JSON properties for external migration (net override)
> +sub json_migrate_external_config_properties {
> +    my $prop = shift;
> +
> +    foreach my $opt (keys %$confdesc) {
> +     next if $opt !~ m/^net(\d+)$/;
> +     $prop->{$opt} = $confdesc->{$opt};
> +    }
> +
> +    return $prop;
> +}
> +
>  # return copy of $confdesc_cloudinit to generate documentation
>  sub cloudinit_config_properties {
>  
> 


_______________________________________________
pve-devel mailing list
[email protected]
https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to