I'm add new feature to Fabric:
I need deal this task: from client connect to cent os linux , and from the
linux connect to another linux :
like this:
def GenSSHKey():
#generate ssh key
with cd('~/'):
run("ssh-keygen -t rsa -f ~/.ssh/id_rsa -N ''")
run("ssh-copy-id -i ~/.ssh/id_rsa.pub cloudil@cent3")
but, second linux will prompt " Are you sure you want to continue connecting
(yes/no)? ",
task was freezed .
so, I modify the code io.py (line 147):
class OutputLooper -----> def loop ----->
if prompt:
self.prompt()
elif try_again:
self.try_again()
#add by lirudy 2012-11-2
expectObj = env.expectObj;
if expectObj :
expectObj.deal(self.capture, self.chan)
and, in my task, add class expectObj():
class expectObj():
expectDict = {
"Are you sure you want to continue connecting (yes/no)? " : "yes",
"cloudil@cent3's password: " : "1"
}
def findString(self, script, str):
tail = script[-1 * len(str):]
src = ''.join(tail)
start = src.find(str)
end = src.find('\n',start)
return start,end
def deal(self, src, channel):
for question in self.expectDict.keys():
start, end = self.findString(src, question)
if(start > -1):
val = self.expectDict[question]
#print("----"+question+" : "+ val)
channel.input_enabled = True
channel.sendall(val+'\n')
now, my task function is:
def GenSSHKey():
#generate ssh key
with cd('~/'):
env.expectObj = expectObj() ####### add question responser
run("ssh-keygen -t rsa -f ~/.ssh/id_rsa -N ''")
run("ssh-copy-id -i ~/.ssh/id_rsa.pub cloudil@cent3")
env.expectObj = None ####### clear it
so, maybe someone have same problem.
Thanks, Fabric is Great!
lirudy_______________________________________________
Fab-user mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/fab-user