1

这是架构文件中的一个部分

   imports:
    - path: configs/folder1/resources/gcpresource/test/*

我正在尝试使用模板的架构文件导入文件夹中的所有文件。我知道这不起作用。

我的问题是,有什么更好的方法来使用 * 或其他合适的方式导入所有文件,以便部署管理器可以导入文件夹中的所有文件而无需明确指定它们?

4

1 回答 1

0

如果它们都是 yaml 配置文件,你可以在 python 中这样做

# my-template.yaml
imports:
- path: omni-importer.py

middleware-likepython 模板中执行以下操作:

# omni-importer.py
import yaml
from os import listdir
from os.path import isfile, join
def generate_config(ctx):
  mypath = ctx.properties['path']
  files = [f for f in listdir(mypath) if isfile(join(mypath, f)) and f.endswith('yaml')]
  yamls = map(lambda f: yaml.load(open('test.txt')['resources']), files)
  return {
    'resources': yamls,
  }

这不是工作代码,而是概念证明

于 2019-01-16T12:57:36.317 回答