Fix whitespace

Signed-off-by: Jose A. Lopes <jabolopes@google.com>
Reviewed-by: Michele Tartara <mtartara@google.com>
Rename 'CdromOption' to '_CdromOption'

... because it is a protected definition.

Signed-off-by: Jose A. Lopes <jabolopes@google.com>
Reviewed-by: Michele Tartara <mtartara@google.com>
Fix missing 'L{...}' in docstring

Signed-off-by: Jose A. Lopes <jabolopes@google.com>
Reviewed-by: Michele Tartara <mtartara@google.com>
Fix missing '@raise' in docstring

Signed-off-by: Jose A. Lopes <jabolopes@google.com>
Reviewed-by: Michele Tartara <mtartara@google.com>
Fix missing '@raise' in docstring

Signed-off-by: Jose A. Lopes <jabolopes@google.com>
Reviewed-by: Michele Tartara <mtartara@google.com>
Assert correct usage of AndRestArguments fields

The special field andRestArguments is intended to be only used
as the last field of an object, catching all remaining keys.
Add a compile-time check to verify that it is used correctly.

Signed-off-by: Klaus Aehlig <aehlig@google.com>
Reviewed-by: Petr Pudlak <pudlak@google.com>
Catch exceptions in 'readConfig' in Ganeti.Config

.. and convert them into a "Result".
This is accomplished by using "liftIO" from ResultT.

Signed-off-by: Petr Pudlak <pudlak@google.com>
Reviewed-by: Klaus Aehlig <aehlig@google.com>
Catch errors in 'lockFile' in Ganeti.Utils

Opening a file can fail as well, so catch errors there too.

Signed-off-by: Petr Pudlak <pudlak@google.com>
Reviewed-by: Klaus Aehlig <aehlig@google.com>
Add Alternative instances for GenericResult and ResultT

This allows to use Alternative specific combinators, namely `optional`.

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

Cherry-pick of 78209a84b0f6be27fd381ac2

Signed-off-by: Klaus Aehlig <aehlig@google.com>
Reviewed-by: Petr Pudlak <pudlak@google.com>
Remove FromString in favor of Error from standard libraries

They have the very same functionality, and using our own FromString only
causes unnecessary code duplication.

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

Cherry-pick of a87a017b023e2979b73f11dcf90

Signed-off-by: Klaus Aehlig <aehlig@google.com>
Reviewed-by: Petr Pudlak <pudlak@google.com>
Add functions for manipulating errors in Result(T)

There is often need to manipulate these errors, for example to convert a String
from Result into an exception. These functions make this easier.

Function 'toErrorStr' lifts 'Result' to any 'MonadError'. This is useful
for converting 'Result' into 'ResultT' or any other similar monad stack.

Functions 'catchErrorT' and 'handleErrorT' catch errors just as 'catchError'
does, but also allow to change the error type.

Functions `withError` and `withErrorT` allow to modify an error within
GenericResult or ResultT. This is convenient when combining functions
with different error types, for example to convert between strings and
exceptions.

Furthemore, 'failError' generalize 'Bad'. It can be used anywhere 'Bad' is, and
in any 'MonadError' instance.

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

Cherry-pick of 565821d1804f8734bdd2959e367

Signed-off-by: Klaus Aehlig <aehlig@google.com>
Reviewed-by: Petr Pudlak <pudlak@google.com>
Add a function changing the priority of an opcode

This pure function follows the semantic that an opcode, including
its priority, may only be changed if the opcode is not finalized.

Signed-off-by: Klaus Aehlig <aehlig@google.com>
Reviewed-by: Petr Pudlak <pudlak@google.com>
Add a function to change the priority of a job

...by changing the priority of the non-finished opcodes.

Signed-off-by: Klaus Aehlig <aehlig@google.com>
Reviewed-by: Petr Pudlak <pudlak@google.com>
Change return type of internal rmJob

...to also provide the job itself. In this way, the function can
also be used for tasks that require temporarily removing a job
from the queue.

Signed-off-by: Klaus Aehlig <aehlig@google.com>
Reviewed-by: Petr Pudlak <pudlak@google.com>
When enqueuing new jobs, respect job ID

When adding new jobs, don't add them at the end, but at a
position that fits with their job id. In this way, we can
build operations that require fully dequeing a job an adding
it later after some modifications.

Signed-off-by: Klaus Aehlig <aehlig@google.com>
Reviewed-by: Petr Pudlak <pudlak@google.com>
Provide a function to change the priority of a queued job

There is a separation of responsibilities here. For jobs still
in the queue, it is the responsibility of the queue (scheduler),
for started jobs, the job itself has to take care of it. To avoid
the job transitioning inbetween, it is temporarily dequeued during
the operation. The operation changes the file on master, while
leaving the replication to the caller.

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

For jobs still queued, we ask the queue to change the priority,
and replicate the changed job. For jobs that have already been
started, we have to contact the job directly, which, at the moment,
means forwarding the request to masterd.

Signed-off-by: Klaus Aehlig <aehlig@google.com>
Reviewed-by: Petr Pudlak <pudlak@google.com>
Merge branch 'stable-2.11' into master

* stable-2.11
  Implement ChangeJobPriority in luxid
  Provide a function to change the priority of a queued job
  When enqueuing new jobs, respect job ID
  Change return type of internal rmJob
  Add a function to change the priority of a job
  Add a function changing the priority of an opcode
  3 cherry-picks from master:
    Add functions for manipulating errors in Result(T)
    Remove FromString in favor of Error from standard libraries
    Add Alternative instances for GenericResult and ResultT

Conflicts:
	src/Ganeti/BasicTypes.hs: use version of master

Signed-off-by: Klaus Aehlig <aehlig@google.com>
Reviewed-by: Petr Pudlak <pudlak@google.com>
Let Haddock also generate Hoogle documentation

The Hoogle database is generated to doc/api/hs/ganeti.txt when Haddock
is run. The database can be used by developers with a locally installed
Hoogle command line tool or for a web installation of Hoogle.

Signed-off-by: Petr Pudlak <pudlak@google.com>
Reviewed-by: Hrvoje Ribicic <riba@google.com>
Add job death detection to the daemons refactoring doc

Describe how to use file lock to implement it in a POSIX compliant way.

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