Add more plugins for proxmox #2

Merged
transcaffeine merged 8 commits from transcaffeine/more-plugins into main 2022-08-24 11:11:47 +00:00
2 changed files with 109 additions and 0 deletions
Showing only changes of commit e72d920b73 - Show all commits

View File

@ -0,0 +1,13 @@
from typing import List, Tuple
from ansible_collections.finallycoffee.proxmox.plugins.module_utils.common import _proxmox_request, ProxmoxAuthInfo
def get_pools(auth_info: ProxmoxAuthInfo) -> [str]:
pool_answer = _proxmox_request('get', f"/pools", auth_info).json()
return pool_answer['data']
def get_pool(auth_info: ProxmoxAuthInfo, pool: str) -> [dict]:
pool_answer = _proxmox_request('get', f"/pools/{pool}", auth_info).json()
return pool_answer['data']

View File

@ -0,0 +1,96 @@
#!/usr/bin/python
# coding: utf-8
# (c) 2022, Johanna Dorothea Reichmann <transcaffeine@finally.coffee>
__metaclass__ = type
import json
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_pool import *
DOCUMENTATION = r'''
---
module: pool_info
author:
- Johanna Dorothea Reichmann (transcaffeine@finally.coffee)
requirements:
- python >= 3.9
short_description: Get information about all proxmox cluster nodes
description:
- "Equivalent to /api2/json/nodes, returns all available top-level information about all visible nodes"
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
'''
EXAMPLES = r'''
- name: Retrieve all resource pools
finallycoffee.proxmox.pool_info:
proxmox_instance: https://my.proxmox-node.local:8006
promox_api_token_id: root@pam!token
proxmox_api_secret: supersecuretokencontent
'''
RETURN = r'''
pools:
description: All resource pools present in the datacenter
returned: When pools are visible (token has atleast Pool.Audit on each pool)
type: list
elements: 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),
),
supports_check_mode=True
)
result = _(
changed=False,
diff={},
message=''
)
pools = []
try:
pools = get_pools(ProxmoxAuthInfo(
module.params['proxmox_instance'],
module.params['proxmox_api_token_id'],
module.params['proxmox_api_secret'],
module.params['proxmox_api_verify_cert'],
))
except IOError as owie:
result['msg'] = owie
module.exit_json(**result)
result['pools'] = pools
module.exit_json(**result)
if __name__ == '__main__':
main()