On Fri, Oct 05, 2012 at 08:29:41PM +0200, Iustin Pop wrote:
> On Fri, Oct 05, 2012 at 09:46:48AM +0200, Agata Murawska wrote:
> > 2012/10/5 Iustin Pop <[email protected]>:
> > > The disk free/total values are optional ones, wrapped in a Maybe, so
> > > we shouldn't directly serialise them. In order to simplify the
> > > embedded extraction, we add a small helper function.
> > >
> > > Signed-off-by: Iustin Pop <[email protected]>
> > > ---
> > > htools/Ganeti/Query/Node.hs | 9 +++++++--
> > > 1 file changed, 7 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/htools/Ganeti/Query/Node.hs b/htools/Ganeti/Query/Node.hs
> > > index 0630754..01d0a89 100644
> > > --- a/htools/Ganeti/Query/Node.hs
> > > +++ b/htools/Ganeti/Query/Node.hs
> > > @@ -68,6 +68,11 @@ nodeLiveFieldsDefs =
> > > "Total amount of memory of physical machine")
> > > ]
> > >
> > > +-- | Helper for extracting Maybe values from a possibly empty list.
> > > +getMaybeJsonHead :: (J.JSON b) => [a] -> (a -> Maybe b) -> J.JSValue
> > > +getMaybeJsonHead [] _ = J.JSNull
> > > +getMaybeJsonHead (x:_) f = maybe J.JSNull J.showJSON (f x)
> > I think this should be in JSON.hs, just in case we'd ever need that again
>
> Thanks, make sense. Will send interdiff.
And here it is:
diff --git a/htools/Ganeti/JSON.hs b/htools/Ganeti/JSON.hs
index 7c7dd34..178915a 100644
--- a/htools/Ganeti/JSON.hs
+++ b/htools/Ganeti/JSON.hs
@@ -32,6 +32,7 @@ module Ganeti.JSON
, fromKeyValue
, fromJVal
, jsonHead
+ , getMaybeJsonHead
, asJSObject
, asObjectList
, tryFromObj
@@ -131,6 +132,11 @@ jsonHead :: (J.JSON b) => [a] -> (a -> b) -> J.JSValue
jsonHead [] _ = J.JSNull
jsonHead (x:_) f = J.showJSON $ f x
+-- | Helper for extracting Maybe values from a possibly empty list.
+getMaybeJsonHead :: (J.JSON b) => [a] -> (a -> Maybe b) -> J.JSValue
+getMaybeJsonHead [] _ = J.JSNull
+getMaybeJsonHead (x:_) f = maybe J.JSNull J.showJSON (f x)
+
-- | Converts a JSON value into a JSON object.
asJSObject :: (Monad m) => J.JSValue -> m (J.JSObject J.JSValue)
asJSObject (J.JSObject a) = return a
diff --git a/htools/Ganeti/Query/Node.hs b/htools/Ganeti/Query/Node.hs
index 01d0a89..06ec199 100644
--- a/htools/Ganeti/Query/Node.hs
+++ b/htools/Ganeti/Query/Node.hs
@@ -68,11 +68,6 @@ nodeLiveFieldsDefs =
"Total amount of memory of physical machine")
]
--- | Helper for extracting Maybe values from a possibly empty list.
-getMaybeJsonHead :: (J.JSON b) => [a] -> (a -> Maybe b) -> J.JSValue
-getMaybeJsonHead [] _ = J.JSNull
-getMaybeJsonHead (x:_) f = maybe J.JSNull J.showJSON (f x)
-
-- | Map each name to a function that extracts that value from
-- the RPC result.
nodeLiveFieldExtract :: String -> RpcResultNodeInfo -> J.JSValue
--
thanks,
iustin