0

I am implementing few application which will run in remote Machines over ssh protocol.

I have opted paramiko to perform ssh connections.

I have below VM's

  1. Control VM----> This machine has trigger.py and remote.py scripts
  2. remote VM1----> This has time1.py script
  3. remote VM2----> This has time1.py script

I am using Threading script and when I am hitting Ctrl z and Program is not terminating . Can any fix a problem. i am thinking it may be bug..

trigger.py is used execute script:

def time_trigger(ip):
    """
    Trigger Onboard Deploy
    """
    cmd = ""
    remote.remote_cmd(ip, cmd)

    t1 = threading.Thread(target=time_trigger, args=(ip1,))
    t2 = threading.Thread(target=time_trigger, args=(ip2,))
    t1.start()
    t2.start()
    t1.join()
    t2.join()

remote.py script is used to establish remote ssh connection:

import paramiko
import os
from paramiko import SSHClient
from scp import SCPClient

class Remote:
    def __init__(self, username, password, port):
        self.port = port
        self.user = username
        self.password = password

    def createSSHClient(self, server):
        client = paramiko.SSHClient()
        client.load_system_host_keys()
        client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        client.connect(server, self.port, self.user, self.password)
        return client

    def remote_cmd(self, hostname, command):
        try:
            client = paramiko.SSHClient()
            client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
            client.connect(hostname, port=self.port, username=self.user, password=self.password)
            stdin, stdout, stderr = client.exec_command(command)
            print stdout.read()

        finally:
            client.close()

time1.py (wait 5 Mins):

 import time
 time.sleep(300)

I am using Python 2.7

Dev Ops Ranga
  • 203
  • 6
  • 15

0 Answers0