proxmox/plugins/module_utils/common.py

26 lines
737 B
Python

from dataclasses import dataclass
import requests
API_BASE_PATH: str = "/api2/json"
@dataclass()
class ProxmoxAuthInfo:
instance_url: str
token_id: str
secret: str
verify_cert: bool = True
def _get_token_from_auth_info(auth_info: ProxmoxAuthInfo) -> str:
return f"PVEAPIToken={auth_info.token_id}={auth_info.secret}"
def _proxmox_request(method: str, endpoint: str, auth_info: ProxmoxAuthInfo, **params):
return requests.request(method,
f"{auth_info.instance_url}{API_BASE_PATH}{endpoint}",
headers={'Authorization': _get_token_from_auth_info(auth_info)},
verify=auth_info.verify_cert,
**params)