Track end of command exec from lxd properly
Track end of command exec from lxd properly

The bug presented as the operation not still existing at the lxd
daemon when the end of the command was reached.  After much testing,
it seemed that the pylxd client was closing the websockets when the
empty message was received on them, which turned out to be too late
for some kinds of output.  Instead, tracking when the operation
completed, and then waiting for the sockets to close meant that the
return code of the command could be obtained, and the wait for the
sockets to be closed by the lxd daemon ensured completion.  The code
also waits for the ws4py manager to clean up and waits on the threads to
end.  This helps with multiple commands.

Signed-off-by: Alex Kavanagh <60c6d277a8bd81de7fdde19201bf9c58a3df08f4@ajkavanagh.co.uk>

lxc/pylxd,lxc/pylxd