-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add type_info module * Add return annotation
- Loading branch information
1 parent
1670dc1
commit acebc35
Showing
6 changed files
with
168 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# type_info | ||
|
||
Get info about a Linode Type. | ||
|
||
- [Examples](#examples) | ||
- [Parameters](#parameters) | ||
- [Return Values](#return-values) | ||
|
||
## Examples | ||
|
||
```yaml | ||
- name: Get info about a Linode type by ID | ||
linode.cloud.type_info: | ||
id: g6-standard-2 | ||
``` | ||
## Parameters | ||
| Field | Type | Required | Description | | ||
|-----------|------|----------|------------------------------------------------------------------------------| | ||
| `id` | <center>`str`</center> | <center>Optional</center> | The ID of the Type to resolve. | | ||
|
||
## Return Values | ||
|
||
- `type` - The returned Type. | ||
|
||
- Sample Response: | ||
```json | ||
{ | ||
"addons": { | ||
"backups": { | ||
"price": { | ||
"hourly": 0.008, | ||
"monthly": 5 | ||
} | ||
} | ||
}, | ||
"class": "standard", | ||
"disk": 81920, | ||
"gpus": 0, | ||
"id": "g6-standard-2", | ||
"label": "Linode 4GB", | ||
"memory": 4096, | ||
"network_out": 1000, | ||
"price": { | ||
"hourly": 0.03, | ||
"monthly": 20 | ||
}, | ||
"successor": null, | ||
"transfer": 4000, | ||
"vcpus": 2 | ||
} | ||
``` | ||
- See the [Linode API response documentation](https://www.linode.com/docs/api/linode-types/#type-view) for a list of returned fields | ||
|
||
|
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,32 @@ | ||
"""Documentation fragments for the vpc_info module""" | ||
|
||
specdoc_examples = [''' | ||
- name: Get info about a Linode type by ID | ||
linode.cloud.type_info: | ||
id: g6-standard-2'''] | ||
|
||
result_type_samples = [''' | ||
{ | ||
"addons": { | ||
"backups": { | ||
"price": { | ||
"hourly": 0.008, | ||
"monthly": 5 | ||
} | ||
} | ||
}, | ||
"class": "standard", | ||
"disk": 81920, | ||
"gpus": 0, | ||
"id": "g6-standard-2", | ||
"label": "Linode 4GB", | ||
"memory": 4096, | ||
"network_out": 1000, | ||
"price": { | ||
"hourly": 0.03, | ||
"monthly": 20 | ||
}, | ||
"successor": null, | ||
"transfer": 4000, | ||
"vcpus": 2 | ||
}'''] |
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,54 @@ | ||
#!/usr/bin/python | ||
# -*- coding: utf-8 -*- | ||
|
||
"""This module allows users to retrieve information about a Linode Type.""" | ||
|
||
from __future__ import absolute_import, division, print_function | ||
|
||
from typing import Any, Dict | ||
|
||
import ansible_collections.linode.cloud.plugins.module_utils.doc_fragments.type_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, Type | ||
|
||
|
||
def _get_by_id(client: LinodeClient, params: Dict[str, Any]) -> None: | ||
""" | ||
This function is intended to be passed into the ID get attribute. | ||
NOTE: This is not implemented as a lambda because Type currently does not work with | ||
client.load(). | ||
""" | ||
inst_type = Type(client, params.get("id")) | ||
inst_type._api_get() | ||
return inst_type._raw_json | ||
|
||
|
||
module = InfoModule( | ||
primary_result=InfoModuleResult( | ||
field_name="type", | ||
field_type=FieldType.dict, | ||
display_name="Type", | ||
docs_url="https://www.linode.com/docs/api/linode-types/#type-view", | ||
samples=docs.result_type_samples, | ||
), | ||
attributes=[ | ||
InfoModuleAttr( | ||
display_name="ID", | ||
name="id", | ||
type=FieldType.string, | ||
get=_get_by_id, | ||
) | ||
], | ||
examples=docs.specdoc_examples, | ||
) | ||
|
||
SPECDOC_META = module.spec | ||
|
||
if __name__ == "__main__": | ||
module.run() |
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,20 @@ | ||
- name: type_info | ||
block: | ||
- set_fact: | ||
r: "{{ 1000000000 | random }}" | ||
|
||
- name: Get info about a type by ID | ||
linode.cloud.type_info: | ||
id: g6-standard-2 | ||
register: type_info | ||
|
||
- assert: | ||
that: | ||
- type_info.type.class == "standard" | ||
|
||
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 "" }}' |