[NEW] refactoring of maintenance_server_monitoring in several modules

This commit is contained in:
clementthomas
2024-04-09 15:51:10 +02:00
parent 661a5b597a
commit 648e5f038a
26 changed files with 588 additions and 199 deletions

View File

@@ -10,11 +10,18 @@ class MaintenanceEquipment(models.Model):
server_domain = fields.Char('Server Domain')
ssh_private_key_path = fields.Char("SSH private key path", default="/opt/odoo/auto/dev/ssh_keys/id_rsa")
def get_ssh_connection(self):
def get_ssh_connection(self):
ssh_connections = self.env.context.get('ssh_connections',{})
if self.id in ssh_connections:
return ssh_connections[self.id]
import paramiko
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(self.server_domain, username="root", key_filename=self.ssh_private_key_path)
ssh_connections[self.id] = ssh
self = self.with_context(ssh_connections=ssh_connections)
return ssh