MCPcopy
hub / github.com/saltstack/salt / cmd_block

Method cmd_block

salt/client/ssh/__init__.py:2070–2279  ·  view source on GitHub ↗

Prepare the pre-check command to send to the subsystem 1. execute SHIM + command 2. check if SHIM returns a master request or if it completed 3. handle any master request 4. re-execute SHIM + command 5. split SHIM results from command results

(self, is_retry=False)

Source from the content-addressed store, hash-verified

2068 return ret
2069
2070 def cmd_block(self, is_retry=False):
2071 """
2072 Prepare the pre-check command to send to the subsystem
2073
2074 1. execute SHIM + command
2075 2. check if SHIM returns a master request or if it completed
2076 3. handle any master request
2077 4. re-execute SHIM + command
2078 5. split SHIM results from command results
2079 6. return command results
2080 """
2081 # For both thin and relenv, use the shim system
2082 # The shim handles extraction and execution
2083 # For relenv, the shim (SSH_SH_SHIM_RELENV) calls salt-call directly
2084 self.argv = _convert_args(self.argv)
2085 log.debug(
2086 "Performing shimmed, blocking command as follows:\n%s",
2087 " ".join([str(arg) for arg in self.argv]),
2088 )
2089
2090 # For relenv, send minion config via SCP to avoid ARG_MAX issues
2091 # The config file is expected to be at {THIN_DIR}/minion by the shim
2092 if self.opts.get("relenv"):
2093 remote_config_path = f"{self.thin_dir}/minion"
2094
2095 # Check if config file already exists on remote (for nested/wrapper calls)
2096 # This avoids ARG_MAX issues when wrappers create nested Single instances
2097 check_cmd = f"test -f {remote_config_path} && echo exists || echo missing"
2098 check_result = self.shell.exec_cmd(check_cmd)
2099
2100 config_exists = (
2101 check_result[0].strip() == "exists" if check_result[2] == 0 else False
2102 )
2103
2104 if config_exists:
2105 log.debug(
2106 "RELENV: Config file already exists at %s, skipping transfer (nested/wrapper call)",
2107 remote_config_path,
2108 )
2109 else:
2110 # Write minion config to a temporary file
2111 with tempfile.NamedTemporaryFile(
2112 mode="w", delete=False, suffix=".conf"
2113 ) as config_tmp_file:
2114 config_tmp_file.write(self.minion_config)
2115 local_config_path = config_tmp_file.name
2116
2117 try:
2118 # SCP the config file to the target
2119 # makedirs=True ensures the thin_dir exists
2120 log.debug(
2121 "RELENV: Sending minion config to %s:%s",
2122 self.target["host"],
2123 remote_config_path,
2124 )
2125 send_result = self.shell.send(
2126 local_config_path, remote_config_path, makedirs=True
2127 )

Callers 12

runMethod · 0.95
_ssh_stateFunction · 0.95
slsFunction · 0.95
lowFunction · 0.95
highFunction · 0.95
highstateFunction · 0.95
topFunction · 0.95
singleFunction · 0.95
callerMethod · 0.95
_exec_state_pkgFunction · 0.95
grainsFunction · 0.80

Calls 15

deploy_extMethod · 0.95
_cmd_strMethod · 0.95
shim_cmdMethod · 0.95
deployMethod · 0.95
_convert_argsFunction · 0.85
debugMethod · 0.80
exec_cmdMethod · 0.80
unlinkMethod · 0.80
warningMethod · 0.80
traceMethod · 0.80
formatMethod · 0.80

Tested by 1