-
Notifications
You must be signed in to change notification settings - Fork 35
TPT-4552: Add modules for object storage global quota #824
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f54929a
fix: improve description for listing with filters disabled
zliang-akamai 49cbf68
feat: add object storage global quota info and list modules
zliang-akamai 10080ad
Update Python target versions and set py-version to 3.10
zliang-akamai 0ea55a3
Enhance type hints and improve function signature for get_quota_usage
zliang-akamai 8ba218f
Update typing for params
zliang-akamai 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
Some comments aren't visible on the classic Files Changed page.
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 |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| # object_storage_global_quota_info | ||
|
|
||
| Get info about a Linode Object Storage Global Quota. | ||
|
|
||
| - [Minimum Required Fields](#minimum-required-fields) | ||
| - [Examples](#examples) | ||
| - [Parameters](#parameters) | ||
| - [Return Values](#return-values) | ||
|
|
||
| ## Minimum Required Fields | ||
| | Field | Type | Required | Description | | ||
| |-------------|-------|--------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ||
| | `api_token` | `str` | **Required** | The Linode account personal access token. It is necessary to run the module. <br/>It can be exposed by the environment variable `LINODE_API_TOKEN` instead. <br/>See details in [Usage](https://github.com/linode/ansible_linode?tab=readme-ov-file#usage). | | ||
|
|
||
| ## Examples | ||
|
|
||
| ```yaml | ||
| - name: Get info about an Object Storage global quota | ||
| linode.cloud.object_storage_global_quota_info: | ||
| quota_id: keys | ||
| ``` | ||
|
|
||
|
|
||
| ## Parameters | ||
|
|
||
| | Field | Type | Required | Description | | ||
| |-----------|------|----------|------------------------------------------------------------------------------| | ||
| | `quota_id` | <center>`str`</center> | <center>**Required**</center> | The Quota ID of the Object Storage Global Quota to resolve. | | ||
|
|
||
| ## Return Values | ||
|
|
||
| - `object_storage_global_quota` - The returned Object Storage Global Quota. | ||
|
|
||
| - Sample Response: | ||
| ```json | ||
| { | ||
| "description": "Current number of access keys per account", | ||
| "has_usage": true, | ||
| "quota_id": "keys", | ||
| "quota_limit": 100, | ||
| "quota_name": "Number of Access Keys", | ||
| "quota_type": "keys", | ||
| "resource_metric": "key" | ||
| } | ||
| ``` | ||
| - See the [Linode API response documentation](https://techdocs.akamai.com/linode-api/reference/get-object-storage-global-quota) for a list of returned fields | ||
|
|
||
|
|
||
| - `quota_usage` - The returned Quota Usage. | ||
|
|
||
| - Sample Response: | ||
| ```json | ||
| { | ||
| "quota_limit": 100, | ||
| "usage": 47 | ||
| } | ||
| ``` | ||
| - See the [Linode API response documentation](https://techdocs.akamai.com/linode-api/reference/get-object-storage-global-quota-usage) for a list of returned fields | ||
|
|
||
|
|
||
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,49 @@ | ||
| # object_storage_global_quota_list | ||
|
|
||
| List Object Storage Global Quotas. | ||
|
|
||
| - [Minimum Required Fields](#minimum-required-fields) | ||
| - [Examples](#examples) | ||
| - [Parameters](#parameters) | ||
| - [Return Values](#return-values) | ||
|
|
||
| ## Minimum Required Fields | ||
| | Field | Type | Required | Description | | ||
| |-------------|-------|--------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ||
| | `api_token` | `str` | **Required** | The Linode account personal access token. It is necessary to run the module. <br/>It can be exposed by the environment variable `LINODE_API_TOKEN` instead. <br/>See details in [Usage](https://github.com/linode/ansible_linode?tab=readme-ov-file#usage). | | ||
|
|
||
| ## Examples | ||
|
|
||
| ```yaml | ||
| - name: List all Object Storage global quotas for the current account | ||
| linode.cloud.object_storage_global_quota_list: | ||
| ``` | ||
|
|
||
|
|
||
| ## Parameters | ||
|
|
||
| | Field | Type | Required | Description | | ||
| |-----------|------|----------|------------------------------------------------------------------------------| | ||
| | `count` | <center>`int`</center> | <center>Optional</center> | The number of Object Storage Global Quotas to return. If undefined, all results will be returned. | | ||
|
|
||
| ## Return Values | ||
|
|
||
| - `object_storage_global_quotas` - The returned Object Storage Global Quotas. | ||
|
|
||
| - Sample Response: | ||
| ```json | ||
| [ | ||
| { | ||
| "description": "Current number of access keys per account", | ||
| "has_usage": true, | ||
| "quota_id": "keys", | ||
| "quota_limit": 100, | ||
| "quota_name": "Number of Access Keys", | ||
| "quota_type": "keys", | ||
| "resource_metric": "key" | ||
| } | ||
| ] | ||
| ``` | ||
| - See the [Linode API response documentation](https://techdocs.akamai.com/linode-api/reference/get-object-storage-global-quotas) for a list of returned fields | ||
|
|
||
|
|
22 changes: 22 additions & 0 deletions
22
plugins/module_utils/doc_fragments/object_storage_global_quota_info.py
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,22 @@ | ||
| """Documentation fragments for the object_storage_global_quota_info module""" | ||
|
|
||
| result_object_storage_global_quota_samples = ['''{ | ||
| "description": "Current number of access keys per account", | ||
| "has_usage": true, | ||
| "quota_id": "keys", | ||
| "quota_limit": 100, | ||
| "quota_name": "Number of Access Keys", | ||
| "quota_type": "keys", | ||
| "resource_metric": "key" | ||
| }'''] | ||
|
|
||
| result_object_storage_global_quota_usage_samples = ['''{ | ||
| "quota_limit": 100, | ||
| "usage": 47 | ||
| }'''] | ||
|
|
||
|
|
||
| specdoc_examples = [''' | ||
| - name: Get info about an Object Storage global quota | ||
| linode.cloud.object_storage_global_quota_info: | ||
| quota_id: keys'''] |
17 changes: 17 additions & 0 deletions
17
plugins/module_utils/doc_fragments/object_storage_global_quota_list.py
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,17 @@ | ||
| """Documentation fragments for the object_storage_global_quota_list module""" | ||
|
|
||
| specdoc_examples = [''' | ||
| - name: List all Object Storage global quotas for the current account | ||
| linode.cloud.object_storage_global_quota_list:'''] | ||
|
|
||
| result_object_storage_global_quotas_samples = ['''[ | ||
| { | ||
| "description": "Current number of access keys per account", | ||
| "has_usage": true, | ||
| "quota_id": "keys", | ||
| "quota_limit": 100, | ||
| "quota_name": "Number of Access Keys", | ||
| "quota_type": "keys", | ||
| "resource_metric": "key" | ||
| } | ||
| ]'''] |
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 |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| #!/usr/bin/python | ||
| # -*- coding: utf-8 -*- | ||
|
|
||
| """This module contains all of the functionality for Linode Object Storage global quota info.""" | ||
|
|
||
| from __future__ import absolute_import, division, print_function | ||
|
|
||
| from typing import Any | ||
|
zliang-akamai marked this conversation as resolved.
|
||
|
|
||
| from ansible_collections.linode.cloud.plugins.module_utils.doc_fragments import ( | ||
| object_storage_global_quota_info as docs, | ||
| ) | ||
| from ansible_collections.linode.cloud.plugins.module_utils.linode_common_info import ( | ||
| InfoModule, | ||
| InfoModuleAttr, | ||
| InfoModuleResult, | ||
| ) | ||
| from ansible_specdoc.objects import FieldType | ||
| from linode_api4 import LinodeClient, ObjectStorageGlobalQuota | ||
|
|
||
|
|
||
| def get_quota_usage( | ||
| client: LinodeClient, | ||
| object_storage_global_quota: dict[str, Any], | ||
| params: dict | None, | ||
| ) -> dict[str, Any] | None: | ||
| """Return quota usage details for a quota when usage is available.""" | ||
| if not object_storage_global_quota["has_usage"]: | ||
| return None | ||
|
|
||
| return ( | ||
| ObjectStorageGlobalQuota( | ||
| client, object_storage_global_quota["quota_id"] | ||
| ) | ||
| .usage() | ||
| .dict | ||
| ) | ||
|
|
||
|
|
||
| module = InfoModule( | ||
| examples=docs.specdoc_examples, | ||
| primary_result=InfoModuleResult( | ||
| display_name="Object Storage Global Quota", | ||
| field_name="object_storage_global_quota", | ||
| field_type=FieldType.dict, | ||
| docs_url="https://techdocs.akamai.com/linode-api/reference/get-object-storage-global-quota", | ||
| samples=docs.result_object_storage_global_quota_samples, | ||
| ), | ||
| secondary_results=[ | ||
| InfoModuleResult( | ||
| display_name="Quota Usage", | ||
| field_name="quota_usage", | ||
| field_type=FieldType.dict, | ||
| docs_url="https://techdocs.akamai.com/linode-api/reference" | ||
| "/get-object-storage-global-quota-usage", | ||
| samples=docs.result_object_storage_global_quota_usage_samples, | ||
| get=get_quota_usage, | ||
| ), | ||
| ], | ||
| attributes=[ | ||
| InfoModuleAttr( | ||
| name="quota_id", | ||
| display_name="Quota ID", | ||
| type=FieldType.string, | ||
| get=lambda client, params: client.load( | ||
| ObjectStorageGlobalQuota, params.get("quota_id") | ||
| )._raw_json, | ||
| ), | ||
| ], | ||
| ) | ||
|
|
||
| SPECDOC_META = module.spec | ||
|
|
||
| DOCUMENTATION = r""" | ||
| """ | ||
| EXAMPLES = r""" | ||
| """ | ||
| RETURN = r""" | ||
| """ | ||
|
|
||
| if __name__ == "__main__": | ||
| module.run() | ||
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,35 @@ | ||
| #!/usr/bin/python | ||
| # -*- coding: utf-8 -*- | ||
|
|
||
| """This module allows users to list Object Storage global quotas.""" | ||
|
|
||
| from __future__ import absolute_import, division, print_function | ||
|
|
||
| from ansible_collections.linode.cloud.plugins.module_utils.doc_fragments import ( | ||
| object_storage_global_quota_list as docs, | ||
| ) | ||
| from ansible_collections.linode.cloud.plugins.module_utils.linode_common_list import ( | ||
| ListModule, | ||
| ) | ||
|
|
||
| module = ListModule( | ||
| result_display_name="Object Storage Global Quotas", | ||
| result_field_name="object_storage_global_quotas", | ||
| endpoint_template="/object-storage/global-quotas", | ||
| result_docs_url="https://techdocs.akamai.com/linode-api/reference/get-object-storage-global-quotas", # pylint: disable=line-too-long | ||
| result_samples=docs.result_object_storage_global_quotas_samples, | ||
| examples=docs.specdoc_examples, | ||
| disable_filters=True, | ||
| ) | ||
|
|
||
| SPECDOC_META = module.spec | ||
|
|
||
| DOCUMENTATION = r""" | ||
| """ | ||
| EXAMPLES = r""" | ||
| """ | ||
| RETURN = r""" | ||
| """ | ||
|
|
||
| if __name__ == "__main__": | ||
| module.run() |
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
28 changes: 28 additions & 0 deletions
28
tests/integration/targets/object_storage_global_quota_info/tasks/main.yaml
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,28 @@ | ||
| - name: object_storage_global_quota_info | ||
| block: | ||
| - name: List Object Storage global quotas | ||
| linode.cloud.object_storage_global_quota_list: | ||
| register: obj_global_quota_list | ||
|
|
||
| - name: Assert at least one global quota returned for the following test | ||
| assert: | ||
| that: | ||
| - obj_global_quota_list.object_storage_global_quotas | length > 0 | ||
|
|
||
| - name: Get info about an Object Storage global quota | ||
| linode.cloud.object_storage_global_quota_info: | ||
| quota_id: '{{ obj_global_quota_list.object_storage_global_quotas[0].quota_id }}' | ||
| register: obj_global_quota | ||
|
|
||
| - name: Assert GET Object Storage global quota response | ||
| assert: | ||
| that: | ||
| - obj_global_quota.object_storage_global_quota.quota_id == obj_global_quota_list.object_storage_global_quotas[0].quota_id | ||
| - not (obj_global_quota.object_storage_global_quota.has_usage | bool) or (obj_global_quota.quota_usage.quota_limit is integer) | ||
|
|
||
| environment: | ||
| LINODE_UA_PREFIX: '{{ ua_prefix }}' | ||
| LINODE_API_TOKEN: '{{ api_token }}' | ||
| LINODE_API_URL: '{{ api_url }}' | ||
| LINODE_API_VERSION: '{{ api_version }}' | ||
| LINODE_CA: '{{ ca_file or "" }}' |
18 changes: 18 additions & 0 deletions
18
tests/integration/targets/object_storage_global_quota_list/tasks/main.yaml
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,18 @@ | ||
| - name: object_storage_global_quota_list | ||
| block: | ||
| - name: List Object Storage global quotas | ||
| linode.cloud.object_storage_global_quota_list: | ||
| register: obj_global_quota_list | ||
|
|
||
| - name: Assert global quotas are listed correctly | ||
| assert: | ||
| that: | ||
| - obj_global_quota_list.object_storage_global_quotas | length > 0 | ||
| - "(obj_global_quota_list.object_storage_global_quotas | selectattr('quota_id', 'equalto', 'keys') | list | length) > 0" | ||
|
|
||
| environment: | ||
| LINODE_UA_PREFIX: '{{ ua_prefix }}' | ||
| LINODE_API_TOKEN: '{{ api_token }}' | ||
| LINODE_API_URL: '{{ api_url }}' | ||
| LINODE_API_VERSION: '{{ api_version }}' | ||
| LINODE_CA: '{{ ca_file or "" }}' |
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.
Uh oh!
There was an error while loading. Please reload this page.