Move storage-related VM rename code to storage class

This commit is contained in:
Marek Marczykowski-Górecki 2013-08-02 20:58:20 +02:00
parent ada5ebd784
commit 21c908b9b2
3 changed files with 22 additions and 2 deletions

View File

@ -564,8 +564,8 @@ class QubesVm(object):
if os.path.exists(self.conf_file):
os.rename(self.conf_file, new_conf)
old_dirpath = self.dir_path
new_dirpath = os.path.join(os.path.dirname(self.dir_path), name)
os.rename(old_dirpath, new_dirpath)
self.storage.rename(self.name, name)
new_dirpath = self.storage.vmdir
self.dir_path = new_dirpath
old_name = self.name
self.name = name

View File

@ -139,6 +139,18 @@ class QubesVmStorage(object):
# TODO: modules?
def rename(self, old_name, new_name):
old_vmdir = self.vmdir
new_vmdir = os.path.join(os.path.dirname(self.vmdir), new_name)
os.rename(self.vmdir, new_dirpath)
self.vmdir = new_dirpath
if self.private_img:
self.private_img = self.private_img.replace(old_vmdir, new_vmdir)
if self.root_img:
self.root_img = self.root_img.replace(old_vmdir, new_vmdir)
if self.volatile_img:
self.volatile_img = self.volatile_img.replace(old_vmdir, new_vmdir)
def verify_files(self):
if not os.path.exists (self.vmdir):
raise QubesException (

View File

@ -59,6 +59,14 @@ class QubesWniVmStorage(QubesVmStorage):
None, 0)
super(QubesWniVmStorage, self).remove_from_disk()
def rename(self, old_name, new_name):
super(QubesWniVmStorage, self).rename(old_name, new_name)
win32api.ShellExecute(None, "runas",
"wmic", "useraccount where name='%s' rename '%s'"
% (self._get_username(old_name), self._get_username(new_name)),
None, 0)
def verify_files(self):
if not os.path.exists (self.vmdir):
raise QubesException (