ganeti-3.1: Cluster-based virtualization management software
Safe HaskellSafe-Inferred
LanguageHaskell2010

Ganeti.THH

Description

TemplateHaskell helper for Ganeti Haskell code.

As TemplateHaskell require that splices be defined in a separate module, we combine all the TemplateHaskell functionality that HTools needs in this module (except the one for unittests).

Synopsis

Documentation

declareSADT :: String -> [(String, Name)] -> Q [Dec] #

declareLADT :: Name -> String -> [(String, String)] -> Q [Dec] #

declareILADT :: String -> [(String, Int)] -> Q [Dec] #

declareIADT :: String -> [(String, Name)] -> Q [Dec] #

makeJSONInstance :: Name -> Q [Dec] #

Generates a JSON instance for a given type.

This assumes that the nameToRaw and nameFromRaw functions have been defined as by the declareSADT function.

deCamelCase :: String -> String #

Transforms a CamelCase string into an_underscore_based_one.

genOpID :: Name -> String -> Q [Dec] #

Constructor-to-string for OpCode.

genOpLowerStrip :: String -> Name -> String -> Q [Dec] #

Strips Op from the constructor name, converts to lower-case and adds a given prefix.

genAllConstr :: (String -> String) -> Name -> String -> Q [Dec] #

Builds a list with all defined constructor names for a type.

vstr :: String
vstr = [...]

Where the actual values of the string are the constructor names mapped via trans_fun.

genAllOpIDs :: Name -> String -> Q [Dec] #

Generates a list of all defined opcode IDs.

class PyValue a where #

Converts Haskell values into Python values

This is necessary for the default values of opcode parameters and return values. For example, if a default value or return type is a Data.Map, then it must be shown as a Python dictioanry.

Minimal complete definition

showValue

Methods

showValue :: a -> String #

showValueList :: [a] -> String #

Instances

Instances details
PyValue ByteString # 
Instance details

Defined in Ganeti.PyValue

Methods

showValue :: ByteString -> String #

showValueList :: [ByteString] -> String #

PyValue Protocol #

PyValue instance of Protocol

This instance is used by the Haskell to Python constants

Instance details

Defined in Ganeti.ConstantUtils

Methods

showValue :: Protocol -> String #

showValueList :: [Protocol] -> String #

PyValue PythonChar # 
Instance details

Defined in Ganeti.ConstantUtils

Methods

showValue :: PythonChar -> String #

showValueList :: [PythonChar] -> String #

PyValue PythonNone # 
Instance details

Defined in Ganeti.ConstantUtils

Methods

showValue :: PythonNone -> String #

showValueList :: [PythonNone] -> String #

PyValue DiskIndex # 
Instance details

Defined in Ganeti.OpCodes

Methods

showValue :: DiskIndex -> String #

showValueList :: [DiskIndex] -> String #

PyValue IDiskParams # 
Instance details

Defined in Ganeti.OpCodes

Methods

showValue :: IDiskParams -> String #

showValueList :: [IDiskParams] -> String #

PyValue INicParams # 
Instance details

Defined in Ganeti.OpCodes

Methods

showValue :: INicParams -> String #

showValueList :: [INicParams] -> String #

PyValue RecreateDisksInfo # 
Instance details

Defined in Ganeti.OpCodes

Methods

showValue :: RecreateDisksInfo -> String #

showValueList :: [RecreateDisksInfo] -> String #

PyValue PyValueEx # 
Instance details

Defined in Ganeti.PyValue

Methods

showValue :: PyValueEx -> String #

showValueList :: [PyValueEx] -> String #

PyValue InstanceState # 
Instance details

Defined in Ganeti.Rpc

Methods

showValue :: InstanceState -> String #

showValueList :: [InstanceState] -> String #

PyValue PyType # 
Instance details

Defined in Ganeti.THH.PyType

Methods

showValue :: PyType -> String #

showValueList :: [PyType] -> String #

PyValue AdminStateSource # 
Instance details

Defined in Ganeti.Types

Methods

showValue :: AdminStateSource -> String #

showValueList :: [AdminStateSource] -> String #

PyValue CVErrorCode # 
Instance details

Defined in Ganeti.OpCodes

Methods

showValue :: CVErrorCode -> String #

showValueList :: [CVErrorCode] -> String #

PyValue DiskTemplate # 
Instance details

Defined in Ganeti.Types

Methods

showValue :: DiskTemplate -> String #

showValueList :: [DiskTemplate] -> String #

PyValue ExportMode # 
Instance details

Defined in Ganeti.OpCodes

Methods

showValue :: ExportMode -> String #

showValueList :: [ExportMode] -> String #

PyValue Hypervisor # 
Instance details

Defined in Ganeti.Types

Methods

showValue :: Hypervisor -> String #

