Proxmox servers added with API
This commit is contained in:
BIN
ow_vm_management/models/.DS_Store
vendored
Normal file
BIN
ow_vm_management/models/.DS_Store
vendored
Normal file
Binary file not shown.
@@ -1,2 +1,3 @@
|
||||
from . import vps_server
|
||||
from . import res_partner
|
||||
from . import res_partner
|
||||
from . import proxmox_server
|
||||
Binary file not shown.
Binary file not shown.
38
ow_vm_management/models/proxmox_server.py
Normal file
38
ow_vm_management/models/proxmox_server.py
Normal 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))
|
||||
Reference in New Issue
Block a user