Make the salt client call in the new fasion chunked multi-call way
(self)
| 153 | return local.cmd(*args) |
| 154 | |
| 155 | def run_chunked(self): |
| 156 | """ |
| 157 | Make the salt client call in the new fasion chunked multi-call way |
| 158 | """ |
| 159 | files, empty_dirs = self._list_files() |
| 160 | dest = self.opts["dest"] |
| 161 | gzip = self.opts["gzip"] |
| 162 | tgt = self.opts["tgt"] |
| 163 | timeout = self.opts["timeout"] |
| 164 | selected_target_option = self.opts.get("selected_target_option") |
| 165 | |
| 166 | dest_is_dir = ( |
| 167 | bool(empty_dirs) or len(files) > 1 or bool(re.search(r"[\\/]$", dest)) |
| 168 | ) |
| 169 | |
| 170 | reader = ( |
| 171 | salt.utils.gzip_util.compress_file |
| 172 | if gzip |
| 173 | else salt.utils.itertools.read_file |
| 174 | ) |
| 175 | |
| 176 | _res = salt.utils.minions.CkMinions(self.opts).check_minions( |
| 177 | tgt, tgt_type=selected_target_option or "glob" |
| 178 | ) |
| 179 | minions = _res["minions"] |
| 180 | |
| 181 | def _get_remote_path(fn_): |
| 182 | if fn_ in self.opts["src"]: |
| 183 | # This was a filename explicitly passed on the CLI |
| 184 | return ( |
| 185 | os.path.join(dest, os.path.basename(fn_)) if dest_is_dir else dest |
| 186 | ) |
| 187 | else: |
| 188 | for path in self.opts["src"]: |
| 189 | relpath = os.path.relpath(fn_, path + os.sep) |
| 190 | if relpath.startswith(parent): |
| 191 | # File is not within this dir |
| 192 | continue |
| 193 | return os.path.join(dest, os.path.basename(path), relpath) |
| 194 | else: # pylint: disable=useless-else-on-loop |
| 195 | # Should not happen |
| 196 | log.error("Failed to find remote path for %s", fn_) |
| 197 | return None |
| 198 | |
| 199 | ret = {} |
| 200 | parent = ".." + os.sep |
| 201 | |
| 202 | with salt.client.get_local_client(self.opts["conf_file"]) as local: |
| 203 | for fn_, mode in files.items(): |
| 204 | remote_path = _get_remote_path(fn_) |
| 205 | |
| 206 | index = 1 |
| 207 | failed = {} |
| 208 | for chunk in reader(fn_, chunk_size=self.opts["salt_cp_chunk_size"]): |
| 209 | chunk = base64.b64encode(salt.utils.stringutils.to_bytes(chunk)) |
| 210 | append = index > 1 |
| 211 | log.debug( |
| 212 | "Copying %s to %starget '%s' as %s%s", |
no test coverage detected