feat(interface): add modules for managing node interfaces
This commit is contained in:
119
plugins/modules/node_interface_info.py
Normal file
119
plugins/modules/node_interface_info.py
Normal file
@ -0,0 +1,119 @@
|
||||
#!/usr/bin/python
|
||||
# coding: utf-8
|
||||
|
||||
# (c) 2022, Johanna Dorothea Reichmann <transcaffeine@finally.coffee>
|
||||
|
||||
__metaclass__ = type
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
from ansible_collections.finallycoffee.proxmox.plugins.module_utils.common import *
|
||||
from ansible_collections.finallycoffee.proxmox.plugins.module_utils.proxmox_node_iface import *
|
||||
|
||||
|
||||
DOCUMENTATION = r'''
|
||||
---
|
||||
module: node_interface_info
|
||||
author:
|
||||
- Johanna Dorothea Reichmann (transcaffeine@finally.coffee)
|
||||
requirements:
|
||||
- python >= 3.9
|
||||
short_description: Configures an authentication realm in a proxmox node
|
||||
description:
|
||||
- "Configue realm in a proxmox instance"
|
||||
options:
|
||||
proxmox_instance:
|
||||
description: Location of the proxmox API with scheme, domain name/ip and port, e.g. https://localhost:8006
|
||||
type: str
|
||||
required: true
|
||||
proxmox_api_token_id:
|
||||
description: The token ID containing username, realm and token name (format: user@realm!name)
|
||||
type: str
|
||||
required: true
|
||||
proxmox_api_secret:
|
||||
description: The secret
|
||||
type: str
|
||||
required: true
|
||||
proxmox_api_verify_cert:
|
||||
description: If the certificate presented for `proxmox_instance_url` should be verified
|
||||
type: bool
|
||||
required: false
|
||||
default: true
|
||||
node:
|
||||
description: Node to retrieve information about.
|
||||
type: str
|
||||
required: true
|
||||
name:
|
||||
description: Interface to retrieve information about. If left omitted, return all realms
|
||||
type: str
|
||||
required: false
|
||||
'''
|
||||
|
||||
EXAMPLES = r'''
|
||||
- name: Retrieve all interfaces on node 'hostname'
|
||||
finallycoffee.proxmox.node_interface_info:
|
||||
proxmox_instance: https://my.proxmox-node.local:8006
|
||||
promox_api_token_id: root@pam!token
|
||||
proxmox_api_secret: supersecuretokencontent
|
||||
node: hostname
|
||||
|
||||
- name: Retrieve interface information for 'vmbr0' on 'other_pm_host'
|
||||
finallycoffee.proxmox.node_interface_info:
|
||||
proxmox_instance: https://my.proxmox-node.local:8006
|
||||
promox_api_token_id: root@pam!token
|
||||
proxmox_api_secret: supersecuretokencontent
|
||||
node: other_pm_host
|
||||
name: vmbr0
|
||||
'''
|
||||
|
||||
RETURN = r'''
|
||||
interfaces:
|
||||
description: The retrieved interfaces on the specified nodes
|
||||
returned: When interfaces are present on a node
|
||||
type: list
|
||||
elements: dict[str, str]
|
||||
|
||||
'''
|
||||
|
||||
|
||||
def main():
|
||||
_ = dict
|
||||
module = AnsibleModule(
|
||||
argument_spec=_(
|
||||
proxmox_instance=_(required=True, type='str'),
|
||||
proxmox_api_token_id=_(required=True, type='str'),
|
||||
proxmox_api_secret=_(type='str', required=True, no_log=True),
|
||||
proxmox_api_verify_cert=_(type='bool', required=False, default=True),
|
||||
node=_(required=True, type='str'),
|
||||
name=_(required=False, type='str'),
|
||||
),
|
||||
supports_check_mode=True
|
||||
)
|
||||
|
||||
result = _(
|
||||
changed=False,
|
||||
diff={},
|
||||
message=''
|
||||
)
|
||||
|
||||
realms = []
|
||||
try:
|
||||
interfaces = get_interfaces(ProxmoxAuthInfo(
|
||||
module.params['proxmox_instance'],
|
||||
module.params['proxmox_api_token_id'],
|
||||
module.params['proxmox_api_secret'],
|
||||
module.params['proxmox_api_verify_cert'],
|
||||
),
|
||||
module.params['node'],
|
||||
)
|
||||
except IOError as owie:
|
||||
result['msg'] = owie
|
||||
module.exit_json(**result)
|
||||
|
||||
result['interfaces'] = interfaces
|
||||
|
||||
module.exit_json(**result)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
Reference in New Issue
Block a user