Answer the question
In order to leave comments, you need to log in
Proxmox | Python | Paramiko | Entering a container?
Greetings!
Essence of a question: There is a server that works at proxmox. There are containers that are spinning there. Can someone please suggest a way to write a method to "inject" into a container through a server we ssh into using Paramiko?
What do we have?
1. SSH class with initialization
2. A method that implements a connection to the server using already known parameters.
def connect_to_server(self):
try:
self.client.connect(hostname=self.connection, username=self.login, password=self.password, port=22,
auth_timeout=True, timeout=5)
except ssh.ssh_exception.AuthenticationException:
print('Ошибка при логировании на сервер')
self.close_connection()
except socket.error:
print("Сервер недоступен!")
self.close_connection()
def show_containers(self):
if not self.closeSSH:
stdin, stdout, stderr = self.client.exec_command("pct list", get_pty=True)
stdin.write('')
stdin.flush()
data = stdout.read() + stderr.read()
print(data.decode())
else:
return "No connection to server"
.exec_command("cat /etc/hostname, get_pty=True)
def enter_to_server(self):
if not self.closeSSH:
self.client.exec_command("pct enter 81103", get_pty=True) [Заходим внутрь контейнера]
stdin, stdout, stderr = self.client.exec_command("cat /etc/hostname", get_pty=True) [Пытаемся узнать имя контейнера]
stdin.write('')
stdin.flush()
data = stdout.read() + stderr.read()
print(data.decode()) [Выводит "mainserver"]
else:
return "No connection to server"
def enter_to_server(self):
if not self.closeSSH:
stdin, stdout, stderr = self.client.exec_command("pct enter 81103", get_pty=True)
stdin.write('')
stdin.flush()
data = stdout.read() + stderr.read()
print(data.decode())
else:
return "No connection to server"
stdin, stdout, stderr = self.client.exec_command("pct enter 81103", get_pty=True)
Answer the question
In order to leave comments, you need to log in
I am not an expert in python, but I can tell you something:
stdin, stdout, stderr = self.client.exec_command("echo 'pwd ; exit' | pct enter 81103", get_pty=True)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question