mirror of
https://github.com/ansible-collections/community.docker.git
synced 2026-03-16 04:04:31 +00:00
Address no-else-return.
This commit is contained in:
parent
e3b07ed6b2
commit
f9cd56a985
@ -384,7 +384,6 @@ disable=raw-checker-failed,
|
|||||||
consider-using-with,
|
consider-using-with,
|
||||||
fixme,
|
fixme,
|
||||||
import-error, # TODO figure out why pylint cannot find the module
|
import-error, # TODO figure out why pylint cannot find the module
|
||||||
no-else-return,
|
|
||||||
no-member,
|
no-member,
|
||||||
no-name-in-module, # TODO figure out why pylint cannot find the module
|
no-name-in-module, # TODO figure out why pylint cannot find the module
|
||||||
not-an-iterable, # TODO: needs better typing info
|
not-an-iterable, # TODO: needs better typing info
|
||||||
|
|||||||
@ -349,21 +349,19 @@ class Connection(ConnectionBase):
|
|||||||
) >= LooseVersion("1.7"):
|
) >= LooseVersion("1.7"):
|
||||||
# Support for specifying the exec user was added in docker 1.7
|
# Support for specifying the exec user was added in docker 1.7
|
||||||
return self.remote_user
|
return self.remote_user
|
||||||
else:
|
self.remote_user = None
|
||||||
self.remote_user = None
|
actual_user = self._get_docker_remote_user()
|
||||||
actual_user = self._get_docker_remote_user()
|
if actual_user != self.get_option("remote_user"):
|
||||||
if actual_user != self.get_option("remote_user"):
|
display.warning(
|
||||||
display.warning(
|
f'docker {self.docker_version} does not support remote_user, using container default: {actual_user or "?"}'
|
||||||
f'docker {self.docker_version} does not support remote_user, using container default: {actual_user or "?"}'
|
)
|
||||||
)
|
return actual_user
|
||||||
return actual_user
|
if self._display.verbosity > 2:
|
||||||
elif self._display.verbosity > 2:
|
|
||||||
# Since we are not setting the actual_user, look it up so we have it for logging later
|
# Since we are not setting the actual_user, look it up so we have it for logging later
|
||||||
# Only do this if display verbosity is high enough that we'll need the value
|
# Only do this if display verbosity is high enough that we'll need the value
|
||||||
# This saves overhead from calling into docker when we do not need to.
|
# This saves overhead from calling into docker when we do not need to.
|
||||||
return self._get_docker_remote_user()
|
return self._get_docker_remote_user()
|
||||||
else:
|
return None
|
||||||
return None
|
|
||||||
|
|
||||||
def _connect(self, port=None):
|
def _connect(self, port=None):
|
||||||
"""Connect to the container. Nothing to do"""
|
"""Connect to the container. Nothing to do"""
|
||||||
@ -487,10 +485,9 @@ class Connection(ConnectionBase):
|
|||||||
import ntpath
|
import ntpath
|
||||||
|
|
||||||
return ntpath.normpath(remote_path)
|
return ntpath.normpath(remote_path)
|
||||||
else:
|
if not remote_path.startswith(os.path.sep):
|
||||||
if not remote_path.startswith(os.path.sep):
|
remote_path = os.path.join(os.path.sep, remote_path)
|
||||||
remote_path = os.path.join(os.path.sep, remote_path)
|
return os.path.normpath(remote_path)
|
||||||
return os.path.normpath(remote_path)
|
|
||||||
|
|
||||||
def put_file(self, in_path, out_path):
|
def put_file(self, in_path, out_path):
|
||||||
"""Transfer a file from local to docker container"""
|
"""Transfer a file from local to docker container"""
|
||||||
|
|||||||
@ -369,10 +369,9 @@ class Connection(ConnectionBase):
|
|||||||
import ntpath
|
import ntpath
|
||||||
|
|
||||||
return ntpath.normpath(remote_path)
|
return ntpath.normpath(remote_path)
|
||||||
else:
|
if not remote_path.startswith(os.path.sep):
|
||||||
if not remote_path.startswith(os.path.sep):
|
remote_path = os.path.join(os.path.sep, remote_path)
|
||||||
remote_path = os.path.join(os.path.sep, remote_path)
|
return os.path.normpath(remote_path)
|
||||||
return os.path.normpath(remote_path)
|
|
||||||
|
|
||||||
def put_file(self, in_path, out_path):
|
def put_file(self, in_path, out_path):
|
||||||
"""Transfer a file from local to docker container"""
|
"""Transfer a file from local to docker container"""
|
||||||
|
|||||||
@ -217,11 +217,11 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable):
|
|||||||
if daemon_env == "require":
|
if daemon_env == "require":
|
||||||
display.warning(f"{warning_prefix}: host will be skipped")
|
display.warning(f"{warning_prefix}: host will be skipped")
|
||||||
return True
|
return True
|
||||||
else: # 'optional', 'optional-silently'
|
if daemon_env == "optional":
|
||||||
if daemon_env == "optional":
|
display.warning(
|
||||||
display.warning(
|
f"{warning_prefix}: host will lack dm_DOCKER_xxx variables"
|
||||||
f"{warning_prefix}: host will lack dm_DOCKER_xxx variables"
|
)
|
||||||
)
|
# daemon_env is 'optional-silently'
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def _populate(self):
|
def _populate(self):
|
||||||
|
|||||||
@ -278,8 +278,7 @@ class APIClient(_Session, DaemonApiMixin):
|
|||||||
|
|
||||||
if kwargs.get("versioned_api", True):
|
if kwargs.get("versioned_api", True):
|
||||||
return f"{self.base_url}/v{self._version}{pathfmt.format(*args)}"
|
return f"{self.base_url}/v{self._version}{pathfmt.format(*args)}"
|
||||||
else:
|
return f"{self.base_url}{pathfmt.format(*args)}"
|
||||||
return f"{self.base_url}{pathfmt.format(*args)}"
|
|
||||||
|
|
||||||
def _raise_for_status(self, response):
|
def _raise_for_status(self, response):
|
||||||
"""Raises stored :class:`APIError`, if one occurred."""
|
"""Raises stored :class:`APIError`, if one occurred."""
|
||||||
@ -427,12 +426,11 @@ class APIClient(_Session, DaemonApiMixin):
|
|||||||
|
|
||||||
if stream:
|
if stream:
|
||||||
return gen
|
return gen
|
||||||
else:
|
try:
|
||||||
try:
|
# Wait for all the frames, concatenate them, and return the result
|
||||||
# Wait for all the frames, concatenate them, and return the result
|
return consume_socket_output(gen, demux=demux)
|
||||||
return consume_socket_output(gen, demux=demux)
|
finally:
|
||||||
finally:
|
response.close()
|
||||||
response.close()
|
|
||||||
|
|
||||||
def _disable_socket_timeout(self, socket):
|
def _disable_socket_timeout(self, socket):
|
||||||
"""Depending on the combination of python version and whether we are
|
"""Depending on the combination of python version and whether we are
|
||||||
@ -484,8 +482,7 @@ class APIClient(_Session, DaemonApiMixin):
|
|||||||
sep = b""
|
sep = b""
|
||||||
if stream:
|
if stream:
|
||||||
return self._multiplexed_response_stream_helper(res)
|
return self._multiplexed_response_stream_helper(res)
|
||||||
else:
|
return sep.join(list(self._multiplexed_buffer_helper(res)))
|
||||||
return sep.join(list(self._multiplexed_buffer_helper(res)))
|
|
||||||
|
|
||||||
def _unmount(self, *args):
|
def _unmount(self, *args):
|
||||||
for proto in args:
|
for proto in args:
|
||||||
@ -497,8 +494,7 @@ class APIClient(_Session, DaemonApiMixin):
|
|||||||
except _InvalidSchema as e:
|
except _InvalidSchema as e:
|
||||||
if self._custom_adapter:
|
if self._custom_adapter:
|
||||||
return self._custom_adapter
|
return self._custom_adapter
|
||||||
else:
|
raise e
|
||||||
raise e
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def api_version(self):
|
def api_version(self):
|
||||||
|
|||||||
@ -68,8 +68,7 @@ def home_dir():
|
|||||||
"""
|
"""
|
||||||
if IS_WINDOWS_PLATFORM:
|
if IS_WINDOWS_PLATFORM:
|
||||||
return os.environ.get("USERPROFILE", "")
|
return os.environ.get("USERPROFILE", "")
|
||||||
else:
|
return os.path.expanduser("~")
|
||||||
return os.path.expanduser("~")
|
|
||||||
|
|
||||||
|
|
||||||
def load_general_config(config_path=None):
|
def load_general_config(config_path=None):
|
||||||
|
|||||||
@ -90,9 +90,8 @@ def split_port(port):
|
|||||||
if external is not None and len(internal) != len(external):
|
if external is not None and len(internal) != len(external):
|
||||||
raise ValueError("Port ranges don't match in length")
|
raise ValueError("Port ranges don't match in length")
|
||||||
return internal, external
|
return internal, external
|
||||||
else:
|
if not external:
|
||||||
if not external:
|
external = [None] * len(internal)
|
||||||
external = [None] * len(internal)
|
elif len(internal) != len(external):
|
||||||
elif len(internal) != len(external):
|
raise ValueError("Port ranges don't match in length")
|
||||||
raise ValueError("Port ranges don't match in length")
|
return internal, [(host, ext_port) for ext_port in external]
|
||||||
return internal, [(host, ext_port) for ext_port in external]
|
|
||||||
|
|||||||
@ -111,8 +111,7 @@ def frames_iter(socket, tty):
|
|||||||
"""
|
"""
|
||||||
if tty:
|
if tty:
|
||||||
return ((STDOUT, frame) for frame in frames_iter_tty(socket))
|
return ((STDOUT, frame) for frame in frames_iter_tty(socket))
|
||||||
else:
|
return frames_iter_no_tty(socket)
|
||||||
return frames_iter_no_tty(socket)
|
|
||||||
|
|
||||||
|
|
||||||
def frames_iter_no_tty(socket):
|
def frames_iter_no_tty(socket):
|
||||||
@ -194,7 +193,6 @@ def demux_adaptor(stream_id, data):
|
|||||||
"""
|
"""
|
||||||
if stream_id == STDOUT:
|
if stream_id == STDOUT:
|
||||||
return (data, None)
|
return (data, None)
|
||||||
elif stream_id == STDERR:
|
if stream_id == STDERR:
|
||||||
return (None, data)
|
return (None, data)
|
||||||
else:
|
raise ValueError(f"{stream_id} is not a valid stream")
|
||||||
raise ValueError(f"{stream_id} is not a valid stream")
|
|
||||||
|
|||||||
@ -75,10 +75,9 @@ def compare_version(v1, v2):
|
|||||||
s2 = StrictVersion(v2)
|
s2 = StrictVersion(v2)
|
||||||
if s1 == s2:
|
if s1 == s2:
|
||||||
return 0
|
return 0
|
||||||
elif s1 > s2:
|
if s1 > s2:
|
||||||
return -1
|
return -1
|
||||||
else:
|
return 1
|
||||||
return 1
|
|
||||||
|
|
||||||
|
|
||||||
def version_lt(v1, v2):
|
def version_lt(v1, v2):
|
||||||
|
|||||||
@ -133,38 +133,35 @@ def parse_line(line, logrus_mode=False):
|
|||||||
key.append(cur)
|
key.append(cur)
|
||||||
parser.next()
|
parser.next()
|
||||||
return _Mode.KEY
|
return _Mode.KEY
|
||||||
elif cur == "=":
|
if cur == "=":
|
||||||
parser.next()
|
parser.next()
|
||||||
return _Mode.EQUAL
|
return _Mode.EQUAL
|
||||||
else:
|
if logrus_mode:
|
||||||
if logrus_mode:
|
raise InvalidLogFmt('Key must always be followed by "=" in logrus mode')
|
||||||
raise InvalidLogFmt('Key must always be followed by "=" in logrus mode')
|
handle_kv(has_no_value=True)
|
||||||
handle_kv(has_no_value=True)
|
parser.next()
|
||||||
parser.next()
|
return _Mode.GARBAGE
|
||||||
return _Mode.GARBAGE
|
|
||||||
|
|
||||||
def parse_equal(cur):
|
def parse_equal(cur):
|
||||||
if _is_ident(cur):
|
if _is_ident(cur):
|
||||||
value.append(cur)
|
value.append(cur)
|
||||||
parser.next()
|
parser.next()
|
||||||
return _Mode.IDENT_VALUE
|
return _Mode.IDENT_VALUE
|
||||||
elif cur == '"':
|
if cur == '"':
|
||||||
parser.next()
|
parser.next()
|
||||||
return _Mode.QUOTED_VALUE
|
return _Mode.QUOTED_VALUE
|
||||||
else:
|
handle_kv()
|
||||||
handle_kv()
|
parser.next()
|
||||||
parser.next()
|
return _Mode.GARBAGE
|
||||||
return _Mode.GARBAGE
|
|
||||||
|
|
||||||
def parse_ident_value(cur):
|
def parse_ident_value(cur):
|
||||||
if _is_ident(cur):
|
if _is_ident(cur):
|
||||||
value.append(cur)
|
value.append(cur)
|
||||||
parser.next()
|
parser.next()
|
||||||
return _Mode.IDENT_VALUE
|
return _Mode.IDENT_VALUE
|
||||||
else:
|
handle_kv()
|
||||||
handle_kv()
|
parser.next()
|
||||||
parser.next()
|
return _Mode.GARBAGE
|
||||||
return _Mode.GARBAGE
|
|
||||||
|
|
||||||
def parse_quoted_value(cur):
|
def parse_quoted_value(cur):
|
||||||
if cur == "\\":
|
if cur == "\\":
|
||||||
@ -182,16 +179,15 @@ def parse_line(line, logrus_mode=False):
|
|||||||
value.append(parser.parse_unicode_sequence())
|
value.append(parser.parse_unicode_sequence())
|
||||||
parser.next()
|
parser.next()
|
||||||
return _Mode.QUOTED_VALUE
|
return _Mode.QUOTED_VALUE
|
||||||
elif cur == '"':
|
if cur == '"':
|
||||||
handle_kv()
|
handle_kv()
|
||||||
parser.next()
|
parser.next()
|
||||||
return _Mode.GARBAGE
|
return _Mode.GARBAGE
|
||||||
elif cur < " ":
|
if cur < " ":
|
||||||
raise InvalidLogFmt("Control characters in quoted string are not allowed")
|
raise InvalidLogFmt("Control characters in quoted string are not allowed")
|
||||||
else:
|
value.append(cur)
|
||||||
value.append(cur)
|
parser.next()
|
||||||
parser.next()
|
return _Mode.QUOTED_VALUE
|
||||||
return _Mode.QUOTED_VALUE
|
|
||||||
|
|
||||||
parsers = {
|
parsers = {
|
||||||
_Mode.GARBAGE: parse_garbage,
|
_Mode.GARBAGE: parse_garbage,
|
||||||
|
|||||||
@ -436,11 +436,10 @@ def _parse_port_range(range_or_port, module):
|
|||||||
if end < start:
|
if end < start:
|
||||||
module.fail_json(msg=f'Invalid port range: "{range_or_port}"')
|
module.fail_json(msg=f'Invalid port range: "{range_or_port}"')
|
||||||
return list(range(start, end + 1))
|
return list(range(start, end + 1))
|
||||||
else:
|
try:
|
||||||
try:
|
return [int(range_or_port)]
|
||||||
return [int(range_or_port)]
|
except ValueError:
|
||||||
except ValueError:
|
module.fail_json(msg=f'Invalid port: "{range_or_port}"')
|
||||||
module.fail_json(msg=f'Invalid port: "{range_or_port}"')
|
|
||||||
|
|
||||||
|
|
||||||
def _split_colon_ipv6(text, module):
|
def _split_colon_ipv6(text, module):
|
||||||
|
|||||||
@ -347,8 +347,7 @@ class DockerAPIEngineDriver(EngineDriver):
|
|||||||
)
|
)
|
||||||
output = client._get_result_tty(False, res, config["Config"]["Tty"])
|
output = client._get_result_tty(False, res, config["Config"]["Tty"])
|
||||||
return output, True
|
return output, True
|
||||||
else:
|
return f"Result logged using `{logging_driver}` driver", False
|
||||||
return f"Result logged using `{logging_driver}` driver", False
|
|
||||||
|
|
||||||
def update_container(self, client, container_id, update_parameters):
|
def update_container(self, client, container_id, update_parameters):
|
||||||
result = client.post_json_to_json(
|
result = client.post_json_to_json(
|
||||||
|
|||||||
@ -85,8 +85,7 @@ class DockerSocketHandlerBase:
|
|||||||
if "OpenSSL.SSL.ZeroReturnError" in str(type(e)):
|
if "OpenSSL.SSL.ZeroReturnError" in str(type(e)):
|
||||||
self._eof = True
|
self._eof = True
|
||||||
return
|
return
|
||||||
else:
|
raise
|
||||||
raise
|
|
||||||
elif isinstance(self._sock, getattr(pysocket, "SocketIO")):
|
elif isinstance(self._sock, getattr(pysocket, "SocketIO")):
|
||||||
data = self._sock.read()
|
data = self._sock.read()
|
||||||
else:
|
else:
|
||||||
|
|||||||
@ -67,7 +67,6 @@ def write_to_socket(sock, data):
|
|||||||
# WrappedSocket (urllib3/contrib/pyopenssl) does not have `send`, but
|
# WrappedSocket (urllib3/contrib/pyopenssl) does not have `send`, but
|
||||||
# only `sendall`, which uses `_send_until_done` under the hood.
|
# only `sendall`, which uses `_send_until_done` under the hood.
|
||||||
return sock._send_until_done(data)
|
return sock._send_until_done(data)
|
||||||
elif hasattr(sock, "send"):
|
if hasattr(sock, "send"):
|
||||||
return sock.send(data)
|
return sock.send(data)
|
||||||
else:
|
return os.write(sock.fileno(), data)
|
||||||
return os.write(sock.fileno(), data)
|
|
||||||
|
|||||||
@ -74,22 +74,18 @@ class AnsibleDockerSwarmClient(AnsibleDockerClient):
|
|||||||
swarm_info = json.loads(json_str)
|
swarm_info = json.loads(json_str)
|
||||||
if swarm_info["Swarm"]["NodeID"]:
|
if swarm_info["Swarm"]["NodeID"]:
|
||||||
return True
|
return True
|
||||||
if swarm_info["Swarm"]["LocalNodeState"] in (
|
return swarm_info["Swarm"]["LocalNodeState"] in (
|
||||||
"active",
|
"active",
|
||||||
"pending",
|
"pending",
|
||||||
"locked",
|
"locked",
|
||||||
):
|
)
|
||||||
return True
|
|
||||||
return False
|
return False
|
||||||
else:
|
try:
|
||||||
try:
|
node_info = self.get_node_inspect(node_id=node_id)
|
||||||
node_info = self.get_node_inspect(node_id=node_id)
|
except APIError:
|
||||||
except APIError:
|
return
|
||||||
return
|
|
||||||
|
|
||||||
if node_info["ID"] is not None:
|
return node_info["ID"] is not None
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
def check_if_swarm_manager(self):
|
def check_if_swarm_manager(self):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@ -98,10 +98,9 @@ def sanitize_result(data):
|
|||||||
"""
|
"""
|
||||||
if isinstance(data, dict):
|
if isinstance(data, dict):
|
||||||
return dict((k, sanitize_result(v)) for k, v in data.items())
|
return dict((k, sanitize_result(v)) for k, v in data.items())
|
||||||
elif isinstance(data, (list, tuple)):
|
if isinstance(data, (list, tuple)):
|
||||||
return [sanitize_result(v) for v in data]
|
return [sanitize_result(v) for v in data]
|
||||||
else:
|
return data
|
||||||
return data
|
|
||||||
|
|
||||||
|
|
||||||
def log_debug(msg, pretty_print=False):
|
def log_debug(msg, pretty_print=False):
|
||||||
@ -194,31 +193,28 @@ def compare_generic(a, b, method, datatype):
|
|||||||
# Do proper comparison (both objects not None)
|
# Do proper comparison (both objects not None)
|
||||||
if datatype == "value":
|
if datatype == "value":
|
||||||
return a == b
|
return a == b
|
||||||
elif datatype == "list":
|
if datatype == "list":
|
||||||
if method == "strict":
|
if method == "strict":
|
||||||
return a == b
|
return a == b
|
||||||
else:
|
i = 0
|
||||||
i = 0
|
for v in a:
|
||||||
for v in a:
|
while i < len(b) and b[i] != v:
|
||||||
while i < len(b) and b[i] != v:
|
|
||||||
i += 1
|
|
||||||
if i == len(b):
|
|
||||||
return False
|
|
||||||
i += 1
|
i += 1
|
||||||
return True
|
if i == len(b):
|
||||||
elif datatype == "dict":
|
return False
|
||||||
|
i += 1
|
||||||
|
return True
|
||||||
|
if datatype == "dict":
|
||||||
if method == "strict":
|
if method == "strict":
|
||||||
return a == b
|
return a == b
|
||||||
else:
|
return compare_dict_allow_more_present(a, b)
|
||||||
return compare_dict_allow_more_present(a, b)
|
if datatype == "set":
|
||||||
elif datatype == "set":
|
|
||||||
set_a = set(a)
|
set_a = set(a)
|
||||||
set_b = set(b)
|
set_b = set(b)
|
||||||
if method == "strict":
|
if method == "strict":
|
||||||
return set_a == set_b
|
return set_a == set_b
|
||||||
else:
|
return set_b >= set_a
|
||||||
return set_b >= set_a
|
if datatype == "set(dict)":
|
||||||
elif datatype == "set(dict)":
|
|
||||||
for av in a:
|
for av in a:
|
||||||
found = False
|
found = False
|
||||||
for bv in b:
|
for bv in b:
|
||||||
@ -335,10 +331,9 @@ def clean_dict_booleans_for_docker_api(data, allow_sequences=False):
|
|||||||
def sanitize(value):
|
def sanitize(value):
|
||||||
if value is True:
|
if value is True:
|
||||||
return "true"
|
return "true"
|
||||||
elif value is False:
|
if value is False:
|
||||||
return "false"
|
return "false"
|
||||||
else:
|
return str(value)
|
||||||
return str(value)
|
|
||||||
|
|
||||||
result = dict()
|
result = dict()
|
||||||
if data is not None:
|
if data is not None:
|
||||||
|
|||||||
@ -343,31 +343,31 @@ def retrieve_diff(
|
|||||||
diff["before_header"] = container_path
|
diff["before_header"] = container_path
|
||||||
diff["before"] = "(directory)"
|
diff["before"] = "(directory)"
|
||||||
return
|
return
|
||||||
elif regular_stat["mode"] & (1 << (32 - 4)) != 0:
|
if regular_stat["mode"] & (1 << (32 - 4)) != 0:
|
||||||
diff["before_header"] = container_path
|
diff["before_header"] = container_path
|
||||||
diff["before"] = "(temporary file)"
|
diff["before"] = "(temporary file)"
|
||||||
return
|
return
|
||||||
elif regular_stat["mode"] & (1 << (32 - 5)) != 0:
|
if regular_stat["mode"] & (1 << (32 - 5)) != 0:
|
||||||
diff["before_header"] = container_path
|
diff["before_header"] = container_path
|
||||||
diff["before"] = link_target
|
diff["before"] = link_target
|
||||||
return
|
return
|
||||||
elif regular_stat["mode"] & (1 << (32 - 6)) != 0:
|
if regular_stat["mode"] & (1 << (32 - 6)) != 0:
|
||||||
diff["before_header"] = container_path
|
diff["before_header"] = container_path
|
||||||
diff["before"] = "(device)"
|
diff["before"] = "(device)"
|
||||||
return
|
return
|
||||||
elif regular_stat["mode"] & (1 << (32 - 7)) != 0:
|
if regular_stat["mode"] & (1 << (32 - 7)) != 0:
|
||||||
diff["before_header"] = container_path
|
diff["before_header"] = container_path
|
||||||
diff["before"] = "(named pipe)"
|
diff["before"] = "(named pipe)"
|
||||||
return
|
return
|
||||||
elif regular_stat["mode"] & (1 << (32 - 8)) != 0:
|
if regular_stat["mode"] & (1 << (32 - 8)) != 0:
|
||||||
diff["before_header"] = container_path
|
diff["before_header"] = container_path
|
||||||
diff["before"] = "(socket)"
|
diff["before"] = "(socket)"
|
||||||
return
|
return
|
||||||
elif regular_stat["mode"] & (1 << (32 - 11)) != 0:
|
if regular_stat["mode"] & (1 << (32 - 11)) != 0:
|
||||||
diff["before_header"] = container_path
|
diff["before_header"] = container_path
|
||||||
diff["before"] = "(character device)"
|
diff["before"] = "(character device)"
|
||||||
return
|
return
|
||||||
elif regular_stat["mode"] & (1 << (32 - 13)) != 0:
|
if regular_stat["mode"] & (1 << (32 - 13)) != 0:
|
||||||
diff["before_header"] = container_path
|
diff["before_header"] = container_path
|
||||||
diff["before"] = "(unknown filesystem object)"
|
diff["before"] = "(unknown filesystem object)"
|
||||||
return
|
return
|
||||||
|
|||||||
@ -271,8 +271,7 @@ class DockerHostManager(DockerBaseClass):
|
|||||||
try:
|
try:
|
||||||
if self.verbose_output:
|
if self.verbose_output:
|
||||||
return self.client.df()
|
return self.client.df()
|
||||||
else:
|
return dict(LayersSize=self.client.df()["LayersSize"])
|
||||||
return dict(LayersSize=self.client.df()["LayersSize"])
|
|
||||||
except APIError as exc:
|
except APIError as exc:
|
||||||
self.client.fail(f"Error inspecting docker host: {exc}")
|
self.client.fail(f"Error inspecting docker host: {exc}")
|
||||||
|
|
||||||
|
|||||||
@ -656,17 +656,16 @@ class ImageManager(DockerBaseClass):
|
|||||||
|
|
||||||
if archived is None:
|
if archived is None:
|
||||||
return build_msg("since none present")
|
return build_msg("since none present")
|
||||||
elif (
|
if (
|
||||||
current_image_id == api_image_id(archived.image_id)
|
current_image_id == api_image_id(archived.image_id)
|
||||||
and [current_image_name] == archived.repo_tags
|
and [current_image_name] == archived.repo_tags
|
||||||
):
|
):
|
||||||
return None
|
return None
|
||||||
else:
|
name = ", ".join(archived.repo_tags)
|
||||||
name = ", ".join(archived.repo_tags)
|
|
||||||
|
|
||||||
return build_msg(
|
return build_msg(
|
||||||
f"overwriting archive with image {archived.image_id} named {name}"
|
f"overwriting archive with image {archived.image_id} named {name}"
|
||||||
)
|
)
|
||||||
|
|
||||||
def archive_image(self, name, tag):
|
def archive_image(self, name, tag):
|
||||||
"""
|
"""
|
||||||
@ -1076,8 +1075,7 @@ class ImageManager(DockerBaseClass):
|
|||||||
|
|
||||||
if is_image_name_id(self.name):
|
if is_image_name_id(self.name):
|
||||||
return self.client.find_image_by_id(self.name, accept_missing_image=True)
|
return self.client.find_image_by_id(self.name, accept_missing_image=True)
|
||||||
else:
|
return self.client.find_image(self.name, self.tag)
|
||||||
return self.client.find_image(self.name, self.tag)
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|||||||
@ -359,7 +359,7 @@ def validate_cidr(cidr):
|
|||||||
"""
|
"""
|
||||||
if CIDR_IPV4.match(cidr):
|
if CIDR_IPV4.match(cidr):
|
||||||
return "ipv4"
|
return "ipv4"
|
||||||
elif CIDR_IPV6.match(cidr):
|
if CIDR_IPV6.match(cidr):
|
||||||
return "ipv6"
|
return "ipv6"
|
||||||
raise ValueError(f'"{cidr}" is not a valid CIDR')
|
raise ValueError(f'"{cidr}" is not a valid CIDR')
|
||||||
|
|
||||||
|
|||||||
@ -196,9 +196,8 @@ def docker_service_inspect(client, service_name):
|
|||||||
rc, out, err = client.call_cli("service", "inspect", service_name)
|
rc, out, err = client.call_cli("service", "inspect", service_name)
|
||||||
if rc != 0:
|
if rc != 0:
|
||||||
return None
|
return None
|
||||||
else:
|
ret = json.loads(out)[0]["Spec"]
|
||||||
ret = json.loads(out)[0]["Spec"]
|
return ret
|
||||||
return ret
|
|
||||||
|
|
||||||
|
|
||||||
def docker_stack_deploy(client, stack_name, compose_files):
|
def docker_stack_deploy(client, stack_name, compose_files):
|
||||||
|
|||||||
@ -932,8 +932,7 @@ def get_docker_environment(env, env_files):
|
|||||||
if not env_list:
|
if not env_list:
|
||||||
if env is not None or env_files is not None:
|
if env is not None or env_files is not None:
|
||||||
return []
|
return []
|
||||||
else:
|
return None
|
||||||
return None
|
|
||||||
return sorted(env_list)
|
return sorted(env_list)
|
||||||
|
|
||||||
|
|
||||||
@ -992,17 +991,16 @@ def get_docker_networks(networks, network_ids):
|
|||||||
def get_nanoseconds_from_raw_option(name, value):
|
def get_nanoseconds_from_raw_option(name, value):
|
||||||
if value is None:
|
if value is None:
|
||||||
return None
|
return None
|
||||||
elif isinstance(value, int):
|
if isinstance(value, int):
|
||||||
return value
|
return value
|
||||||
elif isinstance(value, str):
|
if isinstance(value, str):
|
||||||
try:
|
try:
|
||||||
return int(value)
|
return int(value)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return convert_duration_to_nanosecond(value)
|
return convert_duration_to_nanosecond(value)
|
||||||
else:
|
raise ValueError(
|
||||||
raise ValueError(
|
f"Invalid type for {name} {value} ({type(value)}). Only string or int allowed."
|
||||||
f"Invalid type for {name} {value} ({type(value)}). Only string or int allowed."
|
)
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def get_value(key, values, default=None):
|
def get_value(key, values, default=None):
|
||||||
@ -1080,8 +1078,7 @@ def has_list_changed(new_list, old_list, sort_lists=True, sort_key=None):
|
|||||||
old_item_casted = new_item_type(old_item)
|
old_item_casted = new_item_type(old_item)
|
||||||
if new_item != old_item_casted:
|
if new_item != old_item_casted:
|
||||||
return True
|
return True
|
||||||
else:
|
continue
|
||||||
continue
|
|
||||||
except UnicodeEncodeError:
|
except UnicodeEncodeError:
|
||||||
# Fallback to assuming the strings are different
|
# Fallback to assuming the strings are different
|
||||||
return True
|
return True
|
||||||
|
|||||||
@ -27,15 +27,15 @@ def make_unsafe(value):
|
|||||||
|
|
||||||
if isinstance(value, Mapping):
|
if isinstance(value, Mapping):
|
||||||
return dict((make_unsafe(key), make_unsafe(val)) for key, val in value.items())
|
return dict((make_unsafe(key), make_unsafe(val)) for key, val in value.items())
|
||||||
elif isinstance(value, Set):
|
if isinstance(value, Set):
|
||||||
return set(make_unsafe(elt) for elt in value)
|
return set(make_unsafe(elt) for elt in value)
|
||||||
elif is_sequence(value):
|
if is_sequence(value):
|
||||||
return type(value)(make_unsafe(elt) for elt in value)
|
return type(value)(make_unsafe(elt) for elt in value)
|
||||||
elif isinstance(value, bytes):
|
if isinstance(value, bytes):
|
||||||
if _RE_TEMPLATE_CHARS_BYTES.search(value):
|
if _RE_TEMPLATE_CHARS_BYTES.search(value):
|
||||||
value = _make_unsafe(value)
|
value = _make_unsafe(value)
|
||||||
return value
|
return value
|
||||||
elif isinstance(value, str):
|
if isinstance(value, str):
|
||||||
if _RE_TEMPLATE_CHARS.search(value):
|
if _RE_TEMPLATE_CHARS.search(value):
|
||||||
value = _make_unsafe(value)
|
value = _make_unsafe(value)
|
||||||
return value
|
return value
|
||||||
|
|||||||
@ -500,15 +500,14 @@ class TCPSocketStreamTest(unittest.TestCase):
|
|||||||
path = self.path.split("/")[-1]
|
path = self.path.split("/")[-1]
|
||||||
if path == "tty":
|
if path == "tty":
|
||||||
return stdout_data + stderr_data
|
return stdout_data + stderr_data
|
||||||
elif path == "no-tty":
|
if path == "no-tty":
|
||||||
data = b""
|
data = b""
|
||||||
data += self.frame_header(1, stdout_data)
|
data += self.frame_header(1, stdout_data)
|
||||||
data += stdout_data
|
data += stdout_data
|
||||||
data += self.frame_header(2, stderr_data)
|
data += self.frame_header(2, stderr_data)
|
||||||
data += stderr_data
|
data += stderr_data
|
||||||
return data
|
return data
|
||||||
else:
|
raise NotImplementedError(f"Unknown path {path}")
|
||||||
raise NotImplementedError(f"Unknown path {path}")
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def frame_header(stream, data):
|
def frame_header(stream, data):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user