@@ -6,29 +6,46 @@ module Control.Distributed.Process.Backend.Azure
6 , initializeBackend
6 , initializeBackend
7 -- * Re-exports from Azure Service Management
7 -- * Re-exports from Azure Service Management
8 , CloudService(..)
8 , CloudService(..)
11import System.Environment (getEnv)
12import System.Environment (getEnv)
12import System.FilePath ((</>))
13import System.FilePath ((</>))
13import System.Environment.Executable (getExecutablePath)
14import System.Environment.Executable (getExecutablePath)
15+import Control.Concurrent (threadDelay)
14import Network.Azure.ServiceManagement
16import Network.Azure.ServiceManagement
15− ( CloudService )
17+ ( CloudService(..)
16import qualified Network.Azure.ServiceManagement as Azure
21import qualified Network.Azure.ServiceManagement as Azure
17 ( cloudServices
22 ( cloudServices
18 , AzureSetup
23 , AzureSetup
19 , azureSetup
24 , azureSetup
27+import qualified Network.SSH.Client.LibSSH2 as SSH
31+import qualified Network.SSH.Client.LibSSH2.Foreign as SSH
22-- | Azure backend
37-- | Azure backend
23data Backend = Backend {
38data Backend = Backend {
24 -- | Find virtual machines
39 -- | Find virtual machines
25 cloudServices :: IO [CloudService]
40 cloudServices :: IO [CloudService]
41+ , startOnVM :: VirtualMachine -> IO ()
28data AzureParameters = AzureParameters {
44data AzureParameters = AzureParameters {
29 azureSubscriptionId :: String
45 azureSubscriptionId :: String
30 , azureAuthCertificate :: FilePath
46 , azureAuthCertificate :: FilePath
31 , azureAuthPrivateKey :: FilePath
47 , azureAuthPrivateKey :: FilePath
48+ , azureSshUserName :: FilePath
32 , azureSshPublicKey :: FilePath
49 , azureSshPublicKey :: FilePath
33 , azureSshPrivateKey :: FilePath
50 , azureSshPrivateKey :: FilePath
34 , azureSshKnownHosts :: FilePath
51 , azureSshKnownHosts :: FilePath
@@ -41,10 +58,12 @@ defaultAzureParameters :: String -- ^ Azure subscription ID
41 -> IO AzureParameters
58 -> IO AzureParameters
42defaultAzureParameters sid x509 pkey = do
59defaultAzureParameters sid x509 pkey = do
43 home <- getEnv "HOME"
60 home <- getEnv "HOME"
61+ user <- getEnv "USER"
44 return AzureParameters
62 return AzureParameters
45 { azureSubscriptionId = sid
63 { azureSubscriptionId = sid
46 , azureAuthCertificate = x509
64 , azureAuthCertificate = x509
47 , azureAuthPrivateKey = pkey
65 , azureAuthPrivateKey = pkey
66+ , azureSshUserName = user
48 , azureSshPublicKey = home </> ".ssh" </> "id_rsa.pub"
67 , azureSshPublicKey = home </> ".ssh" </> "id_rsa.pub"
49 , azureSshPrivateKey = home </> ".ssh" </> "id_rsa"
68 , azureSshPrivateKey = home </> ".ssh" </> "id_rsa"
50 , azureSshKnownHosts = home </> ".ssh" </> "known_hosts"
69 , azureSshKnownHosts = home </> ".ssh" </> "known_hosts"
@@ -60,4 +79,21 @@ initializeBackend params = do
61 return Backend {
80 return Backend {
62 cloudServices = Azure.cloudServices setup
81 cloudServices = Azure.cloudServices setup
82+ , startOnVM = apiStartOnVM params
85+-- | Start a CH node on the given virtual machine
86+apiStartOnVM :: AzureParameters -> VirtualMachine -> IO ()
87+apiStartOnVM params vm = do
88+ _ <- SSH.initialize True
89+ let ep = Azure.vmSshEndpoint vm
90+ SSH.withSSH2 (azureSshKnownHosts params)
91+ (azureSshPublicKey params)
92+ (azureSshPrivateKey params)
93+ (azureSshUserName params)
95+ (read $ endpointPort ep) $ \fd s ch -> do
96+ _ <- SSH.retryIfNeeded fd s $ SSH.channelExecute ch "/home/edsko/testservice"
97+ threadDelay $ 10 * 1000000 -- 10 seconds