storage: have QubesVM() handle vm.dir_path, also on clone and rename
Keep it uniform - QubesVM() object is responsible for handling vm.dir_path, Storage() is responsible for handling disk volumes (which may live in that directory QubesOS/qubes-issues#2256
This commit is contained in:
parent
53be79b3b7
commit
68d5ca93e1
@ -370,23 +370,10 @@ class Storage(object):
|
||||
def clone(self, src_vm):
|
||||
''' Clone volumes from the specified vm '''
|
||||
|
||||
src_path = src_vm.dir_path
|
||||
msg = "Source path {!s} does not exist".format(src_path)
|
||||
assert os.path.exists(src_path), msg
|
||||
|
||||
dst_path = self.vm.dir_path
|
||||
msg = "Destination {!s} already exists".format(dst_path)
|
||||
assert not os.path.exists(dst_path), msg
|
||||
os.mkdir(dst_path)
|
||||
|
||||
# clone/import functions may be either synchronous or asynchronous
|
||||
# in the later case, we need to wait for them to finish
|
||||
clone_op = {}
|
||||
|
||||
msg = "Cloning directory: {!s} to {!s}"
|
||||
msg = msg.format(src_path, dst_path)
|
||||
self.log.info(msg)
|
||||
|
||||
self.vm.volumes = {}
|
||||
with VmCreationManager(self.vm):
|
||||
for name, config in self.vm.volume_config.items():
|
||||
@ -439,10 +426,6 @@ class Storage(object):
|
||||
def rename(self, old_name, new_name):
|
||||
''' Notify the pools that the domain was renamed '''
|
||||
volumes = self.vm.volumes
|
||||
vm = self.vm
|
||||
old_dir_path = os.path.join(os.path.dirname(vm.dir_path), old_name)
|
||||
new_dir_path = os.path.join(os.path.dirname(vm.dir_path), new_name)
|
||||
os.rename(old_dir_path, new_dir_path)
|
||||
for name, volume in volumes.items():
|
||||
pool = self.get_pool(volume)
|
||||
volumes[name] = pool.rename(volume, old_name, new_name)
|
||||
|
@ -753,6 +753,10 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM):
|
||||
# pylint: disable=unused-argument
|
||||
self.init_log()
|
||||
|
||||
old_dir_path = os.path.join(os.path.dirname(self.dir_path), oldvalue)
|
||||
new_dir_path = os.path.join(os.path.dirname(self.dir_path), newvalue)
|
||||
os.rename(old_dir_path, new_dir_path)
|
||||
|
||||
self.storage.rename(oldvalue, newvalue)
|
||||
|
||||
if self._libvirt_domain is not None:
|
||||
@ -1288,6 +1292,12 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM):
|
||||
raise qubes.exc.QubesVMNotHaltedError(
|
||||
self, 'Cannot clone a running domain {!r}'.format(self.name))
|
||||
|
||||
msg = "Destination {!s} already exists".format(self.dir_path)
|
||||
assert not os.path.exists(self.dir_path), msg
|
||||
|
||||
self.log.info('Creating directory: {0}'.format(self.dir_path))
|
||||
os.makedirs(self.dir_path, mode=0o775)
|
||||
|
||||
if pool or pools:
|
||||
# pylint: disable=attribute-defined-outside-init
|
||||
self.volume_config = _patch_volume_config(self.volume_config, pool,
|
||||
|
Loading…
Reference in New Issue
Block a user