gcloud CLI flags-file中配置重复字典类型参数(如--boost-config、--allowed-ports)失败的问题求助
大家好,我现在在用gcloud CLI创建新的Workstation配置,为了简化配置管理,想用yaml配置文件来指定参数值。基础的Workstation配置用这种方式能成功创建,但遇到两个重复字典类型的参数——--allowed-ports和--boost-config时,怎么都配置不成功。
先说说--boost-config,它是个至少包含id和machine-type字段的字典参数。如果直接在命令行里加单个或多个该参数,是完全没问题的:
# 单个boost-config可以成功创建 gcloud beta workstations configs create workstation_config --flags-file=config.yaml --boost-config=id=xl,machine-type=e2-standard-8 # 多个boost-config也能成功 gcloud beta workstations configs create workstation_config --flags-file=config.yaml --boost-config=id=xl,machine-type=e2-standard-8 --boost-config=id=xxl,machine-type=e2-standard-16
但只要把哪怕一个boost配置写到yaml文件里,就会报错。比如这样的config.yaml:
... --boost-config: id: xl machine-type: e2-standard-8 ...
得到的错误是:
ERROR: (gcloud.beta.workstations.configs.create) argument --boost-config: invalid <googlecloudsdk.calliope.arg_parsers.ArgObject object at 0x78b11f65deb0> value: {'id': 'xl', 'machine-type': 'e2-standard-8'}
我也试过用列表形式配置多个boost-config,yaml内容如下:
... --boost-config: - id: xl machine-type: e2-standard-8 - id: xxl machine-type: e2-standard-16 ...
结果还是报错:
ERROR: (gcloud.beta.workstations.configs.create) argument --boost-config: invalid <googlecloudsdk.calliope.arg_parsers.ArgObject object at 0x7cfaf64e8d10> value: [{'id': 'xl', 'machine-type': 'e2-standard-8'}, {'id': 'xxl', 'machine-type': 'e2-standard-16'}]
我还尝试过按照gcloud官方关于flags-file的文档思路,用重复键的方式,但这不符合YAML语法,直接解析失败:
... - --boost-config: id: xl machine-type: e2-standard-8 - --boost-config: id: xxl machine-type: e2-standard-16 ...
错误信息是:
ERROR: (gcloud) Failed to parse YAML: while parsing a block mapping
就连直接写重复的--boost-config键也会报重复键错误。
后来我去翻了gcloud CLI的代码,试着把字典转成字符串的方式写在yaml里,单个配置倒是能成功,但这种方式太不优雅了,完全违背了用yaml管理配置的初衷:
... --boost-config: '{"id": "xl", "machine-type": "e2-standard-8"}' ...
而且就算用这种方法,我还是没法配置多个boost-config,--allowed-ports也遇到了一模一样的问题。
有没有大佬能指点一下,我到底哪里没弄对?
内容来源于stack exchange

