mirror of
https://github.com/wassname/ray.git
synced 2026-08-13 12:30:18 +08:00
Lint Python files with Yapf (#1872)
This commit is contained in:
committed by
Robert Nishihara
parent
a3ddde398c
commit
74162d1492
@@ -25,12 +25,10 @@ assert StrictVersion(boto3.__version__) >= StrictVersion("1.4.8"), \
|
||||
def key_pair(i, region):
|
||||
"""Returns the ith default (aws_key_pair_name, key_pair_path)."""
|
||||
if i == 0:
|
||||
return (
|
||||
"{}_{}".format(RAY, region),
|
||||
os.path.expanduser("~/.ssh/{}_{}.pem".format(RAY, region)))
|
||||
return (
|
||||
"{}_{}_{}".format(RAY, i, region),
|
||||
os.path.expanduser("~/.ssh/{}_{}_{}.pem".format(RAY, i, region)))
|
||||
return ("{}_{}".format(RAY, region),
|
||||
os.path.expanduser("~/.ssh/{}_{}.pem".format(RAY, region)))
|
||||
return ("{}_{}_{}".format(RAY, i, region),
|
||||
os.path.expanduser("~/.ssh/{}_{}_{}.pem".format(RAY, i, region)))
|
||||
|
||||
|
||||
# Suppress excessive connection dropped logs from boto
|
||||
@@ -83,7 +81,9 @@ def _configure_iam_role(config):
|
||||
"Statement": [
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Principal": {"Service": "ec2.amazonaws.com"},
|
||||
"Principal": {
|
||||
"Service": "ec2.amazonaws.com"
|
||||
},
|
||||
"Action": "sts:AssumeRole",
|
||||
},
|
||||
],
|
||||
@@ -97,8 +97,7 @@ def _configure_iam_role(config):
|
||||
profile.add_role(RoleName=role.name)
|
||||
time.sleep(15) # wait for propagation
|
||||
|
||||
print("Role not specified for head node, using {}".format(
|
||||
profile.arn))
|
||||
print("Role not specified for head node, using {}".format(profile.arn))
|
||||
config["head_node"]["IamInstanceProfile"] = {"Arn": profile.arn}
|
||||
|
||||
return config
|
||||
@@ -146,8 +145,10 @@ def _configure_key_pair(config):
|
||||
def _configure_subnet(config):
|
||||
ec2 = _resource("ec2", config)
|
||||
subnets = sorted(
|
||||
[s for s in ec2.subnets.all()
|
||||
if s.state == "available" and s.map_public_ip_on_launch],
|
||||
[
|
||||
s for s in ec2.subnets.all()
|
||||
if s.state == "available" and s.map_public_ip_on_launch
|
||||
],
|
||||
reverse=True, # sort from Z-A
|
||||
key=lambda subnet: subnet.availability_zone)
|
||||
if not subnets:
|
||||
@@ -157,9 +158,9 @@ def _configure_subnet(config):
|
||||
"and trying this again. Note that the subnet must map public IPs "
|
||||
"on instance launch.")
|
||||
if "availability_zone" in config["provider"]:
|
||||
default_subnet = next((s for s in subnets
|
||||
if s.availability_zone ==
|
||||
config["provider"]["availability_zone"]),
|
||||
default_subnet = next((
|
||||
s for s in subnets
|
||||
if s.availability_zone == config["provider"]["availability_zone"]),
|
||||
None)
|
||||
if not default_subnet:
|
||||
raise Exception(
|
||||
@@ -209,11 +210,21 @@ def _configure_security_group(config):
|
||||
|
||||
if not security_group.ip_permissions:
|
||||
security_group.authorize_ingress(
|
||||
IpPermissions=[
|
||||
{"FromPort": -1, "ToPort": -1, "IpProtocol": "-1",
|
||||
"UserIdGroupPairs": [{"GroupId": security_group.id}]},
|
||||
{"FromPort": 22, "ToPort": 22, "IpProtocol": "TCP",
|
||||
"IpRanges": [{"CidrIp": "0.0.0.0/0"}]}])
|
||||
IpPermissions=[{
|
||||
"FromPort": -1,
|
||||
"ToPort": -1,
|
||||
"IpProtocol": "-1",
|
||||
"UserIdGroupPairs": [{
|
||||
"GroupId": security_group.id
|
||||
}]
|
||||
}, {
|
||||
"FromPort": 22,
|
||||
"ToPort": 22,
|
||||
"IpProtocol": "TCP",
|
||||
"IpRanges": [{
|
||||
"CidrIp": "0.0.0.0/0"
|
||||
}]
|
||||
}])
|
||||
|
||||
if "SecurityGroupIds" not in config["head_node"]:
|
||||
print("SecurityGroupIds not specified for head node, using {}".format(
|
||||
@@ -231,8 +242,10 @@ def _configure_security_group(config):
|
||||
def _get_subnet_or_die(config, subnet_id):
|
||||
ec2 = _resource("ec2", config)
|
||||
subnet = list(
|
||||
ec2.subnets.filter(Filters=[
|
||||
{"Name": "subnet-id", "Values": [subnet_id]}]))
|
||||
ec2.subnets.filter(Filters=[{
|
||||
"Name": "subnet-id",
|
||||
"Values": [subnet_id]
|
||||
}]))
|
||||
assert len(subnet) == 1, "Subnet not found"
|
||||
subnet = subnet[0]
|
||||
return subnet
|
||||
@@ -241,8 +254,10 @@ def _get_subnet_or_die(config, subnet_id):
|
||||
def _get_security_group(config, vpc_id, group_name):
|
||||
ec2 = _resource("ec2", config)
|
||||
existing_groups = list(
|
||||
ec2.security_groups.filter(Filters=[
|
||||
{"Name": "vpc-id", "Values": [vpc_id]}]))
|
||||
ec2.security_groups.filter(Filters=[{
|
||||
"Name": "vpc-id",
|
||||
"Values": [vpc_id]
|
||||
}]))
|
||||
for sg in existing_groups:
|
||||
if sg.group_name == group_name:
|
||||
return sg
|
||||
@@ -270,8 +285,10 @@ def _get_instance_profile(profile_name, config):
|
||||
|
||||
def _get_key(key_name, config):
|
||||
ec2 = _resource("ec2", config)
|
||||
for key in ec2.key_pairs.filter(
|
||||
Filters=[{"Name": "key-name", "Values": [key_name]}]):
|
||||
for key in ec2.key_pairs.filter(Filters=[{
|
||||
"Name": "key-name",
|
||||
"Values": [key_name]
|
||||
}]):
|
||||
if key.name == key_name:
|
||||
return key
|
||||
|
||||
|
||||
@@ -84,7 +84,8 @@ class AWSNodeProvider(NodeProvider):
|
||||
tag_pairs = []
|
||||
for k, v in tags.items():
|
||||
tag_pairs.append({
|
||||
"Key": k, "Value": v,
|
||||
"Key": k,
|
||||
"Value": v,
|
||||
})
|
||||
node.create_tags(Tags=tag_pairs)
|
||||
|
||||
@@ -95,20 +96,20 @@ class AWSNodeProvider(NodeProvider):
|
||||
"Value": self.cluster_name,
|
||||
}]
|
||||
for k, v in tags.items():
|
||||
tag_pairs.append(
|
||||
{
|
||||
"Key": k,
|
||||
"Value": v,
|
||||
})
|
||||
tag_pairs.append({
|
||||
"Key": k,
|
||||
"Value": v,
|
||||
})
|
||||
conf.update({
|
||||
"MinCount": 1,
|
||||
"MaxCount": count,
|
||||
"TagSpecifications": conf.get("TagSpecifications", []) + [
|
||||
{
|
||||
"ResourceType": "instance",
|
||||
"Tags": tag_pairs,
|
||||
}
|
||||
]
|
||||
"MinCount":
|
||||
1,
|
||||
"MaxCount":
|
||||
count,
|
||||
"TagSpecifications":
|
||||
conf.get("TagSpecifications", []) + [{
|
||||
"ResourceType": "instance",
|
||||
"Tags": tag_pairs,
|
||||
}]
|
||||
})
|
||||
self.ec2.create_instances(**conf)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user