How to use the podman.ErrorOccurred function in podman

To help you get started, we’ve selected a few podman examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github containers / python-podman / test / test_pods_no_ctnrs.py View on Github external
def test_045_raises_no_ctnrs(self):
        global ident, pod

        with self.assertRaises(podman.NoContainersInPod):
            pod.start()

        with self.assertRaises(podman.NoContainersInPod):
            pod.restart()

        with self.assertRaises(podman.NoContainerRunning):
            next(pod.stats())

        with self.assertRaises(podman.ErrorOccurred):
            pod.top()
github containers / podman / contrib / python / pypodman / pypodman / lib / actions / commit_action.py View on Github external
def commit(self):
        """Create image from container."""
        try:
            try:
                ctnr = self.client.containers.get(self._args.container[0])
            except podman.ContainerNotFound as e:
                sys.stdout.flush()
                print(
                    'Container {} not found.'.format(e.name),
                    file=sys.stderr,
                    flush=True)
                return 1
            else:
                ident = ctnr.commit(self.opts['image'][0], **self.opts)
                print(ident)
        except podman.ErrorOccurred as e:
            sys.stdout.flush()
            print(
                '{}'.format(e.reason).capitalize(),
                file=sys.stderr,
                flush=True)
            return 1
        return 0
github containers / podman / contrib / python / pypodman / pypodman / lib / actions / pod / kill_parser.py View on Github external
def kill(self):
        """Signal provided pods."""
        idents = None if self._args.all else self._args.pod
        pods = query_pods(self.client.pods, idents)

        for pod in pods:
            try:
                pod.kill(self._args.signal)
                print(pod.id)
            except podman.PodNotFound as ex:
                print(
                    'Pod "{}" not found.'.format(ex.name),
                    file=sys.stderr,
                    flush=True)
            except podman.ErrorOccurred as e:
                print(
                    '{}'.format(e.reason).capitalize(),
                    file=sys.stderr,
                    flush=True)
                return 1
        return 0
github containers / podman / contrib / python / pypodman / pypodman / lib / actions / pod / stop_parser.py View on Github external
def stop(self):
        """Stop pod and container(s)."""
        idents = None if self._args.all else self._args.pod
        pods = query_pods(self.client.pods, idents)

        for pod in pods:
            try:
                pod.stop()
            except podman.ErrorOccurred as ex:
                print(
                    '{}'.format(ex.reason).capitalize(),
                    file=sys.stderr,
                    flush=True)
                return 1
        return 0
github containers / podman / contrib / python / pypodman / pypodman / lib / actions / pod / restart_parser.py View on Github external
def restart(self):
        """Restart pod and container(s)."""
        idents = None if self._args.all else self._args.pod
        pods = query_pods(self.client.pods, idents)

        for pod in pods:
            try:
                pod.restart()
                print(pod.id)
            except podman.PodNotFound as ex:
                print(
                    'Pod "{}" not found.'.format(ex.name),
                    file=sys.stderr,
                    flush=True)
            except podman.ErrorOccurred as ex:
                print(
                    '{}'.format(ex.reason).capitalize(),
                    file=sys.stderr,
                    flush=True)
                return 1
        return 0
github containers / podman / contrib / python / pypodman / pypodman / lib / actions / inspect_action.py View on Github external
if self._args.type in ('all', 'container'):
                    obj = self._get_container(ident)
                if obj is None and self._args.type in ('all', 'image'):
                    obj = self._get_image(ident)

                if obj is None:
                    if self._args.type == 'container':
                        msg = 'Container "{}" not found'.format(ident)
                    elif self._args.type == 'image':
                        msg = 'Image "{}" not found'.format(ident)
                    else:
                        msg = 'Object "{}" not found'.format(ident)
                    print(msg, file=sys.stderr, flush=True)
                else:
                    output.update(obj._asdict())
        except podman.ErrorOccurred as e:
            sys.stdout.flush()
            print(
                '{}'.format(e.reason).capitalize(),
                file=sys.stderr,
                flush=True)
            return 1
        else:
            print(json.dumps(output, indent=2))
github containers / podman / contrib / python / pypodman / pypodman / lib / actions / pull_action.py View on Github external
def pull(self):
        """Retrieve image."""
        for ident in self._args.targets:
            try:
                self.client.images.pull(ident)
                print(ident)
            except podman.ImageNotFound as e:
                sys.stdout.flush()
                print(
                    'Image {} not found.'.format(e.name),
                    file=sys.stderr,
                    flush=True)
            except podman.ErrorOccurred as e:
                sys.stdout.flush()
                print(
                    '{}'.format(e.reason).capitalize(),
                    file=sys.stderr,
                    flush=True)
github containers / podman / contrib / python / pypodman / pypodman / lib / actions / export_action.py View on Github external
def export(self):
        """Create tarball from container filesystem."""
        try:
            try:
                ctnr = self.client.containers.get(self._args.container[0])
            except podman.ContainerNotFound as e:
                sys.stdout.flush()
                print(
                    'Container {} not found.'.format(e.name),
                    file=sys.stderr,
                    flush=True)
                return 1
            else:
                ctnr.export(self._args.output[0])
        except podman.ErrorOccurred as e:
            sys.stdout.flush()
            print(
                '{}'.format(e.reason).capitalize(),
                file=sys.stderr,
                flush=True)
            return 1
        return 0
github containers / podman / contrib / python / pypodman / pypodman / lib / actions / info_action.py View on Github external
def info(self):
        """Report on Podman Service."""
        try:
            info = self.client.system.info()
        except podman.ErrorOccurred as e:
            sys.stdout.flush()
            print(
                '{}'.format(e.reason).capitalize(),
                file=sys.stderr,
                flush=True)
            return 1
        else:
            if self._args.format == 'json':
                print(json.dumps(info._asdict(), indent=2), flush=True)
            else:
                print(
                    yaml.dump(
                        dict(info._asdict()),
                        canonical=False,
                        default_flow_style=False),
                    flush=True)
github containers / podman / contrib / python / pypodman / pypodman / lib / actions / restart_action.py View on Github external
def restart(self):
        """Restart container(s)."""
        try:
            for ident in self._args.targets:
                try:
                    ctnr = self.client.containers.get(ident)
                    logging.debug('Restarting Container %s', ctnr.id)
                    ctnr.restart(timeout=self._args.timeout)
                    print(ident)
                except podman.ContainerNotFound as e:
                    sys.stdout.flush()
                    print(
                        'Container {} not found.'.format(e.name),
                        file=sys.stderr,
                        flush=True)
        except podman.ErrorOccurred as e:
            sys.stdout.flush()
            print(
                '{}'.format(e.reason).capitalize(),
                file=sys.stderr,
                flush=True)