git.iko.soy/distributed-process
on master help sign in
Start work on the Azure backend proper
commit67a52fac0df2f6386c0c24afa8e1d7acb5d51f39 authorEdsko de Vries <edsko@well-typed.com> dateFri 27 Jul 2012, 13:16 (14 years ago) parent9597323
3 files changed+68−14
distributed-process-azure/distributed-process-azure.cabal+4−3 distributed-process-azure/src/Control/Distributed/Process/Backend/Azure.hs+56−1 distributed-process-azure/src/Control/Distributed/Process/Backend/Azure/CommandLine.hs+8−10
distributed-process-azure/distributed-process-azure.cabal+4−3
@@ -20,7 +20,8 @@ Source-Repository head
2020
2121Library
2222 Build-Depends: base >= 4.4 && < 5,
23− azure-service-api
23+ azure-service-api >= 0.1 && < 0.2,
24+ filepath >= 1.3 && < 1.4
2425 Exposed-modules: Control.Distributed.Process.Backend.Azure
2526 ghc-options: -Wall
2627 HS-Source-Dirs: src
@@ -30,5 +31,5 @@ Executable cloud-haskell-azure
3031 Build-Depends: base >= 4.4 && < 5,
3132 utf8-string >= 0.3 && < 0.4,
3233 libssh2 >= 0.2 && < 0.3,
33− azure-service-api >= 0.1 && < 0.2,
34− filepath >= 1.3 && < 1.4
34+ filepath >= 1.3 && < 1.4,
35+ distributed-process-azure >= 0.1 && < 0.2
distributed-process-azure/src/Control/Distributed/Process/Backend/Azure.hs+56−1
@@ -1,3 +1,58 @@
1−module Control.Distributed.Process.Backend.Azure where
1+module Control.Distributed.Process.Backend.Azure
2+ ( -- * Initialization
3+ Backend(..)
4+ , AzureParameters(..)
5+ , defaultAzureParameters
6+ , initializeBackend
7+ -- * Re-exports from Azure Service Management
8+ , VirtualMachine(..)
9+ ) where
210
11+import System.Environment (getEnv)
12+import System.FilePath ((</>))
313import Network.Azure.ServiceManagement
14+ ( VirtualMachine
15+ , virtualMachines
16+ , azureSetup
17+ )
18+
19+-- | Azure backend
20+data Backend = Backend {
21+ findVMs :: IO [VirtualMachine]
22+ }
23+
24+data AzureParameters = AzureParameters {
25+ azureSubscriptionId :: String
26+ , azureAuthCertificate :: FilePath
27+ , azureAuthPrivateKey :: FilePath
28+ , azureSshPublicKey :: FilePath
29+ , azureSshPrivateKey :: FilePath
30+ , azureSshKnownHosts :: FilePath
31+ }
32+
33+-- | Create default azure parameters
34+defaultAzureParameters :: String -- ^ Azure subscription ID
35+ -> FilePath -- ^ Path to X509 certificate
36+ -> FilePath -- ^ Path to private key
37+ -> IO AzureParameters
38+defaultAzureParameters sid x509 pkey = do
39+ home <- getEnv "HOME"
40+ return AzureParameters
41+ { azureSubscriptionId = sid
42+ , azureAuthCertificate = x509
43+ , azureAuthPrivateKey = pkey
44+ , azureSshPublicKey = home </> ".ssh" </> "id_rsa.pub"
45+ , azureSshPrivateKey = home </> ".ssh" </> "id_rsa"
46+ , azureSshKnownHosts = home </> ".ssh" </> "known_hosts"
47+ }
48+
49+-- | Initialize the backend
50+initializeBackend :: AzureParameters -> IO Backend
51+initializeBackend params = do
52+ setup <- azureSetup (azureSubscriptionId params)
53+ (azureAuthCertificate params)
54+ (azureAuthPrivateKey params)
55+ return Backend {
56+ findVMs = virtualMachines setup
57+ }
58+
distributed-process-azure/src/Control/Distributed/Process/Backend/Azure/CommandLine.hs+8−10
@@ -1,13 +1,10 @@
1−-- Base
21import System.Environment (getArgs, getEnv)
32import System.FilePath ((</>))
43import System.Posix.Types (Fd)
5−
6−-- SSL
7−import Network.Azure.ServiceManagement
8− ( azureSetup
9− , virtualMachines
10− , vmSshEndpoints
4+import Control.Distributed.Process.Backend.Azure
5+ ( defaultAzureParameters
6+ , initializeBackend
7+ , findVMs
118 )
129
1310-- SSH
@@ -66,6 +63,7 @@ ssh login host port actions = do
6663
6764tryConnectToAzure :: String -> String -> String -> IO ()
6865tryConnectToAzure sid pathToCert pathToKey = do
69− setup <- azureSetup sid pathToCert pathToKey
70− vms <- virtualMachines setup
71− mapM_ print (map vmSshEndpoints vms)
66+ params <- defaultAzureParameters sid pathToCert pathToKey
67+ backend <- initializeBackend params
68+ vms <- findVMs backend
69+ mapM_ print vms