ganeti
Safe HaskellNone

Ganeti.Query.Instance

Description

Implementation of the Ganeti Query2 instance queries.

Synopsis

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.

fieldsMap :: FieldMap Instance Runtime Source #

The instance fields map.

instanceAliases :: [(FieldName, FieldName)] Source #

The instance aliases.

aliasedFields :: FieldList Instance Runtime Source #

The aliased instance fields.

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 #

Arguments

:: 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.

getIndexedConfField Source #

Arguments

:: 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 #

Arguments

:: 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 #

Arguments

:: 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.

getIndexedField Source #

Arguments

:: 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 #

Arguments

:: (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

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

getSecondaryNodeGroupAttribute :: JSON a => (NodeGroup -> a) -> ConfigData -> Instance -> ResultEntry Source #

Get attributes of secondary node groups

beParamGetter Source #

Arguments

:: 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.

hvParamGetter Source #

Arguments

:: 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.

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 #

Arguments

:: 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.

collectLiveData Source #

Arguments

:: 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.