-
Notifications
You must be signed in to change notification settings - Fork 35
TPT-4111: Add info and list modules for regions vpc availability endpoints #779
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
Open
dawiddzhafarov
wants to merge
3
commits into
linode:dev
Choose a base branch
from
dawiddzhafarov:feature/TPT-4111-ansible-add-info-and-list-modules-for-regions-vpc-availability-endpoints
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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,50 @@ | ||
| # region_vpc_availability_info | ||
|
|
||
| Get info about a Linode Region VPC Availability. | ||
|
|
||
| WARNING! This module makes use of beta endpoints and requires the C(api_version) field be explicitly set to C(v4beta). | ||
|
|
||
| - [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 of a Linode Region VPC Availability | ||
| linode.cloud.region_vpc_availability_info: | ||
|
dawiddzhafarov marked this conversation as resolved.
|
||
| api_version: v4beta | ||
| id: us-mia | ||
| ``` | ||
|
|
||
|
|
||
| ## Parameters | ||
|
|
||
| | Field | Type | Required | Description | | ||
| |-----------|------|----------|------------------------------------------------------------------------------| | ||
| | `id` | <center>`str`</center> | <center>**Required**</center> | The ID of the Region VPC Availability to resolve. | | ||
|
|
||
| ## Return Values | ||
|
|
||
| - `region_vpc_availability` - The returned Region VPC Availability. | ||
|
|
||
| - Sample Response: | ||
| ```json | ||
| { | ||
| "region": "us-mia", | ||
| "available": true, | ||
| "available_ipv6_prefix_lengths": [ | ||
| 48, | ||
| 52 | ||
| ] | ||
| } | ||
| ``` | ||
| - See the [Linode API response documentation](https://techdocs.akamai.com/linode-api/reference/get-region-vpc-availability) 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,77 @@ | ||
| # regions_vpc_availability_list | ||
|
|
||
| List and filter on Regions VPC Availability. | ||
|
|
||
| WARNING! This module makes use of beta endpoints and requires the C(api_version) field be explicitly set to C(v4beta). | ||
|
|
||
| - [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). | | ||
|
dawiddzhafarov marked this conversation as resolved.
|
||
|
|
||
| ## Examples | ||
|
|
||
| ```yaml | ||
| - name: List all of the Linode regions VPC availability | ||
| linode.cloud.regions_vpc_availability_list: | ||
| api_version: v4beta | ||
| ``` | ||
|
|
||
|
|
||
| ## Parameters | ||
|
|
||
| | Field | Type | Required | Description | | ||
| |-----------|------|----------|------------------------------------------------------------------------------| | ||
| | `order` | <center>`str`</center> | <center>Optional</center> | The order to list Regions VPC Availability in. **(Choices: `desc`, `asc`; Default: `asc`)** | | ||
| | `order_by` | <center>`str`</center> | <center>Optional</center> | The attribute to order Regions VPC Availability by. | | ||
| | [`filters` (sub-options)](#filters) | <center>`list`</center> | <center>Optional</center> | A list of filters to apply to the resulting Regions VPC Availability. | | ||
| | `count` | <center>`int`</center> | <center>Optional</center> | The number of Regions VPC Availability to return. If undefined, all results will be returned. | | ||
|
|
||
| ### filters | ||
|
|
||
| | Field | Type | Required | Description | | ||
| |-----------|------|----------|------------------------------------------------------------------------------| | ||
| | `name` | <center>`str`</center> | <center>**Required**</center> | The name of the field to filter on. Valid filterable fields can be found [here](https://techdocs.akamai.com/linode-api/reference/get-regions-vpc-availability). | | ||
| | `values` | <center>`list`</center> | <center>**Required**</center> | A list of values to allow for this field. Fields will pass this filter if at least one of these values matches. | | ||
|
|
||
| ## Return Values | ||
|
|
||
| - `regions_vpc_availability` - The returned Regions VPC Availability. | ||
|
|
||
| - Sample Response: | ||
| ```json | ||
| [ | ||
| { | ||
| "region": "nl-ams", | ||
| "available": true, | ||
| "available_ipv6_prefix_lengths": [ | ||
| 48, | ||
| 52 | ||
| ] | ||
| }, | ||
| { | ||
| "region": "fr-par-2", | ||
| "available": true, | ||
| "available_ipv6_prefix_lengths": [ | ||
| 48, | ||
| 52 | ||
| ] | ||
| }, | ||
| { | ||
| "region": "jp-tyo-3", | ||
| "available": true, | ||
| "available_ipv6_prefix_lengths": [ | ||
| 48, | ||
| 52 | ||
| ] | ||
| } | ||
| ] | ||
| ``` | ||
| - See the [Linode API response documentation](https://techdocs.akamai.com/linode-api/reference/get-regions-vpc-availability) for a list of returned fields | ||
|
|
||
|
|
||
16 changes: 16 additions & 0 deletions
16
plugins/module_utils/doc_fragments/region_vpc_availability_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,16 @@ | ||
| """Documentation fragments for the region_vpc_availability_info module""" | ||
|
|
||
| specdoc_examples = [''' | ||
| - name: Get Info of a Linode Region VPC Availability | ||
| linode.cloud.region_vpc_availability_info: | ||
|
dawiddzhafarov marked this conversation as resolved.
|
||
| api_version: v4beta | ||
| id: us-mia'''] | ||
|
|
||
| result_region_vpc_availability_samples = ['''{ | ||
| "region": "us-mia", | ||
| "available": true, | ||
| "available_ipv6_prefix_lengths": [ | ||
| 48, | ||
| 52 | ||
| ] | ||
| }'''] | ||
33 changes: 33 additions & 0 deletions
33
plugins/module_utils/doc_fragments/regions_vpc_availability_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,33 @@ | ||
| """Documentation fragments for the regions_vpc_availability_list module""" | ||
|
|
||
| specdoc_examples = [''' | ||
| - name: List all of the Linode regions VPC availability | ||
| linode.cloud.regions_vpc_availability_list: | ||
| api_version: v4beta'''] | ||
|
|
||
| result_regions_vpc_availability_samples = ['''[ | ||
| { | ||
| "region": "nl-ams", | ||
| "available": true, | ||
| "available_ipv6_prefix_lengths": [ | ||
| 48, | ||
| 52 | ||
| ] | ||
| }, | ||
| { | ||
| "region": "fr-par-2", | ||
| "available": true, | ||
| "available_ipv6_prefix_lengths": [ | ||
| 48, | ||
| 52 | ||
| ] | ||
| }, | ||
| { | ||
| "region": "jp-tyo-3", | ||
| "available": true, | ||
| "available_ipv6_prefix_lengths": [ | ||
| 48, | ||
| 52 | ||
| ] | ||
| } | ||
| ]'''] |
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,51 @@ | ||
| #!/usr/bin/python | ||
| # -*- coding: utf-8 -*- | ||
|
|
||
| """This module allows users to retrieve information about a Linode Region VPC Availability.""" | ||
|
|
||
| from __future__ import absolute_import, division, print_function | ||
|
|
||
| from ansible_collections.linode.cloud.plugins.module_utils.doc_fragments import ( | ||
| region_vpc_availability_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 Region | ||
|
|
||
| module = InfoModule( | ||
| examples=docs.specdoc_examples, | ||
| primary_result=InfoModuleResult( | ||
| display_name="Region VPC Availability", | ||
| field_name="region_vpc_availability", | ||
| field_type=FieldType.dict, | ||
| docs_url="https://techdocs.akamai.com/linode-api/reference/get-region-vpc-availability", | ||
| samples=docs.result_region_vpc_availability_samples, | ||
| ), | ||
| attributes=[ | ||
| InfoModuleAttr( | ||
| name="id", | ||
| display_name="ID", | ||
| type=FieldType.string, | ||
| get=lambda client, params: client.load( | ||
| Region, params.get("id") | ||
| ).vpc_availability.dict, | ||
| ), | ||
| ], | ||
| requires_beta=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
| 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 Linode regions VPC availability.""" | ||
|
|
||
| from __future__ import absolute_import, division, print_function | ||
|
|
||
| from ansible_collections.linode.cloud.plugins.module_utils.doc_fragments import ( | ||
| regions_vpc_availability_list as docs, | ||
| ) | ||
| from ansible_collections.linode.cloud.plugins.module_utils.linode_common_list import ( | ||
| ListModule, | ||
| ) | ||
|
|
||
| module = ListModule( | ||
| result_display_name="Regions VPC Availability", | ||
| result_field_name="regions_vpc_availability", | ||
| endpoint_template="/regions/vpc-availability", | ||
| result_docs_url="https://techdocs.akamai.com/linode-api/reference/get-regions-vpc-availability", | ||
| requires_beta=True, | ||
| examples=docs.specdoc_examples, | ||
| result_samples=docs.result_regions_vpc_availability_samples, | ||
| ) | ||
|
|
||
| SPECDOC_META = module.spec | ||
|
|
||
| DOCUMENTATION = r""" | ||
| """ | ||
| EXAMPLES = r""" | ||
| """ | ||
| RETURN = r""" | ||
| """ | ||
|
|
||
| if __name__ == "__main__": | ||
| module.run() |
20 changes: 20 additions & 0 deletions
20
tests/integration/targets/region_vpc_availability_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,20 @@ | ||
| - name: region_vpc_availability_info | ||
| block: | ||
| - name: Get Info of a Linode Region VPC Availability | ||
| linode.cloud.region_vpc_availability_info: | ||
| id: us-mia | ||
| register: result | ||
|
|
||
| - name: Assert region_vpc_availability_info | ||
| assert: | ||
| that: | ||
| - result.region_vpc_availability.region == 'us-mia' | ||
| - result.region_vpc_availability.available == true | ||
| - result.region_vpc_availability.available_ipv6_prefix_lengths == [48, 52] | ||
|
dawiddzhafarov marked this conversation as resolved.
|
||
|
|
||
| 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 "" }}' | ||
17 changes: 17 additions & 0 deletions
17
tests/integration/targets/regions_vpc_availability_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,17 @@ | ||
| - name: regions_vpc_availability_list | ||
| block: | ||
| - name: List regions VPC availability | ||
| linode.cloud.regions_vpc_availability_list: | ||
| register: result | ||
|
|
||
| - name: Assert regions_vpc_availability_list | ||
| assert: | ||
| that: | ||
| - result.regions_vpc_availability | length >= 0 | ||
|
dawiddzhafarov marked this conversation as resolved.
|
||
|
|
||
| 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 "" }}' | ||
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.
Uh oh!
There was an error while loading. Please reload this page.