mirror of https://github.com/Aidaho12/haproxy-wi
parent
0371f730b1
commit
385a56c774
|
@ -3,6 +3,7 @@ import distro
|
|||
|
||||
from modules.db_model import *
|
||||
|
||||
from funct import check_ver
|
||||
|
||||
def default_values():
|
||||
if distro.id() == 'ubuntu':
|
||||
|
@ -655,6 +656,13 @@ def default_values():
|
|||
except Exception as e:
|
||||
print(str(e))
|
||||
|
||||
# Needs for insert version in first time
|
||||
def update_db_v_3_4_5_22():
|
||||
try:
|
||||
Version.insert(version='3.4.5.2').execute()
|
||||
except Exception as e:
|
||||
print('Cannot insert version %s' % e)
|
||||
|
||||
|
||||
# Needs for updating user_group. Do not delete
|
||||
def update_db_v_4_3_0():
|
||||
|
@ -955,6 +963,8 @@ def update_ver():
|
|||
|
||||
|
||||
def update_all():
|
||||
if check_ver() is None:
|
||||
update_db_v_3_4_5_22()
|
||||
update_db_v_4_3_0()
|
||||
update_db_v_5_2_4()
|
||||
update_db_v_5_2_4_1()
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import paramiko
|
||||
from paramiko import SSHClient
|
||||
|
||||
|
||||
class SshConnection:
|
||||
def __init__(self, server_ip, ssh_port, ssh_user_name, ssh_user_password, ssh_enable, ssh_key_name=None):
|
||||
self.ssh = SSHClient()
|
||||
|
@ -13,16 +14,26 @@ class SshConnection:
|
|||
self.ssh_enable = ssh_enable
|
||||
self.ssh_key_name = ssh_key_name
|
||||
|
||||
|
||||
def __enter__(self):
|
||||
try:
|
||||
if self.ssh_enable == 1:
|
||||
k = paramiko.pkey.load_private_key_file(self.ssh_key_name)
|
||||
self.ssh.connect(hostname=self.server_ip, port=self.ssh_port, username=self.ssh_user_name, pkey=k,
|
||||
timeout=11, banner_timeout=200)
|
||||
self.ssh.connect(
|
||||
hostname=self.server_ip,
|
||||
port=self.ssh_port,
|
||||
username=self.ssh_user_name, pkey=k,
|
||||
timeout=11,
|
||||
banner_timeout=200
|
||||
)
|
||||
else:
|
||||
self.ssh.connect(hostname=self.server_ip, port=self.ssh_port, username=self.ssh_user_name,
|
||||
password=self.ssh_user_password, timeout=11, banner_timeout=200)
|
||||
self.ssh.connect(
|
||||
hostname=self.server_ip,
|
||||
port=self.ssh_port,
|
||||
username=self.ssh_user_name,
|
||||
password=self.ssh_user_password,
|
||||
timeout=11,
|
||||
banner_timeout=200
|
||||
)
|
||||
except paramiko.AuthenticationException:
|
||||
raise paramiko.SSHException('error: Authentication failed, please verify your credentials')
|
||||
except paramiko.SSHException as sshException:
|
||||
|
@ -40,11 +51,9 @@ class SshConnection:
|
|||
raise paramiko.SSHException(str(e))
|
||||
return self
|
||||
|
||||
|
||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||
self.ssh.close()
|
||||
|
||||
|
||||
def run_command(self, command):
|
||||
try:
|
||||
stdin, stdout, stderr = self.ssh.exec_command(command, get_pty=True)
|
||||
|
@ -53,7 +62,6 @@ class SshConnection:
|
|||
|
||||
return stdin, stdout, stderr
|
||||
|
||||
|
||||
def get_sftp(self, config_path, cfg):
|
||||
try:
|
||||
sftp = self.ssh.open_sftp()
|
||||
|
@ -71,7 +79,6 @@ class SshConnection:
|
|||
except Exception as e:
|
||||
raise paramiko.SSHException(str(e))
|
||||
|
||||
|
||||
def put_sftp(self, file, full_path):
|
||||
try:
|
||||
sftp = self.ssh.open_sftp()
|
||||
|
|
Loading…
Reference in New Issue