Log In | Get Help   
Home My Page Projects Code Snippets Project Openings BonFIRE VCOC Demonstration Kit
Summary Activity SCM Files Wiki
[bonfiredemokit] Annotation of /ea/ssh_test.py
[bonfiredemokit] / ea / ssh_test.py Repository:
ViewVC logotype

Annotation of /ea/ssh_test.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 14 - (view) (download) (as text)

1 : agomez 10 #
2 :     # BonFIRE Virtual Clusters on Federated Clouds Demonstration Kit
3 :     #
4 :     # Copyright (c) Fundacion Centro Tecnologico de Supercomputacion de Galicia 2012
5 :     #
6 : agomez 14 # License Apache Software
7 : agomez 10 #
8 :     # The research leading to these results has received funding from
9 :     # the European Community's Seventh Framework Programme (FP7/2007-2013)
10 :     # under agreement number 257386
11 :     #
12 :     # This software is provided with ABSOLUTELY NO WARRANTY
13 :     #
14 :     '''
15 :     Created on 30/01/2012
16 :    
17 :     @author: R. Valin
18 :     '''
19 :     import os
20 :     import time
21 :     import subprocess as sub
22 :    
23 :     """
24 :     ###################################################################
25 :     # Es necesario hacer comparacion name in out y no al reves #
26 :     # ya que salida devuelve hostname con \n y si no no se cumple cond#
27 :     ###################################################################
28 :     """
29 :    
30 :     def ssh_open(ip, name):
31 :    
32 :     #cmd = 'ssh -o "StrictHostKeyChecking no"'+ip+' hostname'
33 :     cmd = 'ssh -v '+ip+' hostname'
34 :     print cmd
35 :     #p=os.popen(cmd)
36 :     #a=os.system(cmd)
37 :     out = '**'
38 :     j = 0
39 :     print name
40 :     while name not in out and j<40:
41 :     try:
42 :     #print 'abro popen'
43 :     fout = sub.Popen(cmd,bufsize=-1,shell=True,stdout=sub.PIPE, stderr=sub.STDOUT,close_fds=True)
44 :     #print 'salgo popen'
45 :     out,err =fout.communicate(input=None)
46 :     # print 'communicate'
47 :     j = j + 1;
48 :     except ValueError, msg:
49 :     print 'Error', msg, err
50 :     else:
51 :     if name not in out and j < 40:
52 :     print 'Host not available', j
53 :     time.sleep(float(5))
54 :     elif name not in out and j >= 40:
55 :     print 'Sobrepasado el numero de intentos. 40'
56 :     if j < 40 and name in out:
57 :     print 'Host:', name, 'is ssh available', ip
58 :    
59 :     def ssh_close(ip, name):
60 :    
61 :     cmd = 'ssh -o "StrictHostKeyChecking no" '+ip
62 :     #p=os.popen(cmd)
63 :     #a=os.system(cmd)
64 :     fout = sub.Popen(cmd,bufsize=-1,shell=True,stdout=sub.PIPE, stderr=sub.STDOUT)
65 :     out,err =fout.communicate()
66 :     #out = fout.read()
67 :     #print 'out', out
68 :     #out ='pontevedra'
69 :     #out = '**'
70 :     j = 1
71 :     while name in out and j <40:
72 :     try:
73 :     fout = sub.Popen(cmd,bufsize=-1,shell=True,stdout=sub.PIPE, stderr=sub.STDOUT,close_fds=True)
74 :     out,err =fout.communicate(input=None)
75 :     j = j + 1;
76 :     except ValueError, msg:
77 :     print 'Error', msg, err
78 :     else:
79 :     if name in out and j < 40:
80 :     print 'Host available', out, ip, j, err
81 :     time.sleep(float(5))
82 :     elif name in out and j >= 40:
83 :     print 'Sobrepasado el numero de intentos. 40'
84 :     if j < 40 and name not in out:
85 :     print 'Host:', name, 'is not ssh available', j
86 :    
87 :    
88 :     def ssh_qhost(ip):
89 :     "Comprobacion del qhost"
90 :     #
91 :     cmd = 'ssh -q '+ip+' qhost -xml'
92 :     out='command not found'
93 :     while 'command not found' in out:
94 :     fout = sub.Popen(cmd,bufsize=-1,shell=True,stdout=sub.PIPE, stderr=sub.STDOUT)
95 :     out,err =fout.communicate()
96 :    
97 :     #print 'Salida qhost', out
98 :     return out
99 :    
100 :    
101 :    
102 :    
103 :     #ssh_open('193.144.44.218', 'pontevedra')
104 :     #import paramiko
105 :    
106 :     #def ssh_open(ip):
107 :     #
108 :     # #cmd='ssh '+ip
109 :     # #print(os.system(cmd))
110 :     #
111 :     # # ssh config file
112 :     # config = paramiko.SSHConfig()
113 :     # file1=open('/home/cesga/.ssh/config', 'r')
114 :     # print ip
115 :     # config.parse(file1)
116 :     # o = config.lookup('ip')
117 :     # print 'nada', o
118 :     # #print 'Dame el passwd para la clave'
119 :     # #passwd=input()
120 :     # #print passwd
121 :     # try:
122 :     # #result=ssh.connect(ip, password=passwd)
123 :     # ssh = paramiko.SSHClient()
124 :     # ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
125 :     # ssh.connect(ip)
126 :     # #except StandardError:
127 :     # except StandardError, msg:
128 :     # print 'Error:', msg
129 :     #
130 :     # else:
131 :     # try:
132 :     # stdin, stdout, stderr=ssh.exec_command("hostname")
133 :     # except StandardError, msg:
134 :     # print 'Error:', msg
135 :     # for i in stdout:
136 :     # print i
137 :     # ssh.close()
138 :     #
139 :    
140 :    
141 :    

root@forge.cesga.es
ViewVC Help
Powered by ViewVC 1.0.0  

Powered By FusionForge