Commit 1df0266e authored by Hrvoje Ribicic's avatar Hrvoje Ribicic

Initial changes for adding instance queries

Add basic instance querying capabilities to the Haskell codebase.
Several fields are present, more to come.
Signed-off-by: default avatarHrvoje Ribicic <riba@google.com>
Reviewed-by: default avatarJose A. Lopes <jabolopes@google.com>
parent 5771c501
......@@ -704,6 +704,7 @@ HS_LIB_SRCS = \
src/Ganeti/Query/Export.hs \
src/Ganeti/Query/Filter.hs \
src/Ganeti/Query/Group.hs \
src/Ganeti/Query/Instance.hs \
src/Ganeti/Query/Job.hs \
src/Ganeti/Query/Language.hs \
src/Ganeti/Query/Network.hs \
......
{-# LANGUAGE TupleSections #-}
{-| Implementation of the Ganeti Query2 instance queries.
-}
{-
Copyright (C) 2013 Google Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
-}
module Ganeti.Query.Instance
( Runtime
, fieldsMap
, collectLiveData
) where
import qualified Data.Map as Map
import Ganeti.Objects
import Ganeti.Query.Common
import Ganeti.Query.Language
import Ganeti.Query.Types
-- | Dummy type for runtime to be implemented later, see the 'genericQuery'
-- function in 'Ganeti.Query.Query' for an explanation
data Runtime = Runtime
instanceFields :: FieldList Instance Runtime
instanceFields =
[ (FieldDefinition "disk_template" "Disk_template" QFTText
"Disk template",
FieldSimple (rsNormal . instDiskTemplate), QffNormal)
, (FieldDefinition "name" "Instance" QFTText
"Instance name",
FieldSimple (rsNormal . instName), QffHostname)
, (FieldDefinition "hypervisor" "Hypervisor" QFTText
"Hypervisor name",
FieldSimple (rsNormal . instHypervisor), QffNormal)
, (FieldDefinition "network_port" "Network_port" QFTOther
"Instance network port if available (e.g. for VNC console)",
FieldSimple (rsMaybeNoData . instNetworkPort), QffNormal)
, (FieldDefinition "os" "OS" QFTText
"Operating system",
FieldSimple (rsNormal . instOs), QffNormal)
] ++
serialFields "Instance" ++
uuidFields "Instance"
fieldsMap :: FieldMap Instance Runtime
fieldsMap =
Map.fromList [(fdefName f, v) | v@(f, _, _) <- instanceFields]
-- | Dummy function for collecting live data - just for interface testing
collectLiveData :: Bool -> ConfigData -> [Instance] -> IO [(Instance, Runtime)]
collectLiveData _ _ = return . map (, Runtime)
......@@ -69,6 +69,7 @@ import Ganeti.Objects
import Ganeti.Query.Common
import qualified Ganeti.Query.Export as Export
import Ganeti.Query.Filter
import qualified Ganeti.Query.Instance as Instance
import qualified Ganeti.Query.Job as Query.Job
import qualified Ganeti.Query.Group as Group
import Ganeti.Query.Language
......@@ -219,6 +220,10 @@ queryInner cfg live (Query (ItemTypeOpCode QRNode) fields qfilter) wanted =
genericQuery Node.fieldsMap Node.collectLiveData nodeName configNodes getNode
cfg live fields qfilter wanted
queryInner cfg live (Query (ItemTypeOpCode QRInstance) fields qfilter) wanted =
genericQuery Instance.fieldsMap Instance.collectLiveData instName
configInstances getInstance cfg live fields qfilter wanted
queryInner cfg live (Query (ItemTypeOpCode QRGroup) fields qfilter) wanted =
genericQuery Group.fieldsMap Group.collectLiveData groupName configNodegroups
getGroup cfg live fields qfilter wanted
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment