summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2024-04-23 06:17:00 +0200
committerGitHub <noreply@github.com>2024-04-23 06:17:00 +0200
commit4e64267a408062f18140c2a1c6eb38f023cd4c76 (patch)
tree61f9022a124193c74a827559cd823c27089c1fb1 /src
parentd7e0561e67296d5fab910d4281893c48ecda040c (diff)
parentc2fc2dba32ba861684f5e34635f810c56d551d51 (diff)
downloadvyos-1x-4e64267a408062f18140c2a1c6eb38f023cd4c76.tar.gz
vyos-1x-4e64267a408062f18140c2a1c6eb38f023cd4c76.zip
Merge pull request #3346 from jestabro/add-image-enospc
image-tools: T6260: remove persistence image directory if no space error
Diffstat (limited to 'src')
-rwxr-xr-xsrc/op_mode/image_installer.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/op_mode/image_installer.py b/src/op_mode/image_installer.py
index b1311b6f9..ba0e3b6db 100755
--- a/src/op_mode/image_installer.py
+++ b/src/op_mode/image_installer.py
@@ -26,6 +26,7 @@ from os import environ
from typing import Union
from urllib.parse import urlparse
from passlib.hosts import linux_context
+from errno import ENOSPC
from psutil import disk_partitions
@@ -939,6 +940,16 @@ def add_image(image_path: str, vrf: str = None, username: str = '',
if set_as_default:
grub.set_default(image_name, root_dir)
+ except OSError as e:
+ # if no space error, remove image dir and cleanup
+ if e.errno == ENOSPC:
+ cleanup(mounts=[str(iso_path)],
+ remove_items=[f'{root_dir}/boot/{image_name}'])
+ else:
+ # unmount an ISO and cleanup
+ cleanup([str(iso_path)])
+ exit(f'Error: {e}')
+
except Exception as err:
# unmount an ISO and cleanup
cleanup([str(iso_path)])