-
Notifications
You must be signed in to change notification settings - Fork 529
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[AWS] Support targeted on-demand capacity reservations (#3852)
* wip Allow prioritize reservations format Allow open capacity reservations Add check reserved resources format Remove specific reservations * parent fcf1f60 author Zhanghao Wu <[email protected]> 1724175607 +0000 committer Zhanghao Wu <[email protected]> 1724210666 +0000 wip Allow prioritize reservations format Add check reserved resources format * Support target capacity reservation provisioning * Fix comments * Add doc * format
- Loading branch information
1 parent
40749e3
commit 1cd2444
Showing
9 changed files
with
257 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
"""Utilities for AWS.""" | ||
import dataclasses | ||
import time | ||
from typing import List | ||
|
||
import cachetools | ||
|
||
from sky import skypilot_config | ||
from sky.adaptors import aws | ||
|
||
|
||
@dataclasses.dataclass | ||
class AWSReservation: | ||
name: str | ||
instance_type: str | ||
zone: str | ||
available_resources: int | ||
# Whether the reservation is targeted, i.e. can only be consumed when | ||
# the reservation name is specified. | ||
targeted: bool | ||
|
||
|
||
def use_reservations() -> bool: | ||
prioritize_reservations = skypilot_config.get_nested( | ||
('aws', 'prioritize_reservations'), False) | ||
specific_reservations = skypilot_config.get_nested( | ||
('aws', 'specific_reservations'), set()) | ||
return prioritize_reservations or specific_reservations | ||
|
||
|
||
@cachetools.cached(cache=cachetools.TTLCache(maxsize=100, | ||
ttl=300, | ||
timer=time.time)) | ||
def list_reservations_for_instance_type( | ||
instance_type: str, | ||
region: str, | ||
) -> List[AWSReservation]: | ||
if not use_reservations(): | ||
return [] | ||
ec2 = aws.client('ec2', region_name=region) | ||
response = ec2.describe_capacity_reservations(Filters=[{ | ||
'Name': 'instance-type', | ||
'Values': [instance_type] | ||
}, { | ||
'Name': 'state', | ||
'Values': ['active'] | ||
}]) | ||
reservations = response['CapacityReservations'] | ||
return [ | ||
AWSReservation( | ||
name=r['CapacityReservationId'], | ||
instance_type=r['InstanceType'], | ||
zone=r['AvailabilityZone'], | ||
available_resources=r['AvailableInstanceCount'], | ||
targeted=r['InstanceMatchCriteria'] == 'targeted', | ||
) for r in reservations | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.