git.iko.soy/distributed-process
on master help sign in
Start work on the Azure backend proper
67a52faEdsko de Vries
distributed-process-azure/distributed-process-azure.cabal+4−3
@@ -20,7 +20,8 @@ Source-Repository head
20
20
21Library
21Library
22 Build-Depends: base >= 4.4 && < 5,
22 Build-Depends: base >= 4.4 && < 5,
23− azure-service-api
23+ azure-service-api >= 0.1 && < 0.2,
24+ filepath >= 1.3 && < 1.4
24 Exposed-modules: Control.Distributed.Process.Backend.Azure
25 Exposed-modules: Control.Distributed.Process.Backend.Azure
25 ghc-options: -Wall
26 ghc-options: -Wall
26 HS-Source-Dirs: src
27 HS-Source-Dirs: src
@@ -30,5 +31,5 @@ Executable cloud-haskell-azure
30 Build-Depends: base >= 4.4 && < 5,
31 Build-Depends: base >= 4.4 && < 5,
31 utf8-string >= 0.3 && < 0.4,
32 utf8-string >= 0.3 && < 0.4,
32 libssh2 >= 0.2 && < 0.3,
33 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
2
10
11+import System.Environment (getEnv)
12+import System.FilePath ((</>))
3import Network.Azure.ServiceManagement
13import 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
2import System.Environment (getArgs, getEnv)
1import System.Environment (getArgs, getEnv)
3import System.FilePath ((</>))
2import System.FilePath ((</>))
4import System.Posix.Types (Fd)
3import System.Posix.Types (Fd)
5−
4+import Control.Distributed.Process.Backend.Azure
6−-- SSL
5+ ( defaultAzureParameters
7−import Network.Azure.ServiceManagement
6+ , initializeBackend
8− ( azureSetup
7+ , findVMs
9− , virtualMachines
10− , vmSshEndpoints
11 )
8 )
12
9
13-- SSH
10-- SSH
@@ -66,6 +63,7 @@ ssh login host port actions = do
66
63
67tryConnectToAzure :: String -> String -> String -> IO ()
64tryConnectToAzure :: String -> String -> String -> IO ()
68tryConnectToAzure sid pathToCert pathToKey = do
65tryConnectToAzure sid pathToCert pathToKey = do
69− setup <- azureSetup sid pathToCert pathToKey
66+ params <- defaultAzureParameters sid pathToCert pathToKey
70− vms <- virtualMachines setup
67+ backend <- initializeBackend params
68+ vms <- findVMs backend
71− mapM_ print (map vmSshEndpoints vms)
69+ mapM_ print vms