From ec873e01a34f64f7dbdcce3de884d8235628da03 Mon Sep 17 00:00:00 2001 From: Hongbin Lu Date: Sun, 6 Aug 2017 22:36:32 +0000 Subject: [PATCH] Add argument 'mounts' to container Introduce an option for users to bind-mount Cinder volumes to containers. The syntax will look like: $ zun run --mount source=my-volume,destination=/data The above command will bind-mount cinder volume with name 'my-volume' into path '/data' inside the container. Change-Id: If8e44527e65cf574400b9043108e75b473b3627c Partial-Implements: blueprint direct-cinder-integration --- zunclient/api_versions.py | 2 +- zunclient/common/utils.py | 27 +++++++++++++++ zunclient/osc/v1/containers.py | 16 +++++++++ zunclient/tests/unit/test_shell.py | 8 ++--- .../tests/unit/v1/test_containers_shell.py | 34 +++++++++++++++++++ zunclient/v1/containers.py | 2 +- zunclient/v1/containers_shell.py | 14 ++++++++ 7 files changed, 97 insertions(+), 6 deletions(-) diff --git a/zunclient/api_versions.py b/zunclient/api_versions.py index 5a12c43e..30788015 100644 --- a/zunclient/api_versions.py +++ b/zunclient/api_versions.py @@ -30,7 +30,7 @@ if not LOG.handlers: HEADER_NAME = "OpenStack-API-Version" SERVICE_TYPE = "container" -DEFAULT_API_VERSION = '1.9' +DEFAULT_API_VERSION = '1.11' _SUBSTITUTIONS = {} diff --git a/zunclient/common/utils.py b/zunclient/common/utils.py index 0aa5cd0e..c9382564 100644 --- a/zunclient/common/utils.py +++ b/zunclient/common/utils.py @@ -198,6 +198,33 @@ def parse_command(command): return " ".join(output) +def parse_mounts(mounts): + err_msg = ("Invalid mounts argument '%s'. mounts arguments must be of " + "the form --mount source=,destination=.") + parsed_mounts = [] + for mount in mounts: + mount_info = {"source": "", "destination": ""} + for mnt in mount.split(","): + try: + k, v = mnt.split("=", 1) + k = k.strip() + v = v.strip() + except ValueError: + raise apiexec.CommandError(err_msg % mnt) + if k in mount_info: + if mount_info[k]: + raise apiexec.CommandError(err_msg % mnt) + mount_info[k] = v + else: + raise apiexec.CommandError(err_msg % mnt) + + if not mount_info['source'] or not mount_info['destination']: + raise apiexec.CommandError(err_msg % mnt) + + parsed_mounts.append(mount_info) + return parsed_mounts + + def parse_nets(ns): err_msg = ("Invalid nets argument '%s'. nets arguments must be of " "the form --nets