git.iko.soy/distributed-process
on master help sign in
Get properties of a hosted service
b8b899cEdsko de Vries
azure-service-api/src/Network/Azure/ServiceManagement.hs+37−9
@@ -1,10 +1,13 @@
1{-# LANGUAGE Arrows #-}
1{-# LANGUAGE Arrows #-}
2module Network.Azure.ServiceManagement
2module Network.Azure.ServiceManagement
3+ ( -- * Data types
4+ HostedService
3− ( -- * Setup
5+ -- * Setup
4− AzureSetup(..)
6+ , AzureSetup(..)
5 , azureSetup
7 , azureSetup
6 -- * High-level API
8 -- * High-level API
7 , hostedServices
9 , hostedServices
10+ , hostedServiceProperties
8 -- * Low-level API
11 -- * Low-level API
9 , azureRequest
12 , azureRequest
10 , azureRawRequest
13 , azureRawRequest
@@ -12,6 +15,7 @@ module Network.Azure.ServiceManagement
12
15
13import Prelude hiding (id)
16import Prelude hiding (id)
14import Control.Category (id, (>>>))
17import Control.Category (id, (>>>))
18+import Control.Arrow (arr)
15import Data.ByteString.Lazy (ByteString)
19import Data.ByteString.Lazy (ByteString)
16import Data.ByteString.Char8 as BSC (pack)
20import Data.ByteString.Char8 as BSC (pack)
17import Data.ByteString.Lazy.Char8 as BSLC (unpack)
21import Data.ByteString.Lazy.Char8 as BSLC (unpack)
@@ -34,13 +38,25 @@ import Text.XML.HXT.Core
34 , no
38 , no
35 , XmlTree
39 , XmlTree
36 , IOSArrow
40 , IOSArrow
37− , XNode
38 , ArrowXml
41 , ArrowXml
39 , deep
42 , deep
40 , hasName
43 , hasName
41 , getText
44 , getText
45+ -- FOR DEBUGGING ONLY
46+ , writeDocument
47+ , withIndent
48+ , yes
42 )
49 )
43
50
51+--------------------------------------------------------------------------------
52+-- Data types --
53+--------------------------------------------------------------------------------
54+
55+newtype HostedService = HostedService { unHostedService :: String }
56+
57+instance Show HostedService where
58+ show = unHostedService
59+
44--------------------------------------------------------------------------------
60--------------------------------------------------------------------------------
45-- Setup --
61-- Setup --
46--------------------------------------------------------------------------------
62--------------------------------------------------------------------------------
@@ -72,13 +88,25 @@ azureSetup sid certPath pkeyPath = do
72-- High-level API --
88-- High-level API --
73--------------------------------------------------------------------------------
89--------------------------------------------------------------------------------
74
90
91+-- | Get list of available hosted services
75−hostedServices :: AzureSetup -> IO [(String, String)]
92+hostedServices :: AzureSetup -> IO [HostedService]
76hostedServices setup =
93hostedServices setup =
77− azureRequest setup "/services/hostedservices" "2012-03-01" $ proc xml -> do
94+ azureRequest setup subURL "2012-03-01" $ proc xml -> do
95+ writeDocument [withIndent yes] "hostedservices.xml" -< xml
78− hostedService <- deep (hasName "HostedService") -< xml
96+ hostedService <- deep (hasName "HostedService") -< xml
79− url <- getTextNode "Url" -< hostedService
80− serviceName <- getTextNode "ServiceName" -< hostedService
97+ name <- getTextNode "ServiceName" -< hostedService
81− id -< (url, serviceName)
98+ arr HostedService -< name
99+ where
100+ subURL = "/services/hostedservices"
101+
102+-- | Get properties of the given hosted service
103+hostedServiceProperties :: AzureSetup -> HostedService -> IO [()]
104+hostedServiceProperties setup (HostedService service) = do
105+ azureRequest setup subURL "2012-03-01" $ proc xml -> do
106+ writeDocument [withIndent yes] "properties.xml" -< xml
107+ id -< ()
108+ where
109+ subURL = "/services/hostedservices/" ++ service ++ "?embed-detail=true"
82
110
83--------------------------------------------------------------------------------
111--------------------------------------------------------------------------------
84-- Low-level API --
112-- Low-level API --
azure-service-api/src/Network/Azure/ServiceManagement/CommandLine.hs+5
@@ -1,4 +1,5 @@
1-- Base
1-- Base
2+import Control.Monad (forM_)
2import System.Environment (getArgs, getEnv)
3import System.Environment (getArgs, getEnv)
3import System.FilePath ((</>))
4import System.FilePath ((</>))
4import System.Posix.Types (Fd)
5import System.Posix.Types (Fd)
@@ -7,6 +8,7 @@ import System.Posix.Types (Fd)
7import Network.Azure.ServiceManagement
8import Network.Azure.ServiceManagement
8 ( azureSetup
9 ( azureSetup
9 , hostedServices
10 , hostedServices
11+ , hostedServiceProperties
10 )
12 )
11
13
12-- SSH
14-- SSH
@@ -68,4 +70,7 @@ tryConnectToAzure sid pathToCert pathToKey = do
68 setup <- azureSetup sid pathToCert pathToKey
70 setup <- azureSetup sid pathToCert pathToKey
69 services <- hostedServices setup
71 services <- hostedServices setup
70 mapM_ print services
72 mapM_ print services
73+ forM_ services $ \service -> do
74+ props <- hostedServiceProperties setup service
75+ print props
71
76