Add JSON a decoding function branching on a field

Add a function that allows to branch on a field in a JSObject.
Such a function can be used to decode from JSON objects that
have two variants, e.g., instances and forthcoming instances.

Signed-off-by: Klaus Aehlig <aehlig@google.com>
Reviewed-by: Petr Pudlak <pudlak@google.com>
Add a function to add a field to a JSON object

This is a convenience wrapper over Text.JSON.set_field,
that is defined on all JSValues (and does nothing if the
argument is not an object). Also, the order of arguments
is so that partial application becomes easy.

Signed-off-by: Klaus Aehlig <aehlig@google.com>
Reviewed-by: Petr Pudlak <pudlak@google.com>
Allow fields to be marked as present in forthcoming variant

While in the forthcoming variant of an object usually fields
are optional, some fields still are always present, e.g.,
the UUID. Add a flag to fields to marks those.

Signed-off-by: Klaus Aehlig <aehlig@google.com>
Reviewed-by: Petr Pudlak <pudlak@google.com>
UUID is present, also in forthcoming objects

Signed-off-by: Klaus Aehlig <aehlig@google.com>
Reviewed-by: Petr Pudlak <pudlak@google.com>
Serial fields are present in forthcoming objects

Signed-off-by: Klaus Aehlig <aehlig@google.com>
Reviewed-by: Petr Pudlak <pudlak@google.com>
Add function to obtain "forthcoming" field version

This function renders fields into their "forthcoming" version.
Usually, this just means making the field optional.

Signed-off-by: Klaus Aehlig <aehlig@google.com>
Reviewed-by: Petr Pudlak <pudlak@google.com>
Generate object plus forthcoming variant in THH

From the data defining an object (which, in particular, includes
the list of fields), generate
- a real variant of the object,
- a forthcoming variant of the object,
- and the type itself, having two constructors, one taking a real
  object as argument and one taking a forthcoming object as argument.
Also generate JSON instances. For the sum type, the JSON representation
is a JSON object dispatching on the "forthcoming" entry.

Signed-off-by: Klaus Aehlig <aehlig@google.com>
Reviewed-by: Petr Pudlak <pudlak@google.com>
Also generate accessor functions

As objects that can be forthcoming are sum types, we
need to define additional functions that access the fields,
dispatching on whether the object is real or forthcoming.

Signed-off-by: Klaus Aehlig <aehlig@google.com>
Reviewed-by: Petr Pudlak <pudlak@google.com>
Remove obsolete comment

Signed-off-by: Klaus Aehlig <aehlig@google.com>
Reviewed-by: Petr Pudlak <pudlak@google.com>
Move Instance definition to a separate module

Move the definition of Instances from Ganeti.Objects to
a separate module. This allows convenient exportation of
all generated acessor functions, when we start supporting
forthcoming instances. This module gets reexported from
Ganeti.Objects, so that other modules are not affected.

Signed-off-by: Klaus Aehlig <aehlig@google.com>
Reviewed-by: Petr Pudlak <pudlak@google.com>
Add a value for the empty Container

...so that we can use it as a default for Container
parameters.

Signed-off-by: Klaus Aehlig <aehlig@google.com>
Reviewed-by: Petr Pudlak <pudlak@google.com>
For hvparams add a default

...which is the empty container.

Signed-off-by: Klaus Aehlig <aehlig@google.com>
Reviewed-by: Petr Pudlak <pudlak@google.com>
Also generate empty partial params

...so that they can be used as default values.

Signed-off-by: Klaus Aehlig <aehlig@google.com>
Reviewed-by: Petr Pudlak <pudlak@google.com>
Add a default for beparams

...which is the emptyPartialBeParams.

Signed-off-by: Klaus Aehlig <aehlig@google.com>
Reviewed-by: Petr Pudlak <pudlak@google.com>
Have default values for OS params

...as they are collections anyway.

Signed-off-by: Klaus Aehlig <aehlig@google.com>
Reviewed-by: Petr Pudlak <pudlak@google.com>
Add defaults for disks and nics

...which is not having any of them.

Signed-off-by: Klaus Aehlig <aehlig@google.com>
Reviewed-by: Petr Pudlak <pudlak@google.com>
Build lens for shared fields

If some fields have the same optionality type
in real and forthcoming object, build a Simple Lens
as well.

Signed-off-by: Klaus Aehlig <aehlig@google.com>
Reviewed-by: Petr Pudlak <pudlak@google.com>
Support forthcoming instances

Change the type of instance objects to be the sum of real and
forthcoming instances. Note that the wire representation is
backwards compatible, so we can keep the change local to the
Haskell code base.

Also, for the time being, the monitoring daemon will collect
data only for real instances.

Signed-off-by: Klaus Aehlig <aehlig@google.com>
Reviewed-by: Petr Pudlak <pudlak@google.com>
Add an operation to write and unlock the config

Supporting this function, an additional round-trip can be saved per
operation.

Signed-off-by: Klaus Aehlig <aehlig@google.com>
Reviewed-by: Petr Pudlak <pudlak@google.com>
Make ConfigWrite use configWriteAndUnlock

...thus saving one round trip on config writes.

Signed-off-by: Klaus Aehlig <aehlig@google.com>
Reviewed-by: Petr Pudlak <pudlak@google.com>