showValueList :: [Hypervisor] -> String #

PyValue VType # 
Instance details

Defined in Ganeti.Types

Methods

showValue :: VType -> String #

showValueList :: [VType] -> String #

PyValue VerifyOptionalChecks # 
Instance details

Defined in Ganeti.OpCodes

PyValue JSValue # 
Instance details

Defined in Ganeti.OpCodes

Methods

showValue :: JSValue -> String #

showValueList :: [JSValue] -> String #

PyValue Integer # 
Instance details

Defined in Ganeti.PyValue

Methods

showValue :: Integer -> String #

showValueList :: [Integer] -> String #

PyValue Bool # 
Instance details

Defined in Ganeti.PyValue

Methods

showValue :: Bool -> String #

showValueList :: [Bool] -> String #

PyValue Char # 
Instance details

Defined in Ganeti.PyValue

Methods

showValue :: Char -> String #

showValueList :: [Char] -> String #

PyValue Double # 
Instance details

Defined in Ganeti.PyValue

Methods

showValue :: Double -> String #

showValueList :: [Double] -> String #

PyValue Int # 
Instance details

Defined in Ganeti.PyValue

Methods

showValue :: Int -> String #

showValueList :: [Int] -> String #

PyValue a => PyValue (ListSet a) # 
Instance details

Defined in Ganeti.PyValue

Methods

showValue :: ListSet a -> String #

showValueList :: [ListSet a] -> String #

PyValue a => PyValue (FrozenSet a) #

Converts a Haskell Set into a Python frozenset

This instance was supposed to be for Set instead of FrozenSet. However, 'ghc-6.12.1' seems to be crashing with 'segmentation fault' due to the presence of more than one instance of Set, namely, this one and the one in OpCodes. For this reason, we wrap Set into FrozenSet.

Instance details

Defined in Ganeti.ConstantUtils

Methods

showValue :: FrozenSet a -> String #

showValueList :: [FrozenSet a] -> String #

PyValue a => PyValue (SetParamsMods a) # 
Instance details

Defined in Ganeti.OpCodes

Methods

showValue :: SetParamsMods a -> String #

showValueList :: [SetParamsMods a] -> String #

PyValue a => PyValue (NonEmpty a) # 
Instance details

Defined in Ganeti.OpCodes

Methods

showValue :: NonEmpty a -> String #

showValueList :: [NonEmpty a] -> String #

PyValue a => PyValue (NonNegative a) # 
Instance details

Defined in Ganeti.OpCodes

Methods

showValue :: NonNegative a -> String #

showValueList :: [NonNegative a] -> String #

PyValue a => PyValue (Private a) # 
Instance details

Defined in Ganeti.Types

Methods

showValue :: Private a -> String #

showValueList :: [Private a] -> String #

PyValue a => PyValue (Secret a) # 
Instance details

Defined in Ganeti.Types

Methods

showValue :: Secret a -> String #

showValueList :: [Secret a] -> String #

PyValue a => PyValue (JSObject a) # 
Instance details

Defined in Ganeti.OpCodes

Methods

showValue :: JSObject a -> String #

showValueList :: [JSObject a] -> String #

PyValue a => PyValue [a] # 
Instance details

Defined in Ganeti.PyValue

Methods

showValue :: [a] -> String #

showValueList :: [[a]] -> String #

(PyValue k, PyValue a) => PyValue (Map k a) # 
Instance details

Defined in Ganeti.PyValue

Methods

showValue :: Map k a -> String #

showValueList :: [Map k a] -> String #

(PyValue a, PyValue b) => PyValue (a, b) # 
Instance details

Defined in Ganeti.PyValue

Methods

showValue :: (a, b) -> String #

showValueList :: [(a, b)] -> String #

(PyValue a, PyValue b, PyValue c) => PyValue (a, b, c) # 
Instance details

Defined in Ganeti.PyValue

Methods

showValue :: (a, b, c) -> String #

showValueList :: [(a, b, c)] -> String #

data PyValueEx #

Encapsulates Python default values

Constructors

forall a.PyValue a => PyValueEx a 

Instances

Instances details
PyValue PyValueEx # 
Instance details

Defined in Ganeti.PyValue

Methods

showValue :: PyValueEx -> String #

showValueList :: [PyValueEx] -> String #

data OpCodeField #

Constructors

OpCodeField 

Fields

data OpCodeDescriptor #

Transfers opcode data between the opcode description (through genOpCode) and the Python code generation functions.

Constructors

OpCodeDescriptor 

Fields

genOpCode #

Arguments

:: String

Type name to use

-> [OpCodeConstructor]

Constructor name and parameters

-> Q [Dec] 

Generates the OpCode data type.

This takes an opcode logical definition, and builds both the datatype and the JSON serialisation out of it. We can't use a generic serialisation since we need to be compatible with Ganeti's own, so we have a few quirks to work around.

