How to use the proxmoxer.backends.base_ssh.BaseBackend function in proxmoxer

To help you get started, we’ve selected a few proxmoxer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github swayf / proxmoxer / proxmoxer / backends / openssh.py View on Github external
login=self.username,
                                                        port=self.port,
                                                        timeout=self.timeout,
                                                        identity_file=self.identity_file)

    def _exec(self, cmd):
        if self.sudo:
            cmd = "sudo " + cmd
        ret = self.ssh_client.run(cmd, forward_ssh_agent=self.forward_ssh_agent)
        return ret.stdout, ret.stderr

    def upload_file_obj(self, file_obj, remote_path):
        self.ssh_client.scp((file_obj,), target=remote_path)


class Backend(BaseBackend):
    def __init__(self, host, user, configfile=None, port=22, timeout=5, forward_ssh_agent=False, sudo=False, identity_file=None):
        self.session = ProxmoxOpenSSHSession(host, user,
                                             configfile=configfile,
                                             port=port,
                                             timeout=timeout,
                                             forward_ssh_agent=forward_ssh_agent,
                                             sudo=sudo,
                                             identity_file=identity_file)
github swayf / proxmoxer / proxmoxer / backends / ssh_paramiko.py View on Github external
def _exec(self, cmd):
        if self.sudo:
            cmd = 'sudo ' + cmd
        session = self.ssh_client.get_transport().open_session()
        session.exec_command(cmd)
        stdout = session.makefile('rb', -1).read().decode()
        stderr = session.makefile_stderr('rb', -1).read().decode()
        return stdout, stderr

    def upload_file_obj(self, file_obj, remote_path):
        sftp = self.ssh_client.open_sftp()
        sftp.putfo(file_obj, remote_path)
        sftp.close()


class Backend(BaseBackend):
    def __init__(self, host, user, password=None, private_key_file=None, port=22, timeout=5, sudo=False):
        self.session = ProxmoxParamikoSession(host, user,
                                              password=password,
                                              private_key_file=private_key_file,
                                              port=port,
                                              timeout=timeout,
                                              sudo=sudo)