def prepare_ssh(self): ssh_item = self.image.get('tests.ssh') if ssh_item and self.ip: self.ssh = ssh.SSH(ip=self.ip, username=ssh_item['username'], private_key=self.os_key.private_key, port=ssh_item.get('port', 22))
def host_connect(): """ Handle host connectivity to DUT """ global DUT_CLIENT DUT_CLIENT = ssh.SSH(host=DUT_IP, user=DUT_USER, password=DUT_PWD) print("DUT Successfully Connected ..............................................[OK] \n ")
def __init__(self): logger.setLevel(conf.verbose) self.ssh = ssh.SSH() if self.ssh.loadDbConfig(): self.dao = Database() else: raise Exception("Lychee configuration file not found. Please check the path to Lychee installation")
def BOOTFLASH(ip, username='******', password='******', hostname='#'): try: hn = ssh.SSH(ip, username, password, hostname) hn.sendline('term len 0') hn.expect('#', 60) hn.sendline('term width 511') hn.expect('#', 60) hn.sendline('config t') hn.expect('#', 60) hn.sendline('feature bash') hn.expect('#', 60) hn.sendline('run bash') hn.expect('\$', 60) print hn.before hn.sendline('ls -ltr /bootflash/') hn.expect('\$', 60) dat = hn.before out = re.split('\n', dat) data = [] #print out for i in out: tmp = re.split('\s+', i) if len(tmp) == 10 and tmp[-2][:4] == 'nxos': data.append(tmp) if len(data) > 0: del_image = data[0][-2] else: del_image = 'NULL' #print '>>>old image in the system {}<<<'.format(del_image) hn.sendline('exit') hn.expect('#', 60) hn.sendline('term len 0') hn.expect('#', 60) hn.sendline('dir bootflash:') hn.expect('total', 60) bspace = re.findall('\d+', hn.before) #print bspace free_space = int(bspace[-2]) #print 'Free space in bootflash: {}'.format(free_space) hn.close() return free_space, del_image except: print "Bootflash_size: Problem using ssh to", ip print hn.before return 0, 0
def exec_ssh(self, host, cmd, timeout=None): #SSH in, assuming passwordless authentication try: s = ssh.SSH(self.user, host, "") except paramiko.SSHException: logger.error("Unable to connect to %s@%s!", self.user, host) return logger.debug("Connected to %s@%s", self.user, host) start_time = time.time() #Execute the command and get output from STDOUT result = s.run(cmd, timeout) #Timed out error code if result["exit"] != 137: logger.debug("Execution took %.2f seconds and returned %s" \ % (time.time() - start_time, result["exit"])) else: logger.critical("command timed out!") return [result["out"], result["err"], result["exit"]]
#response = ec2_client.run_instances(**config) response = ec2_client.start_instances(InstanceIds=[args.instance_id1, args.instance_id2]) print(response) ################################################################ # Create SSH interface to all instances # Runs in loop while waiting for instances to be ready ################################################################ import ssh from time import sleep while True: try: instances = [instance['InstanceId'] for instance in response['StartingInstances']] status = ec2_resource.meta.client.describe_instances(InstanceIds=instances) public_ips = [instance['PublicIpAddress'] for instance in status['Reservations'][0]['Instances']] ssh_client = ssh.SSH(public_ips, keypair) # wait a few seconds and run a simple command to make sure instances are up pci = ssh_client.run_on_all('lspci') break except: sleep(10) continue print(pci[0]['stdout']) ''################################################################ # Use local AWS credentials for EC2 ################################################################ '''import getpass import configparser credentials = configparser.ConfigParser()
def generate_revision_key(self, url, ud, d): key = self._revision_key(url, ud, d) return "%s-%s" % (key, bb.data.getVar("PN", d, True) or "") import cvs import git import local import svn import wget import svk import ssh import perforce import bzr import hg import osc import repo methods.append(local.Local()) methods.append(wget.Wget()) methods.append(svn.Svn()) methods.append(git.Git()) methods.append(cvs.Cvs()) methods.append(svk.Svk()) methods.append(ssh.SSH()) methods.append(perforce.Perforce()) methods.append(bzr.Bzr()) methods.append(hg.Hg()) methods.append(osc.Osc()) methods.append(repo.Repo())
import sys import net_parse import ssh import telnet import pexpect if len(sys.argv) != 3: print "usage python2 console.py <device name> <method cons|ssh>" sys.exit() dev = sys.argv[1] method = sys.argv[2] username = '******' password = '******' fdata = net_parse.DICT('device_info.cfg') for i in fdata: if dev == i['host_name']: ip = i['mgmt_ip'] hostname = i['host_name'] if method == 'ssh': handler = ssh.SSH(ip, username, password, hostname) print "connected to device {}:{}".format(hostname, ip) handler.interact() elif method == 'cons': terms = 0 handler = telnet.TELNET(ip, username, password, terms) handler.interact() print "connection closed for ip", ip, hostname
#t = ph.createPackage(name="test_package_4", owners=users, dominion="strong", autoReview="block", auditing=None, description=None, # status="active", paths_set=None, view="users", edit="users") # main scenario # input parameters usersToAdd = ["AAAAA", "Ptester"] projectName = "TestFull5" ad = cldap.CLDAP() group_exists = ad.checkGroup(group="test") if not group_exists: print("At least one of AD groups not found") exit(-1) time.sleep(2) ssh = ssh.SSH() ssh.exec_script(repo=projectName) # Step 1 : get users id from given names users = [] for user in usersToAdd: try: _user = ph.findUser(user) except Exception as e: print("Error message : " + str(e)) continue users.append(_user) for i in users: print(i) # Step 2 : create project with given name and members
import ssh ptySSH = ssh.SSH("127.0.0.1", "xxx", "yyy", 22) # create SSH object and reuse it for different commands print ptySSH.push('./t.sh', '~') # copy the test shell script to server print ptySSH.cmd('rm -r ~/output') print ptySSH.cmd('mkdir ~/output') # generate an output folder that's gonna collect all the outputs print ptySSH.cmd('~/t.sh') # run the test shell script print ptySSH.cmd('rm ~/t.sh') print ptySSH.pull_dir('~/output', '.') # copy the output folder back to local print ptySSH.cmd('rm -rf ~/output') # remove the generated output on server is optional
def __init__(self, log, gitconfig): super(Git, self).__init__() self.log = log self.ssh = ssh.SSH(log) self.config = gitconfig