Commit 3c9c571d authored by Iustin Pop's avatar Iustin Pop
Browse files

Remove instance's symlinks

This is a forward-port of commits 1150 and 1151 on the 1.2 branch:
  Add _RemoveBlockDevLinks auxiliary function, called when an instance
  fails to start and when it is shut down.

  Reviewed-by: iustinp

and:
  Fix cut&paste error when removing symlinks

  It's just whitespace... isn't it? uhm... :) Anyway, fixing an error made
  when reformatting the code for the new "safer" behaviour.

  Reviewed-by: iustinp

Original-Author: ultrotter
parent ec596c24
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment