@@ -18,6 +18,7 @@ import Data.Binary (encode, decode)
18import Data.Digest.Pure.MD5 (md5, MD5Digest)
18import Data.Digest.Pure.MD5 (md5, MD5Digest)
19import qualified Data.ByteString.Char8 as BSSC (pack)
19import qualified Data.ByteString.Char8 as BSSC (pack)
20import qualified Data.ByteString.Lazy as BSL (ByteString, readFile, putStr, writeFile)
20import qualified Data.ByteString.Lazy as BSL (ByteString, readFile, putStr, writeFile)
21+import qualified Data.ByteString.Lazy.Char8 as BSLC (unpack)
21import Data.Typeable (Typeable)
22import Data.Typeable (Typeable)
22import Control.Applicative ((<$>))
23import Control.Applicative ((<$>))
23import Control.Monad (void)
24import Control.Monad (void)
@@ -171,12 +172,14 @@ apiCallOnVM params dict vm port proc =
171 ++ " --host " ++ vmIpAddress vm
172 ++ " --host " ++ vmIpAddress vm
172 ++ " --port " ++ port
173 ++ " --port " ++ port
173 ++ " 2>&1"
174 ++ " 2>&1"
174− (_, r) <- SSH.withChannelBy (SSH.openChannelSession s) id $ \ch -> do
175+ (status, r) <- SSH.withChannelBy (SSH.openChannelSession s) id $ \ch -> do
175 SSH.channelExecute ch exe
176 SSH.channelExecute ch exe
176 _cnt <- SSH.writeAllChannel ch (encode $ proc `cpBind` cpEncodeToStdout dict)
177 _cnt <- SSH.writeAllChannel ch (encode $ proc `cpBind` cpEncodeToStdout dict)
177 SSH.channelSendEOF ch
178 SSH.channelSendEOF ch
178 SSH.readAllChannel ch
179 SSH.readAllChannel ch
179− return (decode r)
181+ then return $ decode r
182+ else error (BSLC.unpack r)
181apiSpawnOnVM :: AzureParameters -> VirtualMachine -> String -> Closure (Process ()) -> IO ()
184apiSpawnOnVM :: AzureParameters -> VirtualMachine -> String -> Closure (Process ()) -> IO ()
182apiSpawnOnVM params vm port proc =
185apiSpawnOnVM params vm port proc =
@@ -188,12 +191,14 @@ apiSpawnOnVM params vm port proc =
188 ++ " --background "
191 ++ " --background "
189 ++ " 2>&1"
192 ++ " 2>&1"
190 BSL.writeFile "closure" (encode proc)
193 BSL.writeFile "closure" (encode proc)
191− r <- SSH.withChannelBy (SSH.openChannelSession s) id $ \ch -> do
194+ (status, r) <- SSH.withChannelBy (SSH.openChannelSession s) id $ \ch -> do
192 SSH.channelExecute ch exe
195 SSH.channelExecute ch exe
193 _cnt <- SSH.writeAllChannel ch (encode proc)
196 _cnt <- SSH.writeAllChannel ch (encode proc)
194 SSH.channelSendEOF ch
197 SSH.channelSendEOF ch
195 SSH.readAllChannel ch
198 SSH.readAllChannel ch
196− print r
199+ if status == 0
201+ else error (BSLC.unpack r)
198-- | Check the MD5 hash of the executable on the remote machine
203-- | Check the MD5 hash of the executable on the remote machine
199apiCheckMD5 :: AzureParameters -> VirtualMachine -> IO Bool
204apiCheckMD5 :: AzureParameters -> VirtualMachine -> IO Bool