Skip to content

Commit

Permalink
Merge pull request #7 from ava-dylang/client-version-mismatch
Browse files Browse the repository at this point in the history
User declared client version & exit on mismatch.
  • Loading branch information
srikalyan committed Feb 12, 2016
2 parents b660f21 + 5053ced commit a1bc7cf
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
26 changes: 22 additions & 4 deletions dockerrotate/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@
from dateutil import parser
from docker import Client
from docker.errors import APIError
from docker.errors import NotFound
from docker.utils import kwargs_from_env


UNIX_SOC_ARGS = {"base_url": 'unix://var/run/docker.sock'}

TEN_SECONDS = timedelta(seconds=10)


Expand Down Expand Up @@ -58,6 +61,11 @@ def parse_args():
action="store_true",
help="Do not remove anything",
)
parser.add_argument(
"--client-version",
default=None,
help="Specify client version to use.",
)
return parser.parse_args()


Expand All @@ -69,10 +77,20 @@ def make_client(args):
variables (e.g. DOCKER_HOST). This is much simpler than trying to pass
all the possible certificate options through argparse.
"""
if args.use_env:
return Client(**kwargs_from_env(assert_hostname=False))
else:
return Client(base_url='unix://var/run/docker.sock')
kwargs = kwargs_from_env(assert_hostname=False) if args.use_env else UNIX_SOC_ARGS

if args.client_version is not None:
kwargs["version"] = args.client_version

client = Client(**kwargs)

# Verify client can talk to server.
try:
client.version()
except NotFound as error:
raise SystemExit(error) # noqa

return client


def normalize_tag_name(tag):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
'nose>=1.3.7',
],
install_requires=[
'docker-py>=0.5.3',
'docker-py>=1.6.0',
'python-dateutil>=2.4.0',
],
tests_require=[
Expand Down

0 comments on commit a1bc7cf

Please sign in to comment.