git.iko.soy/distributed-process
on master help sign in
Make use of new libssh2 bytestring functionality
070b0dcEdsko de Vries
distributed-process-azure/src/Control/Distributed/Process/Backend/Azure.hs+8−10
@@ -15,12 +15,10 @@ import System.Environment.Executable (getExecutablePath)
15import System.Posix.Types (Fd)
15import System.Posix.Types (Fd)
16import Data.Binary (encode)
16import Data.Binary (encode)
17import Data.Digest.Pure.MD5 (md5, MD5Digest)
17import Data.Digest.Pure.MD5 (md5, MD5Digest)
18−import qualified Data.ByteString.Lazy as BSL (readFile)
18+import qualified Data.ByteString.Lazy as BSL (readFile, length)
19−import qualified Data.ByteString.Lazy.Char8 as BSLC (unpack)
20import Control.Applicative ((<$>))
19import Control.Applicative ((<$>))
21import Control.Monad (void)
20import Control.Monad (void)
22import Control.Exception (catches, Handler(Handler))
21import Control.Exception (catches, Handler(Handler))
23−import GHC.IO.Encoding (setForeignEncoding, char8)
24
22
25-- Azure
23-- Azure
26import Network.Azure.ServiceManagement
24import Network.Azure.ServiceManagement
@@ -40,7 +38,6 @@ import qualified Network.SSH.Client.LibSSH2 as SSH
40 , execCommands
38 , execCommands
41 , scpSendFile
39 , scpSendFile
42 , withChannel
40 , withChannel
43− , readAllChannel
44 , Session
41 , Session
45 )
42 )
46import qualified Network.SSH.Client.LibSSH2.Foreign as SSH
43import qualified Network.SSH.Client.LibSSH2.Foreign as SSH
@@ -55,6 +52,10 @@ import qualified Network.SSH.Client.LibSSH2.Errors as SSH
55 , NULL_POINTER
52 , NULL_POINTER
56 , getLastError
53 , getLastError
57 )
54 )
55+import qualified Network.SSH.Client.LibSSH2.ByteString.Lazy as SSHBS
56+ ( writeChannel
57+ , readAllChannel
58+ )
58
59
59-- CH
60-- CH
60import Control.Distributed.Process
61import Control.Distributed.Process
@@ -140,12 +141,9 @@ apiRunOnVM params vm port proc =
140 putStrLn $ "Executing " ++ show exe
141 putStrLn $ "Executing " ++ show exe
141 r <- SSH.withChannel (SSH.openChannelSession s) id fd s $ \ch -> do
142 r <- SSH.withChannel (SSH.openChannelSession s) id fd s $ \ch -> do
142 SSH.retryIfNeeded fd s $ SSH.channelExecute ch exe
143 SSH.retryIfNeeded fd s $ SSH.channelExecute ch exe
143− let enc = encode proc
144− putStrLn $ "Sending closure of size " ++ show (length (BSLC.unpack enc))
145− setForeignEncoding char8
146− SSH.writeChannel ch $ BSLC.unpack enc
144+ SSHBS.writeChannel fd ch (encode proc)
147 SSH.channelSendEOF ch
145 SSH.channelSendEOF ch
148− SSH.readAllChannel fd ch
146+ SSHBS.readAllChannel fd ch
149 print r
147 print r
150
148
151-- | Check the MD5 hash of the executable on the remote machine
149-- | Check the MD5 hash of the executable on the remote machine
@@ -157,7 +155,7 @@ apiCheckMD5 params vm = do
157 SSH.retryIfNeeded fd s $ SSH.channelExecute ch "md5sum -c --status"
155 SSH.retryIfNeeded fd s $ SSH.channelExecute ch "md5sum -c --status"
158 SSH.writeChannel ch $ show hash ++ " " ++ azureSshRemotePath params
156 SSH.writeChannel ch $ show hash ++ " " ++ azureSshRemotePath params
159 SSH.channelSendEOF ch
157 SSH.channelSendEOF ch
160− SSH.readAllChannel fd ch
158+ SSHBS.readAllChannel fd ch
161 return (r == 0)
159 return (r == 0)
162
160
163withSSH2 :: AzureParameters -> VirtualMachine -> (Fd -> SSH.Session -> IO a) -> IO a
161withSSH2 :: AzureParameters -> VirtualMachine -> (Fd -> SSH.Session -> IO a) -> IO a