cddeploymentmanager-samples/examples/v2/step_by_step_guide/step6_use_multiple_templates/python
nanocompute-engine-template.py# use your preferred text editor
# Copyright 2016 Google Inc. All rights reserved.## Licensed under the Apache License, Version 2.0 (the "License");# you may not use this file except in compliance with the License.# You may obtain a copy of the License at## http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing, software# distributed under the License is distributed on an "AS IS" BASIS,# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# See the License for the specific language governing permissions and# limitations under the License."""Creates the Compute Engine."""defGenerateConfig(context):"""Creates the Compute Engine with network and firewall."""resources=[{'name':'vm-1','type':'vm-template.py'},{'name':'vm-2','type':'vm-template-2.py'},{'name':'network-1','type':'network-template.py'},{'name':'firewall-1','type':'firewall-template.py'}]return{'resources':resources}
查看配置
打开部署的配置文件:
cddeploymentmanager-samples/examples/v2/step_by_step_guide/step6_use_multiple_templates/python
nanoconfig-with-many-templates.yaml# use your preferred text editor
# Copyright 2016 Google Inc. All rights reserved.## Licensed under the Apache License, Version 2.0 (the "License");# you may not use this file except in compliance with the License.# You may obtain a copy of the License at## http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing, software# distributed under the License is distributed on an "AS IS" BASIS,# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# See the License for the specific language governing permissions and# limitations under the License.imports:-path:vm-template.py-path:vm-template-2.py-path:network-template.py-path:firewall-template.py-path:compute-engine-template.pyresources:-name:compute-engine-setuptype:compute-engine-template.py
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-19。"],[[["\u003cp\u003eThis step involves exploring a template, \u003ccode\u003ecompute-engine-template.py\u003c/code\u003e, which imports other templates to manage various resources within a deployment.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003ecompute-engine-template.py\u003c/code\u003e imports templates such as \u003ccode\u003evm-template.py\u003c/code\u003e, \u003ccode\u003evm-template-2.py\u003c/code\u003e, \u003ccode\u003enetwork-template.py\u003c/code\u003e, and \u003ccode\u003efirewall-template.py\u003c/code\u003e to create virtual machines, a network, and a firewall rule.\u003c/p\u003e\n"],["\u003cp\u003eThe configuration file, \u003ccode\u003econfig-with-many-templates.yaml\u003c/code\u003e, only needs to call \u003ccode\u003ecompute-engine-template.py\u003c/code\u003e, as this template handles the importing of the other templates.\u003c/p\u003e\n"],["\u003cp\u003eDeploying the configuration is done using the command \u003ccode\u003egcloud deployment-manager deployments create deployment-with-many-templates --config config-with-many-templates.yaml\u003c/code\u003e, and the deployment can be deleted later with the delete command.\u003c/p\u003e\n"]]],[],null,[]]