56
57
return False, [val]
58
def generate_clone_disk_path(origpath, design):
59
def generate_clone_disk_path(origpath, design, newname=None):
60
origname = design.original_guest
61
newname = newname or design.clone_name
62
65
# Try to split the suffix off the existing disk name. Ex.
65
68
# If the suffix is greater than 7 characters, assume it isn't
66
69
# a file extension and is part of the disk name, at which point
67
70
# just stick '-clone' on the end.
68
if basename.count(".") and len(basename.rsplit(".", 1)[1]) <= 7:
69
basename, suffix = basename.rsplit(".", 1)
71
if origpath.count(".") and len(origpath.rsplit(".", 1)[1]) <= 7:
72
path, suffix = origpath.rsplit(".", 1)
70
73
suffix = "." + suffix
72
return _util.generate_name(basename + "-clone",
73
lambda p: VirtualDisk.path_exists(design.original_conn, p),
75
dirname = os.path.dirname(path)
76
basename = os.path.basename(path)
78
clonebase = basename + "-clone"
79
if origname and basename == origname:
82
clonebase = os.path.join(dirname, clonebase)
83
return _util.generate_name(
85
lambda p: VirtualDisk.path_exists(design.original_conn, p),
77
89
def generate_clone_name(design):
78
90
# If the orig name is "foo-clone", we don't want the clone to be
176
188
self._valid_guest.set_name(name)
177
189
except ValueError, e:
178
raise ValueError, _("Invalid name for new guest: %s") % (str(e),)
190
raise ValueError(_("Invalid name for new guest: %s") % e)
180
192
# Make sure new VM name isn't taken.
194
206
self._valid_guest.set_uuid(uuid)
195
207
except ValueError, e:
196
raise ValueError, _("Invalid uuid for new guest: %s") % (str(e),)
208
raise ValueError(_("Invalid uuid for new guest: %s") % e)
198
210
if _util.vm_uuid_collision(self._hyper_conn, uuid):
199
211
raise ValueError(_("UUID '%s' is in use by another guest.") %
407
419
if status not in [libvirt.VIR_DOMAIN_SHUTOFF,
408
420
libvirt.VIR_DOMAIN_PAUSED]:
409
raise RuntimeError, _("Domain with devices to clone must be "
410
"paused or shutoff.")
421
raise RuntimeError(_("Domain with devices to clone must be "
422
"paused or shutoff."))
413
425
def setup_clone(self):
439
451
count = ctx.xpathEval("count(/domain/devices/interface/mac)")
440
for i in range(1, int(count+1)):
452
for i in range(1, int(count + 1)):
441
453
base_xpath = "/domain/devices/interface[%d]" % i
442
454
base_node = ctx.xpathEval(base_xpath)[0]
443
455
node = ctx.xpathEval(base_xpath + "/mac/@address")
574
586
count = _util.get_xml_path(xml, "count(/domain/devices/disk)")
575
for i in range(1, int(count+1)):
587
for i in range(1, int(count + 1)):
576
588
# Check if the disk needs cloning
577
589
(path, target) = self._do_we_clone_device(xml, i)
578
590
if target == None: