git.iko.soy/distributed-process
on master help sign in
Better naming
commita81f853a99cbf7b7920c412d8d8a110729068d6a authorEdsko de Vries <edsko@well-typed.com> dateFri 27 Jul 2012, 14:35 (14 years ago) parent67a52fa
4 files changed+41−37
azure-service-api/src/Network/Azure/ServiceManagement.hs+20−22 distributed-process-azure/distributed-process-azure.cabal+2−1 distributed-process-azure/src/Control/Distributed/Process/Backend/Azure.hs+16−11 distributed-process-azure/src/Control/Distributed/Process/Backend/Azure/CommandLine.hs+3−3
azure-service-api/src/Network/Azure/ServiceManagement.hs+20−22
@@ -2,17 +2,17 @@
22module Network.Azure.ServiceManagement
33 ( -- * Data types
44 HostedService(..)
5− , Role(..)
6− , Endpoint(..)
5+ , CloudService(..)
76 , VirtualMachine(..)
7+ , Endpoint(..)
88 -- * Pure functions
9− , vmSshEndpoints
9+ , cloudServiceSshEndpoints
1010 -- * Setup
1111 , AzureSetup(..)
1212 , azureSetup
1313 -- * High-level API
1414 , hostedServices
15− , virtualMachines
15+ , cloudServices
1616 ) where
1717
1818import Prelude hiding (id, (.))
@@ -56,13 +56,17 @@ import Text.XML.HXT.XPath (getXPathTrees)
5656data HostedService = HostedService {
5757 hostedServiceName :: String
5858 }
59+ deriving Show
5960
60−instance Show HostedService where
61− show = hostedServiceName
61+data CloudService = CloudService {
62+ cloudServiceName :: String
63+ , cloudServiceVMs :: [VirtualMachine]
64+ }
65+ deriving Show
6266
63−data Role = Role {
64− roleName :: String
65− , roleInputEndpoints :: [Endpoint]
67+data VirtualMachine = VirtualMachine {
68+ vmName :: String
69+ , vmInputEndpoints :: [Endpoint]
6670 }
6771 deriving Show
6872
@@ -73,20 +77,14 @@ data Endpoint = Endpoint {
7377 }
7478 deriving Show
7579
76−data VirtualMachine = VirtualMachine {
77− vmService :: HostedService
78− , vmRoles :: [Role]
79− }
80− deriving Show
81−
8280--------------------------------------------------------------------------------
8381-- Pure operations --
8482--------------------------------------------------------------------------------
8583
86−vmSshEndpoints :: VirtualMachine -> [Endpoint]
87−vmSshEndpoints vm =
84+cloudServiceSshEndpoints :: CloudService -> [Endpoint]
85+cloudServiceSshEndpoints cs =
8886 [ ep
89− | ep <- concatMap roleInputEndpoints (vmRoles vm)
87+ | ep <- concatMap vmInputEndpoints (cloudServiceVMs cs)
9088 , endpointName ep == "SSH"
9189 ]
9290
@@ -122,8 +120,8 @@ azureSetup sid certPath pkeyPath = do
122120--------------------------------------------------------------------------------
123121
124122-- | Get a list of virtual machines
125−virtualMachines :: AzureSetup -> IO [VirtualMachine]
126−virtualMachines setup = azureExecute setup $ \exec -> do
123+cloudServices :: AzureSetup -> IO [CloudService]
124+cloudServices setup = azureExecute setup $ \exec -> do
127125 services <- exec hostedServicesRequest
128126 forM services $ \service -> do
129127 roles <- exec AzureRequest {
@@ -134,9 +132,9 @@ virtualMachines setup = azureExecute setup $ \exec -> do
134132 role <- getXPathTrees "//Role[@type='PersistentVMRole']" -< xml
135133 name <- getText . getXPathTrees "/Role/RoleName/text()" -< role
136134 endpoints <- listA (parseEndpoint . getXPathTrees "//InputEndpoint") -< role
137− id -< Role name endpoints
135+ id -< VirtualMachine name endpoints
138136 }
139− return $ VirtualMachine service roles
137+ return $ CloudService (hostedServiceName service) roles
140138
141139-- | Get list of available hosted services
142140hostedServices :: AzureSetup -> IO [HostedService]
distributed-process-azure/distributed-process-azure.cabal+2−1
@@ -21,7 +21,8 @@ Source-Repository head
2121Library
2222 Build-Depends: base >= 4.4 && < 5,
2323 azure-service-api >= 0.1 && < 0.2,
24− filepath >= 1.3 && < 1.4
24+ filepath >= 1.3 && < 1.4,
25+ executable-path >= 0.0.3 && < 0.1
2526 Exposed-modules: Control.Distributed.Process.Backend.Azure
2627 ghc-options: -Wall
2728 HS-Source-Dirs: src
distributed-process-azure/src/Control/Distributed/Process/Backend/Azure.hs+16−11
@@ -5,20 +5,24 @@ module Control.Distributed.Process.Backend.Azure
55 , defaultAzureParameters
66 , initializeBackend
77 -- * Re-exports from Azure Service Management
8− , VirtualMachine(..)
8+ , CloudService(..)
99 ) where
1010
1111import System.Environment (getEnv)
1212import System.FilePath ((</>))
13+import System.Environment.Executable (getExecutablePath)
1314import Network.Azure.ServiceManagement
14− ( VirtualMachine
15− , virtualMachines
15+ ( CloudService )
16+import qualified Network.Azure.ServiceManagement as Azure
17+ ( cloudServices
18+ , AzureSetup
1619 , azureSetup
17− )
20+ )
1821
1922-- | Azure backend
2023data Backend = Backend {
21− findVMs :: IO [VirtualMachine]
24+ -- | Find virtual machines
25+ cloudServices :: IO [CloudService]
2226 }
2327
2428data AzureParameters = AzureParameters {
@@ -31,7 +35,7 @@ data AzureParameters = AzureParameters {
3135 }
3236
3337-- | Create default azure parameters
34−defaultAzureParameters :: String -- ^ Azure subscription ID
38+defaultAzureParameters :: String -- ^ Azure subscription ID
3539 -> FilePath -- ^ Path to X509 certificate
3640 -> FilePath -- ^ Path to private key
3741 -> IO AzureParameters
@@ -49,10 +53,11 @@ defaultAzureParameters sid x509 pkey = do
4953-- | Initialize the backend
5054initializeBackend :: AzureParameters -> IO Backend
5155initializeBackend params = do
52− setup <- azureSetup (azureSubscriptionId params)
53− (azureAuthCertificate params)
54− (azureAuthPrivateKey params)
56+ setup <- Azure.azureSetup (azureSubscriptionId params)
57+ (azureAuthCertificate params)
58+ (azureAuthPrivateKey params)
59+ exe <- getExecutablePath
60+ print exe
5561 return Backend {
56− findVMs = virtualMachines setup
62+ cloudServices = Azure.cloudServices setup
5763 }
58−
distributed-process-azure/src/Control/Distributed/Process/Backend/Azure/CommandLine.hs+3−3
@@ -4,7 +4,7 @@ import System.Posix.Types (Fd)
44import Control.Distributed.Process.Backend.Azure
55 ( defaultAzureParameters
66 , initializeBackend
7− , findVMs
7+ , cloudServices
88 )
99
1010-- SSH
@@ -65,5 +65,5 @@ tryConnectToAzure :: String -> String -> String -> IO ()
6565tryConnectToAzure sid pathToCert pathToKey = do
6666 params <- defaultAzureParameters sid pathToCert pathToKey
6767 backend <- initializeBackend params
68− vms <- findVMs backend
69− mapM_ print vms
68+ css <- cloudServices backend
69+ mapM_ print css