Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def loadCache(self):
with podman.Client(self.host) as pclient:
self.images = list(pclient.images.list())
self.alpine_image = next(
iter(
[
i
for i in self.images
if "docker.io/library/alpine:latest" in i["repoTags"]
]
or []
),
None,
)
return self.images
def setUp(self):
self.tmpdir = os.environ['TMPDIR']
self.host = os.environ['PODMAN_HOST']
self.pclient = podman.Client(self.host)
def setUp(self):
self.tmpdir = os.environ["TMPDIR"]
self.host = os.environ["PODMAN_HOST"]
self.pclient = podman.Client(self.host)
self.images = self.loadCache()
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()
def test_get(self):
actual = self.pclient.containers.get(self.alpine_ctnr.id)
for k in ['id', 'status', 'ports']:
self.assertEqual(actual[k], self.alpine_ctnr[k])
with self.assertRaises(podman.ContainerNotFound):
self.pclient.containers.get("bozo")
#!/usr/bin/env python3
"""Example: Show all containers created since midnight."""
from datetime import datetime, time, timezone
import podman
print('{}\n'.format(__doc__))
midnight = datetime.combine(datetime.today(), time.min, tzinfo=timezone.utc)
with podman.Client() as client:
for c in client.containers.list():
created_at = podman.datetime_parse(c.createdat)
if created_at > midnight:
print('{}: image: {} createdAt: {}'.format(
c.id[:12], c.image[:32], podman.datetime_format(created_at)))
with open(path, "w") as stream:
stream.write("FROM alpine")
builder = self.pclient.images.build(
containerfiles=[path], tags=["alpine-unittest"]
)
self.assertIsNotNone(builder)
for line, img in builder():
# drain the generator...
continue
self.assertIsNotNone(img)
self.assertIn("localhost/alpine-unittest:latest", img.repoTags)
self.assertLess(
podman.datetime_parse(img.created), datetime.now(timezone.utc)
)
from datetime import datetime, time, timezone
import podman
print('{}\n'.format(__doc__))
midnight = datetime.combine(datetime.today(), time.min, tzinfo=timezone.utc)
with podman.Client() as client:
for c in client.containers.list():
created_at = podman.datetime_parse(c.createdat)
if created_at > midnight:
print('{}: image: {} createdAt: {}'.format(
c.id[:12], c.image[:32], podman.datetime_format(created_at)))
def test_remote(self, mock_ping):
p = Client(
uri='unix:/run/podman',
interface='io.podman',
remote_uri='ssh://user@hostname/run/podman/podman',
identity_file='~/.ssh/id_rsa')
self.assertIsInstance(p._client, BaseClient)
mock_ping.assert_called_once_with()
def test_local(self, mock_ping):
p = Client(
uri='unix:/run/podman',
interface='io.podman',
)
self.assertIsInstance(p._client, LocalClient)
self.assertIsInstance(p._client, BaseClient)
mock_ping.assert_called_once_with()