@@ -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+