Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions python/ray/autoscaler/aws/node_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,28 @@
from botocore.config import Config

from ray.autoscaler.node_provider import NodeProvider
from ray.autoscaler.tags import TAG_RAY_CLUSTER_NAME
from ray.autoscaler.tags import TAG_RAY_CLUSTER_NAME, TAG_RAY_NODE_NAME
from ray.ray_constants import BOTO_MAX_RETRIES


def to_aws_format(tags):
"""Convert the Ray node name tag to the AWS-specific 'Name' tag."""

if TAG_RAY_NODE_NAME in tags:
tags["Name"] = tags[TAG_RAY_NODE_NAME]
del tags[TAG_RAY_NODE_NAME]
return tags


def from_aws_format(tags):
"""Convert the AWS-specific 'Name' tag to the Ray node name tag."""

if "Name" in tags:
tags[TAG_RAY_NODE_NAME] = tags["Name"]
del tags["Name"]
return tags


class AWSNodeProvider(NodeProvider):
def __init__(self, provider_config, cluster_name):
NodeProvider.__init__(self, provider_config, cluster_name)
Expand All @@ -26,6 +44,7 @@ def __init__(self, provider_config, cluster_name):
self.external_ip_cache = {}

def nodes(self, tag_filters):
tag_filters = to_aws_format(tag_filters)
filters = [
{
"Name": "instance-state-name",
Expand Down Expand Up @@ -59,7 +78,7 @@ def node_tags(self, node_id):
tags = {}
for tag in node.tags:
tags[tag["Key"]] = tag["Value"]
return tags
return from_aws_format(tags)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need this for this method in particular? ie, why not have this for all methods where you call to_aws_format?

tags is a dict and is passed by ref; so every time you call to_aws_format you end up modifying the original...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only one that returns tags?

And yes, the mutation is fine.


def external_ip(self, node_id):
if node_id in self.external_ip_cache:
Expand All @@ -80,6 +99,7 @@ def internal_ip(self, node_id):
return ip

def set_node_tags(self, node_id, tags):
tags = to_aws_format(tags)
node = self._node(node_id)
tag_pairs = []
for k, v in tags.items():
Expand All @@ -90,6 +110,7 @@ def set_node_tags(self, node_id, tags):
node.create_tags(Tags=tag_pairs)

def create_node(self, node_config, tags, count):
tags = to_aws_format(tags)
conf = node_config.copy()
tag_pairs = [{
"Key": TAG_RAY_CLUSTER_NAME,
Expand Down