-
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.
Migrated Firewall-related info and list modules to new framework (#568)
* Migrated firewall info and list modules * Fixed docs
- Loading branch information
1 parent
ce05f8a
commit 73cbd64
Showing
4 changed files
with
72 additions
and
237 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
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 |
---|---|---|
@@ -1,132 +1,32 @@ | ||
#!/usr/bin/python | ||
# -*- coding: utf-8 -*- | ||
|
||
"""This module allows users to list Linode tokens.""" | ||
from __future__ import absolute_import, division, print_function | ||
"""This module contains all of the functionality for listing Linode Firewalls.""" | ||
|
||
from typing import Any, Dict, Optional | ||
from __future__ import absolute_import, division, print_function | ||
|
||
import ansible_collections.linode.cloud.plugins.module_utils.doc_fragments.firewall_list as docs | ||
from ansible_collections.linode.cloud.plugins.module_utils.linode_common import ( | ||
LinodeModuleBase, | ||
) | ||
from ansible_collections.linode.cloud.plugins.module_utils.linode_docs import ( | ||
global_authors, | ||
global_requirements, | ||
) | ||
from ansible_collections.linode.cloud.plugins.module_utils.linode_helper import ( | ||
construct_api_filter, | ||
get_all_paginated, | ||
) | ||
from ansible_specdoc.objects import ( | ||
FieldType, | ||
SpecDocMeta, | ||
SpecField, | ||
SpecReturnValue, | ||
from ansible_collections.linode.cloud.plugins.module_utils.linode_common_list import ( | ||
ListModule, | ||
) | ||
|
||
spec_filter = { | ||
"name": SpecField( | ||
type=FieldType.string, | ||
required=True, | ||
description=[ | ||
"The name of the field to filter on.", | ||
"Valid filterable attributes can be found here: " | ||
"https://techdocs.akamai.com/linode-api/reference/get-ips", | ||
], | ||
), | ||
"values": SpecField( | ||
type=FieldType.list, | ||
element_type=FieldType.string, | ||
required=True, | ||
description=[ | ||
"A list of values to allow for this field.", | ||
"Fields will pass this filter if at least one of these values matches.", | ||
], | ||
), | ||
} | ||
|
||
spec = { | ||
# Disable the default values | ||
"state": SpecField(type=FieldType.string, required=False, doc_hide=True), | ||
"label": SpecField(type=FieldType.string, required=False, doc_hide=True), | ||
"order": SpecField( | ||
type=FieldType.string, | ||
description=["The order to list firewalls in."], | ||
default="asc", | ||
choices=["desc", "asc"], | ||
), | ||
"order_by": SpecField( | ||
type=FieldType.string, | ||
description=["The attribute to order firewalls by."], | ||
), | ||
"filters": SpecField( | ||
type=FieldType.list, | ||
element_type=FieldType.dict, | ||
suboptions=spec_filter, | ||
description=["A list of filters to apply to the resulting firewalls."], | ||
), | ||
"count": SpecField( | ||
type=FieldType.integer, | ||
description=[ | ||
"The number of results to return.", | ||
"If undefined, all results will be returned.", | ||
], | ||
), | ||
} | ||
|
||
SPECDOC_META = SpecDocMeta( | ||
description=["List and filter on Firewalls."], | ||
requirements=global_requirements, | ||
author=global_authors, | ||
options=spec, | ||
module = ListModule( | ||
result_display_name="Firewalls", | ||
result_field_name="firewalls", | ||
endpoint_template="/networking/firewalls", | ||
result_docs_url="https://techdocs.akamai.com/linode-api/reference/get-firewalls", | ||
examples=docs.specdoc_examples, | ||
return_values={ | ||
"firewalls": SpecReturnValue( | ||
description="The returned firewalls.", | ||
docs_url="https://techdocs.akamai.com/linode-api/reference/get-firewalls", | ||
type=FieldType.list, | ||
elements=FieldType.dict, | ||
sample=docs.result_firewalls_samples, | ||
) | ||
}, | ||
result_samples=docs.result_firewalls_samples, | ||
) | ||
|
||
SPECDOC_META = module.spec | ||
|
||
DOCUMENTATION = r""" | ||
""" | ||
EXAMPLES = r""" | ||
""" | ||
RETURN = r""" | ||
""" | ||
|
||
|
||
class Module(LinodeModuleBase): | ||
"""Module for getting a list of Firewalls""" | ||
|
||
def __init__(self) -> None: | ||
self.module_arg_spec = SPECDOC_META.ansible_spec | ||
self.results: Dict[str, Any] = {"firewalls": []} | ||
|
||
super().__init__(module_arg_spec=self.module_arg_spec) | ||
|
||
def exec_module(self, **kwargs: Any) -> Optional[dict]: | ||
"""Entrypoint for firewall list module""" | ||
|
||
filter_dict = construct_api_filter(self.module.params) | ||
|
||
self.results["firewalls"] = get_all_paginated( | ||
self.client, | ||
"/networking/firewalls", | ||
filter_dict, | ||
num_results=self.module.params["count"], | ||
) | ||
return self.results | ||
|
||
|
||
def main() -> None: | ||
"""Constructs and calls the module""" | ||
Module() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() | ||
module.run() |