-
Notifications
You must be signed in to change notification settings - Fork 9
Add quota views for Coral credits and allow setting maximum platform duration #466
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e4bf7be
Added coral credits to quota view
wtripp180901 a8fd186
move to secret ref
wtripp180901 636ea96
Fixed API errors for tenancies without credits
wtripp180901 f11c2f1
Hide infinite quotas with associated coral quotas
wtripp180901 1e96a63
Add human readable names for quotas
wtripp180901 c94fad7
Add max time option for clusters
wtripp180901 a23312e
Linting
wtripp180901 a6dc13b
Disable unknown resource in platform creation view
wtripp180901 bdb4aa4
unset coral parameters by default
wtripp180901 81f81df
update test snapshot
wtripp180901 deb8f0d
Merge branch 'master' into feat/coral-quotas
wtripp180901 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
|
|
||
| import base64 | ||
| import dataclasses | ||
| import datetime | ||
| import functools | ||
| import hashlib | ||
| import logging | ||
|
|
@@ -14,7 +15,11 @@ | |
| import certifi | ||
| import dateutil.parser | ||
| import rackit | ||
| import requests | ||
| import yaml | ||
| from django.utils.timezone import make_aware | ||
|
|
||
| from azimuth.settings import cloud_settings | ||
|
|
||
| from .. import base, dto, errors # noqa: TID252 | ||
| from . import api | ||
|
|
@@ -286,6 +291,16 @@ def __init__( | |
| project_id_safe = self._connection.project_id.replace("-", "") | ||
| self._project_share_user = prefix + project_id_safe | ||
|
|
||
| # Get Coral bearer token if enabled | ||
| if cloud_settings.CORAL_CREDITS.ADMIN_PASSWORD is not None: | ||
| self._coral_auth_token = requests.post( | ||
| cloud_settings.CORAL_CREDITS.CORAL_URI + "/api-token-auth/", | ||
| json={ | ||
| "username": "admin", | ||
| "password": cloud_settings.CORAL_CREDITS.ADMIN_PASSWORD, | ||
wtripp180901 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| ).json()["token"] | ||
|
|
||
| def _log(self, message, *args, level=logging.INFO, **kwargs): | ||
| logger.log( | ||
| level, | ||
|
|
@@ -337,13 +352,15 @@ def quotas(self): | |
| None, | ||
| compute_limits.total_cores, | ||
| compute_limits.total_cores_used, | ||
| linked_credits_resource="VCPU", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. or PCPU, I think. |
||
| ), | ||
| dto.Quota( | ||
| "ram", | ||
| "RAM", | ||
| "MB", | ||
| compute_limits.total_ram, | ||
| compute_limits.total_ram_used, | ||
| linked_credits_resource="MEMORY_MB", | ||
| ), | ||
| dto.Quota( | ||
| "machines", | ||
|
|
@@ -365,6 +382,9 @@ def quotas(self): | |
| len(list(self._connection.network.floatingips.all())), | ||
| ) | ||
| ) | ||
| # Get coral credits if available | ||
| if cloud_settings.CORAL_CREDITS.CORAL_URI is not None: | ||
| quotas.extend(self.get_coral_quotas()) | ||
| # The volume service is optional | ||
| # In the case where the service is not enabled, just don't add the quotas | ||
| try: | ||
|
|
@@ -391,6 +411,75 @@ def quotas(self): | |
| pass | ||
| return quotas | ||
|
|
||
| def get_coral_quotas(self): | ||
| headers = {"Authorization": "Bearer " + self._coral_auth_token} | ||
| accounts = requests.get( | ||
| cloud_settings.CORAL_CREDITS.CORAL_URI + "/resource_provider_account", | ||
| headers=headers, | ||
| ).json() | ||
|
|
||
| tenancy_account_list = list( | ||
| filter( | ||
| lambda a: a["project_id"].replace("-", "") == self._tenancy.id, accounts | ||
| ) | ||
| ) | ||
| if len(tenancy_account_list) != 1: | ||
| return [] | ||
| tenancy_account = tenancy_account_list[0]["account"] | ||
| all_allocations = requests.get( | ||
| cloud_settings.CORAL_CREDITS.CORAL_URI + "/allocation", headers=headers | ||
| ).json() | ||
| account_allocations = filter( | ||
| lambda a: a["account"] == tenancy_account, all_allocations | ||
| ) | ||
|
|
||
| datetime_format = "%Y-%m-%dT%H:%M:%SZ" | ||
| current_time = make_aware(datetime.datetime.now()) | ||
| target_tz = current_time.tzinfo | ||
|
|
||
| active_allocation_list = list( | ||
| filter( | ||
| lambda a: datetime.datetime.strptime( | ||
| a["start"], datetime_format | ||
| ).replace(tzinfo=target_tz) | ||
| < current_time | ||
| and current_time | ||
| < datetime.datetime.strptime(a["end"], datetime_format).replace( | ||
| tzinfo=target_tz | ||
| ), | ||
| account_allocations, | ||
| ) | ||
| ) | ||
|
|
||
| human_readable_names = { | ||
| "MEMORY_MB": "RAM (MB)", | ||
| "DISK_GB": "Root disk (GB)", # TODO: is this always the root disk? | ||
| } | ||
|
|
||
| quotas = [] | ||
| if len(active_allocation_list) == 1: | ||
| active_allocation_id = active_allocation_list[0]["id"] | ||
| for resource in requests.get( | ||
| cloud_settings.CORAL_CREDITS.CORAL_URI | ||
| + "/allocation/" | ||
| + str(active_allocation_id) | ||
| + "/resources", | ||
| headers=headers, | ||
| ).json(): | ||
| resource_name = resource["resource_class"]["name"] | ||
| quotas.append( | ||
| dto.Quota( | ||
| resource_name, | ||
| human_readable_names.get(resource_name, resource_name) | ||
| + " hours (credits)", | ||
| "resource hours", | ||
| resource["allocated_resource_hours"], | ||
| resource["allocated_resource_hours"] | ||
| - resource["resource_hours"], | ||
| ) | ||
| ) | ||
| return quotas | ||
|
|
||
| def _from_api_image(self, api_image): | ||
| """ | ||
| Converts an OpenStack API image object into a :py:class:`.dto.Image`. | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,3 +1,6 @@ | ||
| AZIMUTH: | ||
| SCHEDULING: | ||
| ENABLED: {{ ternary "true" "false" .Values.scheduling.enabled }} | ||
| {{- with .Values.scheduling.maxPlatformDurationHours }} | ||
| MAX_PLATFORM_DURATION_HOURS: {{ . }} | ||
| {{- end }} |
This file contains hidden or 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,8 @@ | ||
| {{- with .Values.settings.coralCredits }} | ||
| AZIMUTH: | ||
| CORAL_CREDITS: | ||
| CORAL_URI: {{ quote .uri }} | ||
| {{- with .passwordSecretRef }} | ||
| ADMIN_PASSWORD: {{ index (lookup "v1" "Secret" .namespace .name).data .key | b64dec }} | ||
| {{- end }} | ||
| {{- end }} |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
related_resource_names: Sequence[str] = None