Safe Haskell | None |
---|
Implementation of the Ganeti Query2 instance queries.
Synopsis
- type LiveInfo = (Maybe (InstanceInfo, Bool), Maybe InstanceConsoleInfo)
- type Runtime = Either RpcError LiveInfo
- fieldsMap :: FieldMap Instance Runtime
- instanceAliases :: [(FieldName, FieldName)]
- aliasedFields :: FieldList Instance Runtime
- instanceFields :: FieldList Instance Runtime
- nicDescSuffix :: String
- nicAggDescPrefix :: String
- getNetworkName :: ConfigData -> String -> NonEmptyString
- getNicBridge :: FilledNicParams -> Maybe String
- getNicVlan :: FilledNicParams -> Maybe String
- fillNicParamsFromConfig :: ConfigData -> PartialNicParams -> FilledNicParams
- getDefaultNicParams :: ConfigData -> FilledNicParams
- getDiskSizeRequirements :: ConfigData -> Instance -> ResultEntry
- getDiskSizes :: ConfigData -> Instance -> ResultEntry
- getDiskSpindles :: ConfigData -> Instance -> ResultEntry
- getDiskNames :: ConfigData -> Instance -> ResultEntry
- getDiskUuids :: ConfigData -> Instance -> ResultEntry
- getIndexedOptionalConfField :: JSON b => (ConfigData -> Instance -> ErrorResult [a]) -> (a -> Maybe b) -> Int -> FieldGetter Instance Runtime
- getIndexedConfField :: JSON b => (ConfigData -> Instance -> ErrorResult [a]) -> (a -> b) -> Int -> FieldGetter Instance Runtime
- getIndexedNicNetworkNameField :: Int -> FieldGetter Instance Runtime
- getIndexedNicField :: JSON a => (FilledNicParams -> a) -> Int -> FieldGetter Instance Runtime
- getOptionalIndexedNicField :: JSON a => (FilledNicParams -> Maybe a) -> Int -> FieldGetter Instance Runtime
- getIndexedFieldWithDefault :: JSON c => (Instance -> [a]) -> (ConfigData -> Instance -> b) -> (b -> a -> b) -> (b -> Maybe c) -> Int -> FieldGetter Instance Runtime
- getIndexedOptionalField :: JSON b => (Instance -> [a]) -> (a -> Maybe b) -> Int -> FieldGetter Instance Runtime
- getIndexedField :: JSON b => (Instance -> [a]) -> (a -> b) -> Int -> FieldGetter Instance Runtime
- maybeAt :: Int -> [a] -> Maybe a
- fieldDefinitionCompleter :: PrintfArg t1 => PrintfArg t2 => FieldName -> FieldTitle -> FieldType -> FieldDoc -> t1 -> t2 -> FieldDefinition
- fillIncompleteFields :: (t1 -> t2 -> FieldDefinition, t1 -> FieldGetter a b, QffMode) -> t1 -> t2 -> FieldData a b
- instantiateIndexedFields :: (Show t1, Integral t1) => Int -> [(t1 -> String -> FieldDefinition, t1 -> FieldGetter a b, QffMode)] -> FieldList a b
- getPrimaryNode :: ConfigData -> Instance -> ErrorResult Node
- getPrimaryNodeName :: ConfigData -> Instance -> ResultEntry
- getPrimaryNodeGroup :: ConfigData -> Instance -> ErrorResult NodeGroup
- getPrimaryNodeGroupName :: ConfigData -> Instance -> ResultEntry
- getPrimaryNodeGroupUuid :: ConfigData -> Instance -> ResultEntry
- getSecondaryNodes :: ConfigData -> Instance -> ErrorResult [Node]
- getSecondaryNodeAttribute :: JSON a => (Node -> a) -> ConfigData -> Instance -> ResultEntry
- getSecondaryNodeGroups :: ConfigData -> Instance -> ErrorResult [NodeGroup]
- getSecondaryNodeGroupAttribute :: JSON a => (NodeGroup -> a) -> ConfigData -> Instance -> ResultEntry
- beParamGetter :: String -> ConfigData -> Instance -> ResultEntry
- hvParamGetter :: String -> ConfigData -> Instance -> ResultEntry
- instanceLiveFieldsDefs :: [(FieldName, FieldTitle, FieldType, String, FieldDoc)]
- instanceLiveFieldExtract :: FieldName -> InstanceInfo -> Instance -> JSValue
- instanceLiveRpcCall :: FieldName -> Runtime -> Instance -> ResultEntry
- instanceLiveFieldBuilder :: (FieldName, FieldTitle, FieldType, String, FieldDoc) -> FieldData Instance Runtime
- statusDocText :: String
- isPrimaryOffline :: ConfigData -> Instance -> Bool
- userShutdownEnabled :: ConfigData -> Bool
- liveInstanceStatus :: ConfigData -> (InstanceInfo, Bool) -> Instance -> InstanceStatus
- deadInstanceStatus :: ConfigData -> Instance -> InstanceStatus
- determineInstanceStatus :: ConfigData -> Runtime -> Instance -> InstanceStatus
- statusExtract :: ConfigData -> Runtime -> Instance -> ResultEntry
- operStatusExtract :: Runtime -> Instance -> ResultEntry
- consoleExtract :: Runtime -> Instance -> ResultEntry
- checkForNodeError :: [(String, ERpcError a)] -> String -> Maybe RpcError
- findInfoInNodeResult :: Instance -> ERpcError RpcResultAllInstancesInfo -> Maybe InstanceInfo
- getInstanceInfo :: [(String, ERpcError RpcResultAllInstancesInfo)] -> Instance -> ERpcError (Maybe (InstanceInfo, Bool))
- getConsoleInfo :: [(String, ERpcError RpcResultInstanceConsoleInfo)] -> Instance -> Maybe InstanceConsoleInfo
- extractLiveInfo :: [(Node, ERpcError RpcResultAllInstancesInfo)] -> [(Node, ERpcError RpcResultInstanceConsoleInfo)] -> Instance -> Runtime
- getAllConsoleParams :: ConfigData -> [Instance] -> ErrorResult [InstanceConsoleInfoParams]
- compareParamsByNode :: InstanceConsoleInfoParams -> InstanceConsoleInfoParams -> Bool
- consoleParamsToCalls :: [InstanceConsoleInfoParams] -> [(Node, RpcCallInstanceConsoleInfo)]
- getHypervisorSpecs :: ConfigData -> [Instance] -> [(Hypervisor, HvParams)]
- collectLiveData :: Bool -> ConfigData -> [String] -> [Instance] -> IO [(Instance, Runtime)]
- getDiskTemplate :: ConfigData -> Instance -> ResultEntry
Documentation
type LiveInfo = (Maybe (InstanceInfo, Bool), Maybe InstanceConsoleInfo) Source #
The LiveInfo consists of two entries whose presence is independent.
The InstanceInfo
is the live instance information, accompanied by a bool
signifying if it was found on its designated primary node or not.
The InstanceConsoleInfo
describes how to connect to an instance.
Any combination of these may or may not be present, depending on node and
instance availability.
type Runtime = Either RpcError LiveInfo Source #
Runtime containing the LiveInfo
. See the genericQuery function in
the Query.hs file for an explanation of the terms used.
instanceAliases :: [(FieldName, FieldName)] Source #
The instance aliases.
Helper functions for node property retrieval
nicDescSuffix :: String Source #
Constant suffix of network interface field descriptions.
nicAggDescPrefix :: String Source #
Almost-constant suffix of aggregate network interface field descriptions.
getNetworkName :: ConfigData -> String -> NonEmptyString Source #
Given a network name id, returns the network's name.
getNicBridge :: FilledNicParams -> Maybe String Source #
Gets the bridge of a NIC.
getNicVlan :: FilledNicParams -> Maybe String Source #
Gets the VLAN of a NIC.
fillNicParamsFromConfig :: ConfigData -> PartialNicParams -> FilledNicParams Source #
Fill partial NIC params by using the defaults from the configuration.
getDefaultNicParams :: ConfigData -> FilledNicParams Source #
Retrieves the default network interface parameters.
getDiskSizeRequirements :: ConfigData -> Instance -> ResultEntry Source #
Retrieves the real disk size requirements for all the disks of the instance. This includes the metadata etc. and is different from the values visible to the instance.
getDiskSizes :: ConfigData -> Instance -> ResultEntry Source #
Get a list of disk sizes for an instance
getDiskSpindles :: ConfigData -> Instance -> ResultEntry Source #
Get a list of disk spindles
getDiskNames :: ConfigData -> Instance -> ResultEntry Source #
Get a list of disk names for an instance
getDiskUuids :: ConfigData -> Instance -> ResultEntry Source #
Get a list of disk UUIDs for an instance
getIndexedOptionalConfField Source #
:: JSON b | |
=> (ConfigData -> Instance -> ErrorResult [a]) | Extracts a list of objects |
-> (a -> Maybe b) | Possibly gets a property from an object |
-> Int | Index in list to use |
-> FieldGetter Instance Runtime | Result |
Creates a functions which produces a FieldConfig FieldGetter
when fed
an index. Works for fields that may not return a value, expressed through
the Maybe monad.
:: JSON b | |
=> (ConfigData -> Instance -> ErrorResult [a]) | Extracts a list of objects |
-> (a -> b) | Gets a property from an object |
-> Int | Index in list to use |
-> FieldGetter Instance Runtime | Result |
Creates a function which produces a FieldConfig FieldGetter
when fed
an index. Works only for fields that surely return a value.
getIndexedNicNetworkNameField :: Int -> FieldGetter Instance Runtime Source #
Returns a field that retrieves a given NIC's network name.
getIndexedNicField :: JSON a => (FilledNicParams -> a) -> Int -> FieldGetter Instance Runtime Source #
Gets a fillable NIC field.
getOptionalIndexedNicField :: JSON a => (FilledNicParams -> Maybe a) -> Int -> FieldGetter Instance Runtime Source #
Gets an optional fillable NIC field.
getIndexedFieldWithDefault Source #
:: JSON c | |
=> (Instance -> [a]) | Extracts a list of incomplete objects |
-> (ConfigData -> Instance -> b) | Extracts the default object |
-> (b -> a -> b) | Fills the default object |
-> (b -> Maybe c) | Extracts an obj property |
-> Int | Index in list to use |
-> FieldGetter Instance Runtime | Result |
Creates a function which produces a FieldGetter
when fed an index. Works
for fields that should be filled out through the use of a default.
getIndexedOptionalField Source #
:: JSON b | |
=> (Instance -> [a]) | Extracts a list of objects |
-> (a -> Maybe b) | Possibly gets a property from an object |
-> Int | Index in list to use |
-> FieldGetter Instance Runtime | Result |
Creates a function which produces a FieldGetter
when fed an index. Works
for fields that may not return a value, expressed through the Maybe monad.
:: JSON b | |
=> (Instance -> [a]) | Extracts a list of objects |
-> (a -> b) | Gets a property from an object |
-> Int | Index in list to use |
-> FieldGetter Instance Runtime | Result |
Creates a function which produces a FieldGetter
when fed an index.
Works only for fields that surely return a value.
maybeAt :: Int -> [a] -> Maybe a Source #
Retrieves a value from an array at an index, using the Maybe monad to indicate failure.
fieldDefinitionCompleter :: PrintfArg t1 => PrintfArg t2 => FieldName -> FieldTitle -> FieldType -> FieldDoc -> t1 -> t2 -> FieldDefinition Source #
Primed with format strings for everything but the type, it consumes two values and uses them to complete the FieldDefinition. Warning: a bit unsafe as it uses printf. Handle with care.
fillIncompleteFields :: (t1 -> t2 -> FieldDefinition, t1 -> FieldGetter a b, QffMode) -> t1 -> t2 -> FieldData a b Source #
Given an incomplete field definition and values that can complete it, return a fully functional FieldData. Cannot work for all cases, should be extended as necessary.
instantiateIndexedFields Source #
:: (Show t1, Integral t1) | |
=> Int | The size of the list |
-> [(t1 -> String -> FieldDefinition, t1 -> FieldGetter a b, QffMode)] | The indexed fields |
-> FieldList a b | A list of complete fields |
Given indexed fields that describe lists, complete / instantiate them for a given list size.
Various helper functions for property retrieval
getPrimaryNode :: ConfigData -> Instance -> ErrorResult Node Source #
Helper function for primary node retrieval
getPrimaryNodeName :: ConfigData -> Instance -> ResultEntry Source #
Get primary node hostname
getPrimaryNodeGroup :: ConfigData -> Instance -> ErrorResult NodeGroup Source #
Get primary node group
getPrimaryNodeGroupName :: ConfigData -> Instance -> ResultEntry Source #
Get primary node group name
getPrimaryNodeGroupUuid :: ConfigData -> Instance -> ResultEntry Source #
Get primary node group uuid
getSecondaryNodes :: ConfigData -> Instance -> ErrorResult [Node] Source #
Get secondary nodes - the configuration objects themselves
getSecondaryNodeAttribute :: JSON a => (Node -> a) -> ConfigData -> Instance -> ResultEntry Source #
Get attributes of the secondary nodes
getSecondaryNodeGroups :: ConfigData -> Instance -> ErrorResult [NodeGroup] Source #
Get secondary node groups
getSecondaryNodeGroupAttribute :: JSON a => (NodeGroup -> a) -> ConfigData -> Instance -> ResultEntry Source #
Get attributes of secondary node groups
:: String | The field we are building the getter for |
-> ConfigData | The configuration object |
-> Instance | The instance configuration object |
-> ResultEntry | The result |
Beparam getter builder: given a field, it returns a FieldConfig getter, that is a function that takes the config and the object and returns the Beparam field specified when the getter was built.
:: String | The field we're building the getter for |
-> ConfigData | |
-> Instance | |
-> ResultEntry |
Hvparam getter builder: given a field, it returns a FieldConfig getter, that is a function that takes the config and the object and returns the Hvparam field specified when the getter was built.
Live fields functionality
instanceLiveFieldsDefs :: [(FieldName, FieldTitle, FieldType, String, FieldDoc)] Source #
List of node live fields.
instanceLiveFieldExtract :: FieldName -> InstanceInfo -> Instance -> JSValue Source #
Map each name to a function that extracts that value from the RPC result.
instanceLiveRpcCall :: FieldName -> Runtime -> Instance -> ResultEntry Source #
Helper for extracting an instance live field from the RPC results.
instanceLiveFieldBuilder :: (FieldName, FieldTitle, FieldType, String, FieldDoc) -> FieldData Instance Runtime Source #
Builder for node live fields.
Functionality related to status and operational status extraction
statusDocText :: String Source #
The documentation text for the instance status field
isPrimaryOffline :: ConfigData -> Instance -> Bool Source #
Checks if the primary node of an instance is offline
userShutdownEnabled :: ConfigData -> Bool Source #
Determines if user shutdown reporting is enabled
liveInstanceStatus :: ConfigData -> (InstanceInfo, Bool) -> Instance -> InstanceStatus Source #
Determines the status of a live instance
deadInstanceStatus :: ConfigData -> Instance -> InstanceStatus Source #
Determines the status of a dead instance.
determineInstanceStatus Source #
:: ConfigData | The configuration data |
-> Runtime | All the data from the live call |
-> Instance | Static instance configuration |
-> InstanceStatus | Result |
Determines the status of the instance, depending on whether it is possible to communicate with its primary node, on which node it is, and its configuration.
statusExtract :: ConfigData -> Runtime -> Instance -> ResultEntry Source #
Extracts the instance status, retrieving it using the functions above and
transforming it into a ResultEntry
.
operStatusExtract :: Runtime -> Instance -> ResultEntry Source #
Extracts the operational status of the instance.
consoleExtract :: Runtime -> Instance -> ResultEntry Source #
Extracts the console connection information
Helper functions extracting information as necessary for the generic query
checkForNodeError :: [(String, ERpcError a)] -> String -> Maybe RpcError Source #
This function checks if a node with a given uuid has experienced an error or not.
findInfoInNodeResult :: Instance -> ERpcError RpcResultAllInstancesInfo -> Maybe InstanceInfo Source #
Finds information about the instance in the info delivered by a node
getInstanceInfo :: [(String, ERpcError RpcResultAllInstancesInfo)] -> Instance -> ERpcError (Maybe (InstanceInfo, Bool)) Source #
Retrieves the instance information if it is present anywhere in the all instances RPC result. Notes if it originates from the primary node. An error is delivered if there is no result, and the primary node is down.
getConsoleInfo :: [(String, ERpcError RpcResultInstanceConsoleInfo)] -> Instance -> Maybe InstanceConsoleInfo Source #
Retrieves the console information if present anywhere in the given results
extractLiveInfo :: [(Node, ERpcError RpcResultAllInstancesInfo)] -> [(Node, ERpcError RpcResultInstanceConsoleInfo)] -> Instance -> Runtime Source #
Extracts all the live information that can be extracted.
getAllConsoleParams :: ConfigData -> [Instance] -> ErrorResult [InstanceConsoleInfoParams] Source #
Retrieves all the parameters for the console calls.
compareParamsByNode :: InstanceConsoleInfoParams -> InstanceConsoleInfoParams -> Bool Source #
Compares two params according to their node, needed for grouping.
consoleParamsToCalls :: [InstanceConsoleInfoParams] -> [(Node, RpcCallInstanceConsoleInfo)] Source #
Groups instance information calls heading out to the same nodes.
getHypervisorSpecs :: ConfigData -> [Instance] -> [(Hypervisor, HvParams)] Source #
Retrieves a list of all the hypervisors and params used by the given instances.
:: Bool | Live queries allowed |
-> ConfigData | The cluster config |
-> [String] | The requested fields |
-> [Instance] | The instance objects |
-> IO [(Instance, Runtime)] |
Collect live data from RPC query if enabled.
getDiskTemplate :: ConfigData -> Instance -> ResultEntry Source #
An aggregate disk attribute for backward compatibility.