data.sort(key=lambda x: x.count("/"), reverse=True)
return data
+ @classmethod
+ def _InstanceDir(cls, instance_name):
+ """Return the root directory for an instance.
+
+ """
+ return utils.PathJoin(cls._ROOT_DIR, instance_name)
+
def ListInstances(self):
"""Get the list of running instances.
@return: (name, id, memory, vcpus, stat, times)
"""
- dir_name = "%s/%s" % (self._ROOT_DIR, instance_name)
+ dir_name = self._InstanceDir(instance_name)
if not self._IsDirLive(dir_name):
raise HypervisorError("Instance %s is not running" % instance_name)
return (instance_name, 0, 0, 0, 0, 0)
execute '/ganeti-chroot start'.
"""
- root_dir = "%s/%s" % (self._ROOT_DIR, instance.name)
+ root_dir = self._InstanceDir(instance.name)
if not os.path.exists(root_dir):
try:
os.mkdir(root_dir)
- finally unmount the instance dir
"""
- root_dir = "%s/%s" % (self._ROOT_DIR, instance.name)
+ root_dir = self._InstanceDir(instance.name)
if not os.path.exists(root_dir) or not self._IsDirLive(root_dir):
return
"""Return a command for connecting to the console of an instance.
"""
- root_dir = "%s/%s" % (cls._ROOT_DIR, instance.name)
+ root_dir = cls._InstanceDir(instance.name)
if not os.path.ismount(root_dir):
raise HypervisorError("Instance %s is not running" % instance.name)