我们有一个批处理标记器,用于处理新创建资源的活动日志,然后我们将标签应用于计费目的。我们正在尝试以这种方式自动标记我们的部署,因为我们发现失败的部署正在累积并产生相当数量的成本。我的问题是我无法标记部署。
我需要向部署添加全局标签,但我以编程方式尝试的所有内容似乎都不起作用。
我尝试使用这样的现有配置:
manifests = self.deploymentManagerService.manifests().list(project=project,
deployment=deployment_name).execute()
config = manifests['manifests'][0]['config']
...
content_dict = eval(json.dumps(json.loads(config['content'])))
output = StringIO.StringIO()
yaml.dump(content_dict, output, encoding=None)
body = {'labels': labels, 'fingerprint': fingerprint, 'name': deployment_name, 'target': {'config': { 'content': output.getvalue()}}}
print "BODY=", body
deploymentManagerService.deployments().patch(project=project,
deployment=deployment_name,
body=body).execute()
这正确地标记了部署,但由于路径问题而在更新中出错。
我尝试了一个空的资源部分:
body = {'labels': labels, 'fingerprint': fingerprint, 'name': deployment_name, 'target': {'config': { 'content': 'resources:\n'}}}
这会标记部署,但会清除配置(不好)。
我没有尝试任何配置或目标并得到 400。我不知所措。
无需获取清单。使用patch
是正确的想法,但您需要添加一个额外的标题。下面是一个例子:
dep = self.deploymentManagerService.deployments().get(
deployment=deployment, project=project).execute()
body = {'labels': [{'key': 'foo', 'value': 'bar'}],
'fingerprint': dep['fingerprint']}
req = self.deploymentManagerService.deployments().patch(
project=project, deployment=deployment, body=body)
# This header is required for patch requests to work correctly.
req.headers['X-Cloud-DM-Patch'] = 'True'
res = req.execute()
此外,您可能希望:
execute
结束返回的长时间运行的操作。本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句