genStrOfOp :: Name -> String -> Q [Dec] #

Constructor-to-string for LuxiOp.

genStrOfKey :: Name -> String -> Q [Dec] #

Constructor-to-string for MsgKeys.

genLuxiOp :: String -> [LuxiConstructor] -> Q [Dec] #

Generates the LuxiOp data type.

This takes a Luxi operation definition and builds both the datatype and the function transforming the arguments to JSON. We can't use anything less generic, because the way different operations are serialized differs on both parameter- and top-level.

There are two things to be defined for each parameter:

  • name
  • type

data Field #

Serialised field data type describing how to generate code for the field. Each field has a type, which isn't captured in the type of the data type, but is saved in the Q monad in fieldType.

Let t be a type we want to parametrize the field with. There are the following possible types of fields:

Mandatory with no default.
Then fieldType holds t, fieldDefault = Nothing and fieldIsOptional = NotOptional.
Field with a default value.
Then fieldType holds t and fieldDefault = Just exp where exp is an expression of type t and fieldIsOptional = NotOptional.
Optional, no default value.
Then fieldType holds Maybe t, fieldDefault = Nothing and fieldIsOptional is either OptionalOmitNull or OptionalSerializeNull.

Optional fields with a default value are prohibited, as their main intention is to represent the information that a request didn't contain the field data.

Custom (de)serialization: Field can have custom (de)serialization functions that are stored in fieldRead and fieldShow. If they aren't provided, the default is to use readJSON and showJSON for the field's type t. If they are provided, the type of the contained deserializing expression must be

  [(String, JSON.JSValue)] -> JSON.JSValue -> JSON.Result t

where the first argument carries the whole record in the case the deserializing function needs to process additional information.

The type of the contained serializing experssion must be

  t -> (JSON.JSValue, [(String, JSON.JSValue)])

where the result can provide extra JSON fields to include in the output record (or just return [] if they're not needed).

Note that for optional fields the type appearing in the custom functions is still t. Therefore making a field optional doesn't change the functions.

There is also a special type of optional field AndRestArguments which allows to parse any additional arguments not covered by other fields. There can be at most one such special field and it's type must be Map String JSON.JSValue. See also andRestArguments.

Constructors

Field 

Fields

simpleField :: String -> Q Type -> Field #

Generates a simple field.

andRestArguments :: String -> Field #

Generate an AndRestArguments catch-all field.

withDoc :: String -> Field -> Field #

defaultField :: Q Exp -> Field -> Field #

Sets the default value on a field (makes it optional with a default value).

notSerializeDefaultField :: Q Exp -> Field -> Field #

A defaultField which will be serialized only if it's value differs from a default value.

presentInForthcoming :: Field -> Field #

Mark a field as present in the forthcoming variant.

optionalField :: Field -> Field #

Marks a field optional (turning its base type into a Maybe).

optionalNullSerField :: Field -> Field #

Marks a field optional (turning its base type into a Maybe), but with Nothing serialised explicitly as null.

makeOptional :: Field -> Field #

Make a field optional, if it isn't already.

renameField :: String -> Field -> Field #

Sets the renamed constructor field.

customField #

Arguments

:: Name

The name of the read function

-> Name

The name of the show function

-> [String]

The name of extra field keys

-> Field

The original field

-> Field

Updated field

Sets custom functions on a field.

buildObject :: String -> String -> [Field] -> Q [Dec] #

Build an object declaration.

buildObjectWithForthcoming #

Arguments

:: String

Name of the newly defined type

-> String

base prefix for field names; for the real and forthcoming variant, with base prefix will be prefixed with "real" and forthcoming, respectively.

-> [Field]

List of fields in the real version

-> Q [Dec] 

Build an object that can have a forthcoming variant. This will create 3 data types: two objects, prefixed by Real and Forthcoming, respectively, and a sum type of those. The JSON representation of the latter will be a JSON object, dispatching on the "forthcoming" key.

buildObjectSerialisation :: String -> [Field] -> Q [Dec] #

Generates an object definition: data type and its JSON instance.

buildParam :: String -> String -> [Field] -> Q [Dec] #

Build a parameter declaration.

This function builds two different data structures: a filled one, in which all fields are required, and a partial one, in which all fields are optional. Due to the current record syntax issues, the fields need to be named differrently for the two structures, so the partial ones get a P suffix. Also generate a default value for the partial parameters.

genException #

Arguments

:: String

Name of new type

-> SimpleObject

Constructor name and parameters

-> Q [Dec] 

Builds an exception type definition.

excErrMsg :: (String, Q Type) #

Exception simple error message field.

ssconfConstructorName :: String -> String #

Compute the ssconf constructor name from its file name.