@@ -14,10 +14,10 @@ module Control.Distributed.Process.Backend.Azure
14
14
import System.Environment (getEnv )
15
15
import System.FilePath ((</>) , takeFileName )
16
16
import System.Environment.Executable (getExecutablePath )
17
- import System.Posix.Types (Fd )
18
17
import Data.Binary (encode , decode )
19
18
import Data.Digest.Pure.MD5 (md5 , MD5Digest )
20
- import qualified Data.ByteString.Lazy as BSL (ByteString , readFile , putStr , length , writeFile )
19
+ import qualified Data.ByteString.Char8 as BSSC (pack )
20
+ import qualified Data.ByteString.Lazy as BSL (ByteString , readFile , putStr )
21
21
import Data.Typeable (Typeable )
22
22
import Control.Applicative ((<$>) )
23
23
import Control.Monad (void )
@@ -40,12 +40,13 @@ import qualified Network.Azure.ServiceManagement as Azure
40
40
import qualified Network.SSH.Client.LibSSH2 as SSH
41
41
( withSSH2
42
42
, scpSendFile
43
- , withChannel
43
+ , withChannelBy
44
44
, Session
45
+ , readAllChannel
46
+ , writeAllChannel
45
47
)
46
48
import qualified Network.SSH.Client.LibSSH2.Foreign as SSH
47
49
( openChannelSession
48
- , retryIfNeeded
49
50
, channelExecute
50
51
, writeChannel
51
52
, channelSendEOF
@@ -55,10 +56,6 @@ import qualified Network.SSH.Client.LibSSH2.Errors as SSH
55
56
, NULL_POINTER
56
57
, getLastError
57
58
)
58
- import qualified Network.SSH.Client.LibSSH2.ByteString.Lazy as SSHBS
59
- ( writeChannel
60
- , readAllChannel
61
- )
62
59
63
60
-- CH
64
61
import Control.Distributed.Process
@@ -158,23 +155,23 @@ initializeBackend params = do
158
155
-- | Start a CH node on the given virtual machine
159
156
apiCopyToVM :: AzureParameters -> VirtualMachine -> IO ()
160
157
apiCopyToVM params vm =
161
- void . withSSH2 params vm $ \ fd s -> catchSshError s $
162
- SSH. scpSendFile fd s 0o700 (azureSshLocalPath params) (azureSshRemotePath params)
158
+ void . withSSH2 params vm $ \ s -> catchSshError s $
159
+ SSH. scpSendFile s 0o700 (azureSshLocalPath params) (azureSshRemotePath params)
163
160
164
161
-- | Call a process on a VM
165
162
apiCallOnVM :: Serializable a => AzureParameters -> Static (SerializableDict a ) -> VirtualMachine -> String -> Closure (Process a ) -> IO a
166
163
apiCallOnVM params dict vm port proc =
167
- withSSH2 params vm $ \ fd s -> do
164
+ withSSH2 params vm $ \ s -> do
168
165
let exe = " PATH=. " ++ azureSshRemotePath params
169
166
++ " onvm run "
170
167
++ " --host " ++ vmIpAddress vm
171
168
++ " --port " ++ port
172
169
++ " 2>&1"
173
- (_, r) <- SSH. withChannel (SSH. openChannelSession s) id fd s $ \ ch -> do
174
- SSH. retryIfNeeded fd s $ SSH. channelExecute ch exe
175
- cnt <- SSHBS. writeChannel fd ch (encode proc')
170
+ (_, r) <- SSH. withChannelBy (SSH. openChannelSession s) id $ \ ch -> do
171
+ SSH. channelExecute ch exe
172
+ _cnt <- SSH. writeAllChannel ch (encode proc')
176
173
SSH. channelSendEOF ch
177
- SSHBS . readAllChannel fd ch
174
+ SSH . readAllChannel ch
178
175
return (decode r)
179
176
where
180
177
proc' :: Closure (Process () )
@@ -184,15 +181,15 @@ apiCallOnVM params dict vm port proc =
184
181
apiCheckMD5 :: AzureParameters -> VirtualMachine -> IO Bool
185
182
apiCheckMD5 params vm = do
186
183
hash <- localHash params
187
- withSSH2 params vm $ \ fd s -> do
188
- (r, _) <- SSH. withChannel (SSH. openChannelSession s) id fd s $ \ ch -> do
189
- SSH. retryIfNeeded fd s $ SSH. channelExecute ch " md5sum -c --status"
190
- SSH. writeChannel ch $ show hash ++ " " ++ azureSshRemotePath params
184
+ withSSH2 params vm $ \ s -> do
185
+ (r, _) <- SSH. withChannelBy (SSH. openChannelSession s) id $ \ ch -> do
186
+ SSH. channelExecute ch " md5sum -c --status"
187
+ SSH. writeChannel ch . BSSC. pack $ show hash ++ " " ++ azureSshRemotePath params
191
188
SSH. channelSendEOF ch
192
- SSHBS . readAllChannel fd ch
189
+ SSH . readAllChannel ch
193
190
return (r == 0 )
194
191
195
- withSSH2 :: AzureParameters -> VirtualMachine -> (Fd -> SSH. Session -> IO a ) -> IO a
192
+ withSSH2 :: AzureParameters -> VirtualMachine -> (SSH. Session -> IO a ) -> IO a
196
193
withSSH2 params (Azure. vmSshEndpoint -> Just ep) =
197
194
SSH. withSSH2 (azureSshKnownHosts params)
198
195
(azureSshPublicKey params)
0 commit comments