Skip to content

Commit 9f486f1

Browse files
committed
import_vm: add clone:// and clone+start:// URIs
clone+start:// will be used to implement--hosts=cache://... clone:// itself is not yet used directly, but as the "base" protocol upon which clone+start build, it seems logical (and basically free) to implement. Signed-off-by: Yann Dirson <[email protected]>
1 parent 9751440 commit 9f486f1

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

lib/host.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,10 +294,25 @@ def cached_vm(self, uri, sr_uuid):
294294
logging.info("Could not find a VM in cache for %r", uri)
295295

296296
def import_vm(self, uri, sr_uuid=None, use_cache=False):
297+
vm = None
297298
if use_cache:
298-
vm = self.cached_vm(uri, sr_uuid)
299+
if '://' in uri and uri.startswith("clone"):
300+
protocol, rest = uri.split(":", 1)
301+
assert rest.startswith("//")
302+
filename = rest[2:] # strip "//"
303+
base_vm = self.cached_vm(filename, sr_uuid)
304+
if base_vm:
305+
vm = base_vm.clone()
306+
vm.param_clear('name-description')
307+
if uri.startswith("clone+start"):
308+
vm.start()
309+
wait_for(vm.is_running, "Wait for VM running")
310+
else:
311+
vm = self.cached_vm(uri, sr_uuid)
299312
if vm:
300313
return vm
314+
else:
315+
assert not ('://' in uri and uri.startswith("clone")), "clone URIs require cache enabled"
301316

302317
params = {}
303318
msg = "Import VM %s" % uri

0 commit comments

Comments
 (0)