@@ -4,6 +4,9 @@ module Network.Azure.ServiceManagement
44 HostedService(..)
55 , Role(..)
66 , Endpoint(..)
7+ , VirtualMachine(..)
8+ -- * Pure functions
9+ , vmSshEndpoints
710 -- * Setup
811 , AzureSetup(..)
912 , azureSetup
@@ -58,11 +61,10 @@ instance Show HostedService where
5861 show = hostedServiceName
5962
6063data Role = Role {
61− roleName :: String
64+ roleName :: String
65+ , roleInputEndpoints :: [Endpoint]
6266 }
63−
64−instance Show Role where
65− show = roleName
67+ deriving Show
6668
6769data Endpoint = Endpoint {
6870 endpointName :: String
@@ -71,6 +73,23 @@ data Endpoint = Endpoint {
7173 }
7274 deriving Show
7375
76+data VirtualMachine = VirtualMachine {
77+ vmService :: HostedService
78+ , vmRoles :: [Role]
79+ }
80+ deriving Show
81+
82+--------------------------------------------------------------------------------
83+-- Pure operations --
84+--------------------------------------------------------------------------------
85+
86+vmSshEndpoints :: VirtualMachine -> [Endpoint]
87+vmSshEndpoints vm =
88+ [ ep
89+ | ep <- concatMap roleInputEndpoints (vmRoles vm)
90+ , endpointName ep == "SSH"
91+ ]
92+
7493--------------------------------------------------------------------------------
7594-- Setup --
7695--------------------------------------------------------------------------------
@@ -103,7 +122,7 @@ azureSetup sid certPath pkeyPath = do
103122--------------------------------------------------------------------------------
104123
105124-- | Get a list of virtual machines
106−virtualMachines :: AzureSetup -> IO [(HostedService, [(Role, [Endpoint])])]
125+virtualMachines :: AzureSetup -> IO [VirtualMachine]
107126virtualMachines setup = azureExecute setup $ \exec -> do
108127 services <- exec hostedServicesRequest
109128 forM services $ \service -> do
@@ -115,9 +134,9 @@ virtualMachines setup = azureExecute setup $ \exec -> do
115134 role <- getXPathTrees "//Role[@type='PersistentVMRole']" -< xml
116135 name <- getText . getXPathTrees "/Role/RoleName/text()" -< role
117136 endpoints <- listA (parseEndpoint . getXPathTrees "//InputEndpoint") -< role
118− id -< (Role name, endpoints)
137+ id -< Role name endpoints
119138 }
120− return (service, roles)
139+ return $ VirtualMachine service roles
121140
122141-- | Get list of available hosted services
123142hostedServices :: AzureSetup -> IO [HostedService]