def _inject_files(self, inject_files, plain=False): container_id = self.container['id'] try: for (path, content_base64) in inject_files: # Ensure the parent dir of injecting file exists dirname = os.path.dirname(path) if not dirname: dirname = '/' filename = os.path.basename(path) content = content_base64 if plain else base64.b64decode( content_base64) LOG.debug(_("Inject file %s, content: len = %d, partial = %s"), path, len(content), content[:30]) # TODO: file already exists in the container, need to backup? self.manager.inject_file(container_id, path, content) except TypeError as e: # invalid base64 encode LOG.exception(e) raise exception.InjectFailed(path=path, reason="contents %s" % e.message) except Exception as e: LOG.exception(e) raise exception.InjectFailed(path='', reason=repr(e) + str(e.message))
def personality(self, request, dst_path, file_data): dst_dir = os.path.dirname(dst_path) if not os.path.isdir(dst_dir): os.makedirs(dst_dir) LOG.info("get personality with dst path:%s", dst_path) injected = False with open(dst_path, "wb") as dst: dst.write(base64.b64decode(file_data)) injected = True if not injected: raise exception.InjectFailed(path=dst_path) return webob.Response(status_int=204)
def inject_files(self, request, inject_files): LOG.debug("inject files %s", inject_files) for (path, contents) in inject_files: # Ensure the parent dir of injecting file exists parent_dir = os.path.dirname(path) container_id = self.container['id'] # TODO For docker container the address is modified if (len(parent_dir) > 0 and os.path.isdir(parent_dir)): injected = False with open(path, "wb") as dst: dst.write(contents) injected = True if not injected: raise exception.InjectFailed(path=path) return webob.Response(status_int=200)