[pve-devel] ceph: clone vm

Alexandre DERUMIER aderumier at odiso.com
Thu Feb 6 09:17:05 CET 2014


#qm clone ID NEWID -snapname ABC ? 

options are in /usr/share/perl5/PVE/API2/Qemu.pm

>>            snapname => get_standard_option('pve-snapshot-name', {
>>                requires => 'full',
>>                optional => 1,
>>            }),

(We should remove requires=>'full', and maybe add some checks to avoid cloning of snapshot of qcow2 files, which don't work)




    path => '{vmid}/clone',
    method => 'POST',
    protected => 1,
    proxyto => 'node',
    description => "Create a copy of virtual machine/template.",
    permissions => {
        description => "You need 'VM.Clone' permissions on /vms/{vmid}, and 'VM.Allocate' permissions " .
            "on /vms/{newid} (or on the VM pool /pool/{pool}). You also need " .
            "'Datastore.AllocateSpace' on any used storage.",
        check =>
        [ 'and',
          ['perm', '/vms/{vmid}', [ 'VM.Clone' ]],
          [ 'or',
            [ 'perm', '/vms/{newid}', ['VM.Allocate']],
            [ 'perm', '/pool/{pool}', ['VM.Allocate'], require_param => 'pool'],
          ],
        ]
    },
    parameters => {
        additionalProperties => 0,
        properties => {
            node => get_standard_option('pve-node'),
            vmid => get_standard_option('pve-vmid'),
            newid => get_standard_option('pve-vmid', { description => 'VMID for the clone.' }),
            name => {
                optional => 1,
                type => 'string', format => 'dns-name',
                description => "Set a name for the new VM.",
            },
            description => {
                optional => 1,
                type => 'string',
                description => "Description for the new VM.",
            },
            pool => {
                optional => 1,
                type => 'string', format => 'pve-poolid',
                description => "Add the new VM to the specified pool.",
            },
            snapname => get_standard_option('pve-snapshot-name', {
                requires => 'full',
                optional => 1,
            }),
            storage => get_standard_option('pve-storage-id', {
                description => "Target storage for full clone.",
                requires => 'full',
                optional => 1,
            }),
            'format' => {
                description => "Target format for file storage.",
                requires => 'full',
                type => 'string',
                optional => 1,
                enum => [ 'raw', 'qcow2', 'vmdk'],
            },
            full => {
                optional => 1,
                type => 'boolean',
                description => "Create a full copy of all disk. This is always done when " .
                    "you clone a normal VM. For VM templates, we try to create a linked clone by default.",
                default => 0,
            },
            target => get_standard_option('pve-node', {
                description => "Target node. Only allowed if the original VM is on shared storage.",
                optional => 1,
            }),
        },
    },
----- Mail original ----- 

De: "Stefan Priebe - Profihost AG" <s.priebe at profihost.ag> 
À: "Alexandre DERUMIER" <aderumier at odiso.com> 
Cc: pve-devel at pve.proxmox.com, "Michael Rasmussen" <mir at datanom.net> 
Envoyé: Jeudi 6 Février 2014 08:25:47 
Objet: Re: [pve-devel] ceph: clone vm 

I'll test and send patches - can you tell me how to provice the snapshot? 

qm clone ID NEWID -snap ABC ? 

i'm still not sure how to get the available options. 

Stefan 

Am 06.02.2014 06:20, schrieb Alexandre DERUMIER: 
>>> it adds snapshot support but not linked clones? or do i miss something. 
> 
> this add support to clone from a snapshot from a vm. (at not the default __base__ snapshot, from base-xxx templates ). 
> 
> I don't have tested it, but this is almost all we need. (maybe some checks to add in qemuserver.pm, but nothing too big) 
> ----- Mail original ----- 
> 
> De: "Stefan Priebe" <s.priebe at profihost.ag> 
> À: "Alexandre DERUMIER" <aderumier at odiso.com>, "Michael Rasmussen" <mir at datanom.net> 
> Cc: pve-devel at pve.proxmox.com 
> Envoyé: Mercredi 5 Février 2014 20:50:34 
> Objet: Re: [pve-devel] ceph: clone vm 
> 
> it adds snapshot support but not linked clones? or do i miss something. 
> 
> Stefan 
> 
> Am 05.02.2014 16:06, schrieb Alexandre DERUMIER: 
>>>> Cloning from snapshot is also an opportunity with ZFS. 
>> 
>> yes, sure, for any storage which support snasphot. 
>> 
>> It's not a big work, as we have already almost all subroutines in storage plugins 
>> 
>> 
>> 
>> something like this should work (don't have tested it ;) 
>> 
>> 
>> qemuserver.pm 
>> -------------- 
>>>> sub clone_disk { 
>>>> my ($storecfg, $vmid, $running, $drivename, $drive, $snapname, 
>>>> $newvmid, $storage, $format, $full, $newvollist) = @_; 
>>>> 
>>>> my $newvolid; 
>>>> 
>>>> if (!$full) { 
>>>> print "create linked clone of drive $drivename ($drive->{file})\n"; 
>>>> $newvolid = PVE::Storage::vdisk_clone($storecfg, $drive->{file}, $newvmid); 
>> 
>> sub clone_disk { 
>> my ($storecfg, $vmid, $running, $drivename, $drive, $snapname, 
>> $newvmid, $storage, $format, $full, $newvollist) = @_; 
>> 
>> my $newvolid; 
>> 
>> if (!$full) { 
>> print "create linked clone of drive $drivename ($drive->{file})\n"; 
>> $newvolid = PVE::Storage::vdisk_clone($storecfg, $drive->{file}, $newvmid, $snapname); 
>> 
>> 
>> storage.pm 
>> ---------- 
>>>> sub vdisk_clone { 
>>>> my ($cfg, $volid, $vmid) = @_; 
>>>> 
>>>> my ($storeid, $volname) = parse_volume_id($volid); 
>>>> 
>>>> my $scfg = storage_config($cfg, $storeid); 
>>>> 
>>>> my $plugin = PVE::Storage::Plugin->lookup($scfg->{type}); 
>>>> 
>>>> activate_storage($cfg, $storeid); 
>>>> 
>>>> # lock shared storage 
>>>> return $plugin->cluster_lock_storage($storeid, $scfg->{shared}, undef, sub { 
>>>> my $volname = $plugin->clone_image($scfg, $storeid, $volname, $vmid); 
>>>> return "$storeid:$volname"; 
>>>> }); 
>>>> } 
>> 
>> 
>> sub vdisk_clone { 
>> my ($cfg, $volid, $vmid, $snap) = @_; 
>> 
>> my ($storeid, $volname) = parse_volume_id($volid); 
>> 
>> my $scfg = storage_config($cfg, $storeid); 
>> 
>> my $plugin = PVE::Storage::Plugin->lookup($scfg->{type}); 
>> 
>> activate_storage($cfg, $storeid); 
>> 
>> # lock shared storage 
>> return $plugin->cluster_lock_storage($storeid, $scfg->{shared}, undef, sub { 
>> my $volname = $plugin->clone_image($scfg, $storeid, $volname, $vmid, $snap); 
>> return "$storeid:$volname"; 
>> }); 
>> } 
>> 
>> 
>> storage plugin 
>> -------------- 
>>>> sub clone_image { 
>>>> my ($class, $scfg, $storeid, $volname, $vmid) = @_; 
>>>> 
>>>> my $snap = '__base__'; 
>>>> 
>>>> my ($vtype, $basename, $basevmid, undef, undef, $isBase) = 
>>>> $class->parse_volname($volname); 
>>>> 
>>>> die "clone_image onyl works on base images\n" if !$isBase; 
>>>> 
>>>> my $name = &$find_free_diskname($storeid, $scfg, $vmid); 
>>>> 
>>>> warn "clone $volname: $basename to $name\n"; 
>>>> 
>>>> my $newvol = "$basename/$name"; 
>>>> 
>>>> my $cmd = &$rbd_cmd($scfg, $storeid, 'clone', &$add_pool_to_disk($scfg, $basename), '--snap', $snap, &$add_pool_to_disk($scfg, $name)); 
>>>> run_command($cmd, errmsg => "rbd clone $basename' error"); 
>>>> 
>>>> return $newvol; 
>>>> } 
>> 
>> sub clone_image { 
>> my ($class, $scfg, $storeid, $volname, $vmid, $snapshot) = @_; 
>> 
>> my $snap = '__base__'; 
>> $snap = $snapshot if $snapshot; 
>> 
>> my ($vtype, $basename, $basevmid, undef, undef, $isBase) = 
>> $class->parse_volname($volname); 
>> 
>> die "clone_image onyl works on base images\n" if !$isBase && !$snapshot; 
>> 
>> my $name = &$find_free_diskname($storeid, $scfg, $vmid); 
>> 
>> warn "clone $volname: $basename to $name\n"; 
>> 
>> my $newvol = "$basename/$name"; # Maybe find a way to reference snasphot like "$basename@$snasphot/$name" 
>> 
>> my $cmd = &$rbd_cmd($scfg, $storeid, 'clone', &$add_pool_to_disk($scfg, $basename), '--snap', $snap, &$add_pool_to_disk($scfg, $name)); 
>> run_command($cmd, errmsg => "rbd clone $basename' error"); 
>> 
>> return $newvol; 
>> } 
>> 
>> 
>> 
>> ----- Mail original ----- 
>> 
>> De: "Michael Rasmussen" <mir at datanom.net> 
>> À: pve-devel at pve.proxmox.com 
>> Envoyé: Mercredi 5 Février 2014 15:39:23 
>> Objet: Re: [pve-devel] ceph: clone vm 
>> 
>> On 02-05-2014 14:50, Alexandre DERUMIER wrote: 
>>> 
>>> Maybe could we introduce this feature (for ceph,sheepdog,..), cloning 
>>> from a snapshot. 
>>> 
>> Cloning from snapshot is also an opportunity with ZFS. 
>> 



More information about the pve-devel mailing list