virt-clone: add --skip-copy option

This is the flip side to the --force-copy option. We already
have the plumbing internally

https://bugzilla.redhat.com/show_bug.cgi?id=1564865
This commit is contained in:
Cole Robinson 2019-06-16 14:38:55 -04:00
parent 44cf01cee1
commit 4973564e65
3 changed files with 14 additions and 0 deletions

View File

@ -100,6 +100,13 @@ Force cloning the passed disk target ('hdc', 'sda', etc.). By default,
C<virt-clone> will skip certain disks, such as those marked 'readonly' or
'shareable'.
=item B<--skip-copy> TARGET
Skip cloning the passed disk target ('hdc', 'sda', etc.). By default,
C<virt-clone> will clone certain disk images, typically read/write
devices. Use this to skip copying of a specific device, so the new
VM uses the same storage path as the original VM.
=item B<--nonsparse>
Fully allocate the new storage if the path being cloned is a sparse file.

View File

@ -1273,6 +1273,7 @@ c.add_valid("-o test --auto-clone") # Auto flag, no storage
c.add_valid("-o test --file %(NEWCLONEIMG1)s --file %(NEWCLONEIMG2)s") # Nodisk, but with spurious files passed
c.add_valid("-o test --file %(NEWCLONEIMG1)s --file %(NEWCLONEIMG2)s --prompt") # Working scenario w/ prompt shouldn't ask anything
c.add_valid("--original-xml " + _CLONE_UNMANAGED + " --file %(NEWCLONEIMG1)s --file %(NEWCLONEIMG2)s") # XML File with 2 disks
c.add_valid("--original-xml " + _CLONE_UNMANAGED + " --file %(NEWCLONEIMG1)s --skip-copy=hda") # XML w/ disks, skipping one disk target
c.add_valid("--original-xml " + _CLONE_UNMANAGED + " --file virt-install --file %(EXISTIMG1)s --preserve") # XML w/ disks, overwriting existing files with --preserve
c.add_valid("--original-xml " + _CLONE_UNMANAGED + " --file %(NEWCLONEIMG1)s --file %(NEWCLONEIMG2)s --file %(NEWCLONEIMG3)s --force-copy=hdc") # XML w/ disks, force copy a readonly target
c.add_valid("--original-xml " + _CLONE_UNMANAGED + " --file %(NEWCLONEIMG1)s --file %(NEWCLONEIMG2)s --force-copy=fda") # XML w/ disks, force copy a target with no media

View File

@ -113,6 +113,10 @@ def parse_args():
stog.add_argument("--force-copy", dest="target", action="append",
help=_("Force to copy devices (eg, if 'hdc' is a "
"readonly cdrom device, --force-copy=hdc)"))
stog.add_argument("--skip-copy", action="append",
help=_("Skip copy of the device target. (eg, if 'vda' is a "
"disk you don't want to copy and use the same path "
"in the new VM, use --skip-copy=vda)"))
stog.add_argument("--nonsparse", action="store_false", dest="sparse",
default=True,
help=_("Do not use a sparse file for the clone's "
@ -176,6 +180,8 @@ def main(conn=None):
design.reflink = True
for i in options.target or []:
design.force_target = i
for i in options.skip_copy or []:
design.skip_target = i
design.clone_sparse = options.sparse
design.preserve = options.preserve