Skip to content

Commit

Permalink
Default to zonal bulkInsert
Browse files Browse the repository at this point in the history
  • Loading branch information
mr0re1 committed Sep 5, 2024
1 parent 4fac295 commit ad3f3db
Showing 1 changed file with 13 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,16 +159,12 @@ def create_instances_request(nodes, partition_name, placement_group, job_id=None
# key is instance name, value overwrites properties
body.perInstanceProperties = {k: per_instance_properties(k) for k in nodes}

zone_allow = nodeset.zone_policy_allow or []
zone_deny = nodeset.zone_policy_deny or []
body.locationPolicy.locations = {
**{
f"zones/{zone}": {"preference": "ALLOW"}
for zone in nodeset.zone_policy_allow or []
},
**{
f"zones/{zone}": {"preference": "DENY"}
for zone in nodeset.zone_policy_deny or []
},
}
**{ f"zones/{z}": {"preference": "ALLOW"} for z in zone_allow },
**{ f"zones/{z}": {"preference": "DENY"} for z in zone_deny }}

body.locationPolicy.targetShape = nodeset.zone_target_shape

if lookup().cfg.enable_slurm_gcp_plugins:
Expand All @@ -179,14 +175,15 @@ def create_instances_request(nodes, partition_name, placement_group, job_id=None
request_body=body,
)

request = lookup().compute.regionInstances().bulkInsert(
project=lookup().project, region=region, body=body.to_dict()
)
api_args = dict(
project=lookup().project, region=region, body=body.to_dict())

if log.isEnabledFor(logging.DEBUG):
log.debug(
f"new request: endpoint={request.methodId} nodes={to_hostlist_fast(nodes)}"
)
if len(zone_allow) == 1: # if only one zone is used, use zonal BulkInsert API, as less prone to errors
request = lookup().compute.instances().bulkInsert(**api_args, zone=zone_allow[0])
else:
request = lookup().compute.regionInstances().bulkInsert(**api_args)

log.debug(f"new request: endpoint={request.methodId} nodes={to_hostlist_fast(nodes)}")
log_api_request(request)
return request

Expand Down

0 comments on commit ad3f3db

Please sign in to comment.