Proxmox servers added with API

This commit is contained in:
Mario
2024-08-04 21:13:21 +02:00
parent 8a16fd6751
commit 62b516bf25
9 changed files with 87 additions and 1 deletions

BIN
ow_vm_management/models/.DS_Store vendored Normal file

Binary file not shown.

View File

@@ -1,2 +1,3 @@
from . import vps_server
from . import res_partner
from . import res_partner
from . import proxmox_server

View File

@@ -0,0 +1,38 @@
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))