diff --git a/lib/backend.py b/lib/backend.py index 4839c61624e4ea78c8a0055af44ad5499dcdca46..419b9a7d00b2181cd55f87620bf6834e035c72e3 100644 --- a/lib/backend.py +++ b/lib/backend.py @@ -764,6 +764,18 @@ def _SymlinkBlockDev(instance_name, device_path, device_name): return link_name +def _RemoveBlockDevLinks(instance_name): + """Remove the block device symlinks belonging to the given instance. + + """ + for i in os.listdir(constants.DISK_LINKS_DIR): + if os.path.islink(i) and i.startswith('%s-' % instance_name): + try: + os.remove(link) + except OSError, e: + pass # Ignore errors when removing the symlinks + + def _GatherAndLinkBlockDevs(instance): """Set up an instance's block device(s). @@ -818,6 +830,7 @@ def StartInstance(instance, extra_args): return False except errors.HypervisorError, err: logging.exception("Failed to start instance") + _RemoveBlockDevLinks(instance.name) return False return True @@ -870,6 +883,8 @@ def ShutdownInstance(instance): instance.name) return False + _RemoveBlockDevLinks(instance.name) + return True