【问题标题】:template schema importing all the files in a folder模板模式导入文件夹中的所有文件
【发布时间】:2018-08-07 15:13:13
【问题描述】:

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

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

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

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

【问题讨论】:

  • 模板名称和路径必须以文件扩展名结尾。此时无法将所有文件一起导入。我建议您在我们的公共issue tracker 中提出功能请求。
  • @Milad 有什么解决方法吗?导入文件时它在做什么?如何以编程方式完成?

标签: google-deployment-manager


【解决方案1】:

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

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

middleware-like python 模板中执行如下操作:

# 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,
  }

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

【讨论】:

    猜你喜欢
    • 2016-11-04
    • 1970-01-01
    • 2018-08-17
    • 1970-01-01
    • 2016-08-02
    • 2019-01-25
    • 1970-01-01
    • 1970-01-01
    • 2018-09-09
    相关资源
    最近更新 更多