-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ansible wrapper of https://github.com/equinix-labs/metal-python/blob/main/equinix_metal/equinix_metal/api/plans_api.py#L50 which is a wrapper of: https://deploy.equinix.com/developers/api/metal/#tag/Plans/operation/findPlans Temporary as draft, until i find a way to make category, type, include and exclude filters running
- Loading branch information
Showing
6 changed files
with
379 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
# metal_plan_info | ||
|
||
Gather information about Equinix Metal plans | ||
|
||
|
||
- [Examples](#examples) | ||
- [Parameters](#parameters) | ||
- [Return Values](#return-values) | ||
|
||
## Examples | ||
|
||
```yaml | ||
- name: Gather information about all plans | ||
hosts: localhost | ||
tasks: | ||
- equinix.cloud.metal_plan_info | ||
|
||
``` | ||
|
||
```yaml | ||
- name: Gather information for plans with storage category | ||
hosts: localhost | ||
tasks: | ||
- equinix.cloud.metal_plan_info: | ||
categories: ['storage'] | ||
|
||
``` | ||
|
||
```yaml | ||
- name: Gather information for plans with slug c3.medium | ||
hosts: localhost | ||
tasks: | ||
- equinix.cloud.metal_plan_info: | ||
slug: c3.medium | ||
|
||
``` | ||
|
||
```yaml | ||
- name: Gather information for plans with a standard plan | ||
hosts: localhost | ||
tasks: | ||
- equinix.cloud.metal_plan_info: | ||
type: standard | ||
|
||
``` | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
## Parameters | ||
|
||
| Field | Type | Required | Description | | ||
|-----------|------|----------|------------------------------------------------------------------------------| | ||
| `categories` | <center>`list`</center> | <center>Optional</center> | Filter plans by its categories. | | ||
| `type` | <center>`str`</center> | <center>Optional</center> | Filter plans by its plan type. | | ||
| `slug` | <center>`str`</center> | <center>Optional</center> | Filter plans by slug. | | ||
|
||
|
||
|
||
|
||
|
||
|
||
## Return Values | ||
|
||
- `resources` - Found resources | ||
|
||
- Sample Response: | ||
```json | ||
|
||
{ | ||
"available_in": [], | ||
"available_in_metros": [], | ||
"category": [ | ||
"compute", | ||
"current_gen" | ||
], | ||
"class": "a3.large.opt-m3a2", | ||
"deployment_types": [], | ||
"description": "a3.large.opt-m3a2.x86", | ||
"id": "8c04950a-87ab-5e52-a112-5a90bbca8868", | ||
"legacy": false, | ||
"line": "baremetal", | ||
"name": "a3.large.opt-m3a2.x86", | ||
"pricing_hour": 8.2, | ||
"pricing_month": null, | ||
"slug": "a3.large.opt-m3a2" | ||
} | ||
``` | ||
|
||
|
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,177 @@ | ||
#!/usr/bin/python | ||
# -*- coding: utf-8 -*- | ||
|
||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) | ||
|
||
# DOCUMENTATION, EXAMPLES, and RETURN are generated by | ||
# ansible_specdoc. Do not edit them directly. | ||
|
||
DOCUMENTATION = ''' | ||
author: Equinix DevRel Team (@equinix) <[email protected]> | ||
description: Gather information about Equinix Metal plans | ||
module: metal_plan_info | ||
notes: [] | ||
options: | ||
categories: | ||
description: | ||
- Filter plans by its categories. | ||
required: false | ||
type: list | ||
slug: | ||
description: | ||
- Filter plans by slug. | ||
required: false | ||
type: str | ||
type: | ||
description: | ||
- Filter plans by its plan type. | ||
required: false | ||
type: str | ||
requirements: null | ||
short_description: Gather information about Equinix Metal plans | ||
''' | ||
EXAMPLES = ''' | ||
- name: Gather information about all plans | ||
hosts: localhost | ||
tasks: | ||
- equinix.cloud.metal_plan_info | ||
- name: Gather information for plans with storage category | ||
hosts: localhost | ||
tasks: | ||
- equinix.cloud.metal_plan_info: | ||
categories: | ||
- storage | ||
- name: Gather information for plans with slug c3.medium | ||
hosts: localhost | ||
tasks: | ||
- equinix.cloud.metal_plan_info: | ||
slug: c3.medium | ||
- name: Gather information for plans with a standard plan | ||
hosts: localhost | ||
tasks: | ||
- equinix.cloud.metal_plan_info: | ||
type: standard | ||
''' | ||
RETURN = ''' | ||
resources: | ||
description: Found resources | ||
returned: always | ||
sample: | ||
- "\n{ \ | ||
\ \n \"available_in\": [], \ | ||
\ \ | ||
\ \n \"available_in_metros\": [],\n \"category\"\ | ||
: [\n \"compute\",\n \"current_gen\"\n ],\n \"class\": \"a3.large.opt-m3a2\"\ | ||
,\n \"deployment_types\": [],\n \"description\": \"a3.large.opt-m3a2.x86\",\n\ | ||
\ \"id\": \"8c04950a-87ab-5e52-a112-5a90bbca8868\",\n \"legacy\": false,\n \ | ||
\ \"line\": \"baremetal\",\n \"name\": \"a3.large.opt-m3a2.x86\",\n \"pricing_hour\"\ | ||
: 8.2,\n \"pricing_month\": null,\n \"slug\": \"a3.large.opt-m3a2\"\n}" | ||
type: dict | ||
''' | ||
|
||
# End | ||
|
||
from ansible.module_utils._text import to_native | ||
from ansible_specdoc.objects import SpecField, FieldType, SpecReturnValue | ||
import traceback | ||
|
||
from ansible_collections.equinix.cloud.plugins.module_utils.equinix import ( | ||
EquinixModule, | ||
getSpecDocMeta, | ||
) | ||
|
||
module_spec = dict( | ||
categories=SpecField( | ||
type=FieldType.list, | ||
description=['Filter plans by categories.'], | ||
), | ||
type=SpecField( | ||
type=FieldType.string, | ||
description=['Filter plans by type.'], | ||
), | ||
slug=SpecField( | ||
type=FieldType.string, | ||
description=['Filter plans by slug.'], | ||
), | ||
) | ||
|
||
specdoc_examples = [''' | ||
- name: Gather information about all plans | ||
hosts: localhost | ||
tasks: | ||
- equinix.cloud.metal_plan_info | ||
''', ''' | ||
- name: Gather information for plans with storage category | ||
hosts: localhost | ||
tasks: | ||
- equinix.cloud.metal_plan_info: | ||
categories: ['storage'] | ||
''', ''' | ||
- name: Gather information for plans with slug c3.medium | ||
hosts: localhost | ||
tasks: | ||
- equinix.cloud.metal_plan_info: | ||
slug: c3.medium | ||
''', ''' | ||
- name: Gather information for plans with a standard plan | ||
hosts: localhost | ||
tasks: | ||
- equinix.cloud.metal_plan_info: | ||
type: standard | ||
''', | ||
] | ||
|
||
result_sample = [''' | ||
{ | ||
"available_in": [], | ||
"available_in_metros": [], | ||
"category": [ | ||
"compute", | ||
"current_gen" | ||
], | ||
"class": "a3.large.opt-m3a2", | ||
"deployment_types": [], | ||
"description": "a3.large.opt-m3a2.x86", | ||
"id": "8c04950a-87ab-5e52-a112-5a90bbca8868", | ||
"legacy": false, | ||
"line": "baremetal", | ||
"name": "a3.large.opt-m3a2.x86", | ||
"pricing_hour": 8.2, | ||
"pricing_month": null, | ||
"slug": "a3.large.opt-m3a2" | ||
}''', | ||
] | ||
|
||
SPECDOC_META = getSpecDocMeta( | ||
short_description="Gather information about Equinix Metal plans", | ||
description=( | ||
'Gather information about Equinix Metal plans' | ||
), | ||
examples=specdoc_examples, | ||
options=module_spec, | ||
return_values={ | ||
"resources": SpecReturnValue( | ||
description='Found resources', | ||
type=FieldType.dict, | ||
sample=result_sample, | ||
), | ||
}, | ||
) | ||
|
||
def main(): | ||
module = EquinixModule( | ||
argument_spec=SPECDOC_META.ansible_spec, | ||
is_info=True, | ||
) | ||
try: | ||
module.params_syntax_check() | ||
return_value = {'resources': module.get_list("metal_plan")} | ||
|
||
except Exception as e: | ||
tr = traceback.format_exc() | ||
module.fail_json(msg=to_native(e), exception=tr) | ||
module.exit_json(**return_value) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
Oops, something went wrong.