from odoo import models, fields, api, _ from odoo.exceptions import UserError import requests import urllib3 class ProxmoxServer(models.Model): _name = 'proxmox.server' _description = 'Proxmox Server' name = fields.Char(string='Server Name', required=True) url = fields.Char(string='Proxmox URL', required=True) api_token_id = fields.Char(string='API Token ID', required=True) api_token_secret = fields.Char(string='API Token Secret', required=True) def action_test_connection(self): self.ensure_one() try: urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) response = requests.get( f"{self.url}/api2/json/nodes", verify=False, headers={ "Authorization": f"PVEAPIToken={self.api_token_id}={self.api_token_secret}" } ) response.raise_for_status() return { 'type': 'ir.actions.client', 'tag': 'display_notification', 'params': { 'title': _('Connection Successful'), 'message': _('Successfully connected to the Proxmox server.'), 'sticky': False, 'type': 'success', } } except requests.exceptions.RequestException as e: raise UserError(_("Failed to connect to Proxmox server: %s") % str(e))