From 89f60e39f359d0212461dbbcd2e7acf5e37d9622 Mon Sep 17 00:00:00 2001 From: Melih Elibol Date: Wed, 1 Aug 2018 14:16:57 -0400 Subject: [PATCH] Override user-specified name tag. (#2480) Override user-specified name tag. --- python/ray/autoscaler/aws/node_provider.py | 28 ++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/python/ray/autoscaler/aws/node_provider.py b/python/ray/autoscaler/aws/node_provider.py index 3fb19632a..c756d9afd 100644 --- a/python/ray/autoscaler/aws/node_provider.py +++ b/python/ray/autoscaler/aws/node_provider.py @@ -126,6 +126,29 @@ class AWSNodeProvider(NodeProvider): "Key": k, "Value": v, }) + tag_specs = [{ + "ResourceType": "instance", + "Tags": tag_pairs, + }] + user_tag_specs = conf.get("TagSpecifications", []) + # Allow users to add tags and override values of existing + # tags with their own. This only applies to the resource type + # "instance". All other resource types are appended to the list of + # tag specs. + for user_tag_spec in user_tag_specs: + if user_tag_spec["ResourceType"] == "instance": + for user_tag in user_tag_spec["Tags"]: + exists = False + for tag in tag_specs[0]["Tags"]: + if user_tag["Key"] == tag["Key"]: + exists = True + tag["Value"] = user_tag["Value"] + break + if not exists: + tag_specs[0]["Tags"] += [user_tag] + else: + tag_specs += [user_tag_spec] + # SubnetIds is not a real config key: we must resolve to a # single SubnetId before invoking the AWS API. subnet_ids = conf.pop("SubnetIds") @@ -135,10 +158,7 @@ class AWSNodeProvider(NodeProvider): "MinCount": 1, "MaxCount": count, "SubnetId": subnet_id, - "TagSpecifications": conf.get("TagSpecifications", []) + [{ - "ResourceType": "instance", - "Tags": tag_pairs, - }] + "TagSpecifications": tag_specs }) self.ec2.create_instances(**conf)