Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google api GCP VM部署:如何在创建VM时动态更新yaml配置属性_Google Api_Google Cloud Platform_Gcloud_Google Api Nodejs Client_Google Deployment Manager - Fatal编程技术网

Google api GCP VM部署:如何在创建VM时动态更新yaml配置属性

Google api GCP VM部署:如何在创建VM时动态更新yaml配置属性,google-api,google-cloud-platform,gcloud,google-api-nodejs-client,google-deployment-manager,Google Api,Google Cloud Platform,Gcloud,Google Api Nodejs Client,Google Deployment Manager,我们有一个nodejs应用程序,它使用配置文件(.yaml)和模板在GCP上创建VM。现在,我想在创建VM时根据用户从UI输入更新yaml/模板中的几个属性。如何动态更新配置属性?提前感谢您的建议。GCP部署管理器无法动态执行此操作。您必须添加一个附加层(如单击部署市场),允许用户在应用配置文件之前选择变量。DM没有这样做的功能。GCP部署管理器没有动态执行此操作的方法。您必须添加一个附加层(如单击部署市场),允许用户在应用配置文件之前选择变量。DM没有这样的功能。您似乎有两种选择: 1) ji

我们有一个nodejs应用程序,它使用配置文件(.yaml)和模板在GCP上创建VM。现在,我想在创建VM时根据用户从UI输入更新yaml/模板中的几个属性。如何动态更新配置属性?提前感谢您的建议。

GCP部署管理器无法动态执行此操作。您必须添加一个附加层(如单击部署市场),允许用户在应用配置文件之前选择变量。DM没有这样做的功能。

GCP部署管理器没有动态执行此操作的方法。您必须添加一个附加层(如单击部署市场),允许用户在应用配置文件之前选择变量。DM没有这样的功能。

您似乎有两种选择:

1) jinja模板方式 您可以定义jinja模板,而不是配置文件: 资源:

# my-template.jinja
resources:
- name: my-resource
  type: some-type
  properties:
    prop1: {{ properties['foo'] }}
    prop2: {{ properties['bar'] }}
然后,您可以像这样调用它,变量foo和bar将映射到提供的属性:

gcloud deployment-manager deployments create <my-deployment> \
  --template my-template.jinja \
  --properties foo:user-custom-value,bar:another-value
如果您正在运行shell脚本,或者从node/javascript本身,可以使用
sed
替换文本

const replaces = [
  {name: 'REPLACE-PROP-1', value: 'user-custom-value'},
  {name: 'REPLACE-PROP-2', value: 'another-custom-value'},
];
const templateYaml = fs.readFileSync('my-template.yaml','utf-8');
const customYaml = replaces
  .map(r => templateYaml.replace(RegExp(r.name,'g'), r.value);
或者使用sed

sed -ie 's/REPLACE-PROP-1/user-custom-value/g' my-template.yaml
sed -ie 's/REPLACE-PROP-2/another-cst-value/g' my-template.yaml
最后部署配置

gcloud deployment-manager deployments create <my-deployment> \
  --config my-template.yaml
gcloud部署管理器部署创建\
--配置my-template.yaml

您似乎有两个选择:

1) jinja模板方式 您可以定义jinja模板,而不是配置文件: 资源:

# my-template.jinja
resources:
- name: my-resource
  type: some-type
  properties:
    prop1: {{ properties['foo'] }}
    prop2: {{ properties['bar'] }}
然后,您可以像这样调用它,变量foo和bar将映射到提供的属性:

gcloud deployment-manager deployments create <my-deployment> \
  --template my-template.jinja \
  --properties foo:user-custom-value,bar:another-value
如果您正在运行shell脚本,或者从node/javascript本身,可以使用
sed
替换文本

const replaces = [
  {name: 'REPLACE-PROP-1', value: 'user-custom-value'},
  {name: 'REPLACE-PROP-2', value: 'another-custom-value'},
];
const templateYaml = fs.readFileSync('my-template.yaml','utf-8');
const customYaml = replaces
  .map(r => templateYaml.replace(RegExp(r.name,'g'), r.value);
或者使用sed

sed -ie 's/REPLACE-PROP-1/user-custom-value/g' my-template.yaml
sed -ie 's/REPLACE-PROP-2/another-cst-value/g' my-template.yaml
最后部署配置

gcloud deployment-manager deployments create <my-deployment> \
  --config my-template.yaml
gcloud部署管理器部署创建\
--配置my-template.yaml