self._display.vvvv("connection to %s failed, retrying..."%self._play_context.remote_addr)
time.sleep(0.1)
tries-=1
iftries==0:
self._display.vvv("Could not connect via the accelerated connection, exceeded # of tries")
raiseAnsibleConnectionFailure("Failed to connect to %s on the accelerated port %s"%(self._play_context.remote_addr,self._play_context.accelerate_port))
elifwrong_user:
self._display.vvv("Restarting daemon with a different remote_user")
raiseAnsibleError("The accelerated daemon was started on the remote with a different user")
self.conn.settimeout(C.ACCELERATE_TIMEOUT)
ifnotself.validate_user():
# the accelerated daemon was started with a
# different remote_user. The above command
# should have caused the accelerate daemon to
# shutdown, so we'll reconnect.
wrong_user=True
self._connected=True
returnself
defsend_data(self,data):
@ -173,25 +97,25 @@ class Connection(ConnectionBase):
header_len=8# size of a packed unsigned long long
data=b""
try:
vvvv("%s: in recv_data(), waiting for the header"%self.host)
self._display.vvvv("%s: in recv_data(), waiting for the header"%self._play_context.remote_addr)
whilelen(data)<header_len:
d=self.conn.recv(header_len-len(data))
ifnotd:
vvvv("%s: received nothing, bailing out"%self.host)
self._display.vvvv("%s: received nothing, bailing out"%self._play_context.remote_addr)
returnNone
data+=d
vvvv("%s: got the header, unpacking"%self.host)
self._display.vvvv("%s: got the header, unpacking"%self._play_context.remote_addr)
data_len=struct.unpack('!Q',data[:header_len])[0]
data=data[header_len:]
vvvv("%s: data received so far (expecting %d): %d"%(self.host,data_len,len(data)))
self._display.vvvv("%s: data received so far (expecting %d): %d"%(self._play_context.remote_addr,data_len,len(data)))
whilelen(data)<data_len:
d=self.conn.recv(data_len-len(data))
ifnotd:
vvvv("%s: received nothing, bailing out"%self.host)
self._display.vvvv("%s: received nothing, bailing out"%self._play_context.remote_addr)
returnNone
vvvv("%s: received %d bytes"%(self.host,len(d)))
self._display.vvvv("%s: received %d bytes"%(self._play_context.remote_addr,len(d)))
data+=d
vvvv("%s: received all of the data, returning"%self.host)
self._display.vvvv("%s: received all of the data, returning"%self._play_context.remote_addr)
returndata
exceptsocket.timeout:
raiseAnsibleError("timed out while waiting to receive data")
@ -203,32 +127,32 @@ class Connection(ConnectionBase):
daemontoexitiftheydon't match
'''
vvvv("%s: sending request for validate_user"%self.host)
self._display.vvvv("%s: sending request for validate_user"%self._play_context.remote_addr)
data=dict(
mode='validate_user',
username=self.user,
username=self._play_context.remote_user,
)
data=utils.jsonify(data)
data=utils.encrypt(self.key,data)
data= jsonify(data)
data=keyczar_encrypt(self.key,data)
ifself.send_data(data):
raiseAnsibleError("Failed to send command to %s"%self.host)
raiseAnsibleError("Failed to send command to %s"%self._play_context.remote_addr)
vvvv("%s: waiting for validate_user response"%self.host)
self._display.vvvv("%s: waiting for validate_user response"%self._play_context.remote_addr)
whileTrue:
# we loop here while waiting for the response, because a
# long running command may cause us to receive keepalive packets
# ({"pong":"true"}) rather than the response we want.
response=self.recv_data()
ifnotresponse:
raiseAnsibleError("Failed to get a response from %s"%self.host)
response=utils.decrypt(self.key,response)
response=utils.parse_json(response)
raiseAnsibleError("Failed to get a response from %s"%self._play_context.remote_addr)
response=keyczar_decrypt(self.key,response)
response=json.loads(response)
if"pong"inresponse:
# it's a keepalive, go back to waiting
vvvv("%s: received a keepalive packet"%self.host)
self._display.vvvv("%s: received a keepalive packet"%self._play_context.remote_addr)
continue
else:
vvvv("%s: received the validate_user response: %s"%(self.host,response))
self._display.vvvv("%s: received the validate_user response: %s"%(self._play_context.remote_addr,response))
break
ifresponse.get('failed'):
@ -236,32 +160,30 @@ class Connection(ConnectionBase):
raiseAnsibleError('Incorrect permissions on the private key directory. Use `chmod 0%o%s` to correct this issue, and make sure any of the keys files contained within that directory are set to 0%o'%(int(C.ACCELERATE_KEYS_DIR_PERMS,8),C.ACCELERATE_KEYS_DIR,int(C.ACCELERATE_KEYS_FILE_PERMS,8)))
key_path=os.path.join(key_path,hostname)
# use new AES keys every 2 hours, which means fireball must not allow running for longer either
raiseAnsibleError('Incorrect permissions on the key file for this host. Use `chmod 0%o%s` to correct this issue.'%(int(C.ACCELERATE_KEYS_FILE_PERMS,8),key_path))