Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ services:
before_install:
- sudo apt-get -qq update
- sudo apt-get -qq install btrfs-tools libdevmapper-dev libgpgme11-dev libapparmor-dev
- sudo apt-get -qq install autoconf automake bison e2fslibs-dev libfuse-dev libtool liblzma-dev gettext
- sudo apt-get -qq install autoconf automake bison e2fslibs-dev libfuse-dev libtool liblzma-dev gettext python3-setuptools
- sudo make install.libseccomp.sudo

install:
Expand Down
19 changes: 13 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ test/checkseccomp/checkseccomp: .gopathok $(wildcard test/checkseccomp/*.go)
podman: .gopathok $(shell hack/find-godeps.sh $(GOPKGDIR) cmd/podman $(PROJECT)) varlink_generate varlink_api_generate
$(GO) build -i $(LDFLAGS_PODMAN) -tags "$(BUILDTAGS)" -o bin/$@ $(PROJECT)/cmd/podman

python-podman:
$(MAKE) -C contrib/python python-podman

clean:
ifneq ($(GOPATH),)
rm -f "$(GOPATH)/.gopathok"
Expand All @@ -105,6 +108,8 @@ endif
rm -f test/copyimg/copyimg
rm -f test/checkseccomp/checkseccomp
rm -fr build/
$(MAKE) -C contrib/python clean


libpodimage:
docker build -t ${LIBPOD_IMAGE} .
Expand Down Expand Up @@ -136,16 +141,16 @@ localunit: varlink_generate
ginkgo:
ginkgo -v test/e2e/

localintegration: varlink_generate test-binaries
localintegration: varlink_generate test-binaries clientintegration
ginkgo -v -cover -flakeAttempts 3 -progress -trace -noColor test/e2e/.
# Temporarily disabling these tests due to varlink issues
# in our CI environment
# bash test/varlink/run_varlink_tests.sh

clientintegration:
$(MAKE) -C contrib/python integration

vagrant-check:
BOX=$(BOX) sh ./vagrant.sh

binaries: varlink_generate podman
binaries: varlink_generate podman python-podman

test-binaries: test/bin2img/bin2img test/copyimg/copyimg test/checkseccomp/checkseccomp

Expand Down Expand Up @@ -282,4 +287,6 @@ validate: gofmt .gitvalidation
shell \
changelog \
validate \
install.libseccomp.sudo
install.libseccomp.sudo \
python-podman \
clientintegration
4 changes: 0 additions & 4 deletions contrib/libpodpy/__init__.py

This file was deleted.

45 changes: 0 additions & 45 deletions contrib/libpodpy/client.py

This file was deleted.

8 changes: 0 additions & 8 deletions contrib/libpodpy/containers.py

This file was deleted.

15 changes: 0 additions & 15 deletions contrib/libpodpy/images.py

This file was deleted.

10 changes: 0 additions & 10 deletions contrib/libpodpy/system.py

This file was deleted.

3 changes: 3 additions & 0 deletions contrib/python/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build
dist
*.egg-info
1 change: 1 addition & 0 deletions contrib/python/CHANGES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v0.1.0, 2018-05-11 -- Initial release.
13 changes: 13 additions & 0 deletions contrib/python/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Copyright 2018 Red Hat, Inc

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
2 changes: 2 additions & 0 deletions contrib/python/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
prune test/
include README.md
15 changes: 15 additions & 0 deletions contrib/python/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
PYTHON ?= /usr/bin/python3

.PHONY: python-podman
python-podman:
$(PYTHON) setup.py bdist

.PHONY: integration
integration:
test/test_runner.sh

.PHONY: clean
clean:
$(PYTHON) setup.py clean --all
rm -rf podman.egg-info dist
find . -depth -name __pycache__ -exec rm -rf {} \;
15 changes: 15 additions & 0 deletions contrib/python/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# podman - pythonic library for working with varlink interface to Podman

### Status: Active Development

See [libpod](https://github.com/projectatomic/libpod)


###

To build the podman wheel:

```sh
cd ~/libpod/contrib/pypodman
python3 setup.py clean -a && python3 setup.py bdist_wheel
```
22 changes: 22 additions & 0 deletions contrib/python/podman/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""A client for communicating with a Podman server."""
import pkg_resources

from .client import Client
from .libs import datetime_format, datetime_parse
from .libs.errors import (ContainerNotFound, ErrorOccurred, ImageNotFound,
RuntimeError)

try:
__version__ = pkg_resources.get_distribution('podman').version
except Exception:
__version__ = '0.0.0'

__all__ = [
'Client',
'ContainerNotFound',
'datetime_format',
'datetime_parse',
'ErrorOccurred',
'ImageNotFound',
'RuntimeError',
]
81 changes: 81 additions & 0 deletions contrib/python/podman/client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
"""A client for communicating with a Podman varlink service."""
import contextlib
import functools

from varlink import Client as VarlinkClient
from varlink import VarlinkError

from .libs import cached_property
from .libs.containers import Containers
from .libs.errors import error_factory
from .libs.images import Images
from .libs.system import System


class Client(object):
"""A client for communicating with a Podman varlink service.

Example:

>>> import podman
>>> c = podman.Client()
>>> c.system.versions
"""

# TODO: Port to contextlib.AbstractContextManager once
# Python >=3.6 required

def __init__(self,
uri='unix:/run/podman/io.projectatomic.podman',
interface='io.projectatomic.podman'):
"""Construct a podman varlink Client.

uri from default systemd unit file.
interface from io.projectatomic.podman.varlink, do not change unless
you are a varlink guru.
"""
self._podman = None

@contextlib.contextmanager
def _podman(uri, interface):
"""Context manager for API children to access varlink."""
client = VarlinkClient(address=uri)
try:
iface = client.open(interface)
yield iface
except VarlinkError as e:
raise error_factory(e) from e
finally:
if hasattr(client, 'close'):
client.close()
iface.close()

self._client = functools.partial(_podman, uri, interface)

# Quick validation of connection data provided
if not System(self._client).ping():
raise ValueError('Failed varlink connection "{}/{}"'.format(
uri, interface))

def __enter__(self):
"""Return `self` upon entering the runtime context."""
return self

def __exit__(self, exc_type, exc_value, traceback):
"""Raise any exception triggered within the runtime context."""
return None

@cached_property
def system(self):
"""Manage system model for podman."""
return System(self._client)

@cached_property
def images(self):
"""Manage images model for libpod."""
return Images(self._client)

@cached_property
def containers(self):
"""Manage containers model for libpod."""
return Containers(self._client)
Loading