summaryrefslogtreecommitdiff
path: root/src/op_mode
diff options
context:
space:
mode:
Diffstat (limited to 'src/op_mode')
-rwxr-xr-xsrc/op_mode/containers_op.py30
1 files changed, 16 insertions, 14 deletions
diff --git a/src/op_mode/containers_op.py b/src/op_mode/containers_op.py
index bc317029c..c55a48b3c 100755
--- a/src/op_mode/containers_op.py
+++ b/src/op_mode/containers_op.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
#
-# Copyright (C) 2021 VyOS maintainers and contributors
+# Copyright (C) 2021-2022 VyOS maintainers and contributors
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 or later as
@@ -14,11 +14,14 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+import os
import argparse
from getpass import getuser
from vyos.configquery import ConfigTreeQuery
+from vyos.base import Warning
from vyos.util import cmd
+from subprocess import STDOUT
parser = argparse.ArgumentParser()
parser.add_argument("-a", "--all", action="store_true", help="Show all containers")
@@ -30,9 +33,6 @@ parser.add_argument("-u", "--update", action="store", help="Update given contain
config = ConfigTreeQuery()
base = ['container']
-if not config.exists(base):
- print('Containers not configured')
- exit(0)
if getuser() != 'root':
raise OSError('This functions needs to be run as root to return correct results!')
@@ -42,26 +42,28 @@ if __name__ == '__main__':
if args.all:
print(cmd('podman ps --all'))
-
elif args.image:
print(cmd('podman image ls'))
-
elif args.networks:
print(cmd('podman network ls'))
elif args.pull:
image = args.pull
+ registry_config = '/etc/containers/registries.conf'
+ if not os.path.exists(registry_config):
+ Warning('No container registry configured. Please use full URL when '\
+ 'adding an image. E.g. prefix with docker.io/image-name.')
try:
- print(cmd(f'podman image pull {image}'))
- except:
- print(f'Can\'t find or download image "{image}"')
+ print(os.system(f'podman image pull {image}'))
+ except Exception as e:
+ print(f'Unable to download image "{image}". {e}')
elif args.remove:
image = args.remove
try:
- print(cmd(f'podman image rm {image}'))
- except:
- print(f'Can\'t delete image "{image}"')
+ print(os.system(f'podman image rm {image}'))
+ except FileNotFoundError as e:
+ print(f'Unable to delete image "{image}". {e}')
elif args.update:
tmp = config.get_config_dict(base + ['name', args.update],
@@ -69,8 +71,8 @@ if __name__ == '__main__':
try:
image = tmp['image']
print(cmd(f'podman image pull {image}'))
- except:
- print(f'Can\'t find or download image "{image}"')
+ except Exception as e:
+ print(f'Unable to download image "{image}". {e}')
else:
parser.print_help()
exit(1)