mirror of
https://github.com/wassname/ray.git
synced 2026-08-13 12:30:18 +08:00
[autoscaler] Cleanup Logging (#2709)
Moves Autoscaler onto Python `logging` module.
This commit is contained in:
@@ -33,6 +33,7 @@ def key_pair(i, region):
|
||||
|
||||
# Suppress excessive connection dropped logs from boto
|
||||
logging.getLogger("botocore").setLevel(logging.WARNING)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def bootstrap_aws(config):
|
||||
@@ -60,7 +61,7 @@ def _configure_iam_role(config):
|
||||
profile = _get_instance_profile(DEFAULT_RAY_INSTANCE_PROFILE, config)
|
||||
|
||||
if profile is None:
|
||||
print("Creating new instance profile {}".format(
|
||||
logger.info("Creating new instance profile {}".format(
|
||||
DEFAULT_RAY_INSTANCE_PROFILE))
|
||||
client = _client("iam", config)
|
||||
client.create_instance_profile(
|
||||
@@ -73,7 +74,7 @@ def _configure_iam_role(config):
|
||||
if not profile.roles:
|
||||
role = _get_role(DEFAULT_RAY_IAM_ROLE, config)
|
||||
if role is None:
|
||||
print("Creating new role {}".format(DEFAULT_RAY_IAM_ROLE))
|
||||
logger.info("Creating new role {}".format(DEFAULT_RAY_IAM_ROLE))
|
||||
iam = _resource("iam", config)
|
||||
iam.create_role(
|
||||
RoleName=DEFAULT_RAY_IAM_ROLE,
|
||||
@@ -97,7 +98,8 @@ 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))
|
||||
logger.info("Role not specified for head node, using {}".format(
|
||||
profile.arn))
|
||||
config["head_node"]["IamInstanceProfile"] = {"Arn": profile.arn}
|
||||
|
||||
return config
|
||||
@@ -122,7 +124,7 @@ def _configure_key_pair(config):
|
||||
|
||||
# We can safely create a new key.
|
||||
if not key and not os.path.exists(key_path):
|
||||
print("Creating new key pair {}".format(key_name))
|
||||
logger.info("Creating new key pair {}".format(key_name))
|
||||
key = ec2.create_key_pair(KeyName=key_name)
|
||||
with open(key_path, "w") as f:
|
||||
f.write(key.key_material)
|
||||
@@ -133,7 +135,7 @@ def _configure_key_pair(config):
|
||||
assert os.path.exists(key_path), \
|
||||
"Private key file {} not found for {}".format(key_path, key_name)
|
||||
|
||||
print("KeyName not specified for nodes, using {}".format(key_name))
|
||||
logger.info("KeyName not specified for nodes, using {}".format(key_name))
|
||||
|
||||
config["auth"]["ssh_private_key"] = key_path
|
||||
config["head_node"]["KeyName"] = key_name
|
||||
@@ -170,11 +172,13 @@ def _configure_subnet(config):
|
||||
subnet_descr = [(s.subnet_id, s.availability_zone) for s in subnets]
|
||||
if "SubnetIds" not in config["head_node"]:
|
||||
config["head_node"]["SubnetIds"] = subnet_ids
|
||||
print("SubnetIds not specified for head node, using ", subnet_descr)
|
||||
logger.info("SubnetIds not specified for head node,"
|
||||
" using {}".format(subnet_descr))
|
||||
|
||||
if "SubnetIds" not in config["worker_nodes"]:
|
||||
config["worker_nodes"]["SubnetIds"] = subnet_ids
|
||||
print("SubnetId not specified for workers, using ", subnet_descr)
|
||||
logger.info("SubnetId not specified for workers,"
|
||||
" using {}".format(subnet_descr))
|
||||
|
||||
return config
|
||||
|
||||
@@ -189,7 +193,7 @@ def _configure_security_group(config):
|
||||
security_group = _get_security_group(config, vpc_id, group_name)
|
||||
|
||||
if security_group is None:
|
||||
print("Creating new security group {}".format(group_name))
|
||||
logger.info("Creating new security group {}".format(group_name))
|
||||
client = _client("ec2", config)
|
||||
client.create_security_group(
|
||||
Description="Auto-created security group for Ray workers",
|
||||
@@ -216,13 +220,15 @@ def _configure_security_group(config):
|
||||
}])
|
||||
|
||||
if "SecurityGroupIds" not in config["head_node"]:
|
||||
print("SecurityGroupIds not specified for head node, using {}".format(
|
||||
security_group.group_name))
|
||||
logger.info(
|
||||
"SecurityGroupIds not specified for head node, using {}".format(
|
||||
security_group.group_name))
|
||||
config["head_node"]["SecurityGroupIds"] = [security_group.id]
|
||||
|
||||
if "SecurityGroupIds" not in config["worker_nodes"]:
|
||||
print("SecurityGroupIds not specified for workers, using {}".format(
|
||||
security_group.group_name))
|
||||
logger.info(
|
||||
"SecurityGroupIds not specified for workers, using {}".format(
|
||||
security_group.group_name))
|
||||
config["worker_nodes"]["SecurityGroupIds"] = [security_group.id]
|
||||
|
||||
return config
|
||||
|
||||
Reference in New Issue
Block a user