Ignore hlint warning "Error: Too strict if" in Server.hs

This warning appears only in newer versions of hlint (mine was v1.8.43),
and in this case it's reported incorrectly. The arguments to "showJSON"
have different types, therefore it's not possible to move "showJSON" in
front of "if".

Signed-off-by: Petr Pudlak <pudlak@google.com>
Signed-off-by: Klaus Aehlig <aehlig@google.com>
Reviewed-by: Klaus Aehlig <aehlig@google.com>
Ignore hlint warning "Error: Too strict if" in Server.hs

A previous patch [229da00] added an annotation for ignoring the warning,
but to the middle of a function, which doesn't compile. This patch moves
the annotation to the end of the function to correct the problem.

Signed-off-by: Petr Pudlak <pudlak@google.com>
Signed-off-by: Klaus Aehlig <aehlig@google.com>
Reviewed-by: Klaus Aehlig <aehlig@google.com>
Add missing Constructor for SetParamsMods

Disks and nics can not only be addressed by indices, but also
by name. Hence add a constructor for this case as well, to be
faithful to the python world.

Signed-off-by: Klaus Aehlig <aehlig@google.com>
Reviewed-by: Hrvoje Ribicic <riba@google.com>
man gnt-network: indicate that --network is mandatory

Despite the fact that the '--network' parameter of
'gnt-network add' is mandatory, it is listed in the man
page in parenthesis, which suggests that it is optional.
Fixing this to avoid user confusion.

Signed-off-by: Helga Velroyen <helgav@google.com>
Reviewed-by: Guido Trotter <ultrotter@google.com>
Fix typo in documentation

Signed-off-by: Jose A. Lopes <jabolopes@google.com>
Reviewed-by: Hrvoje Ribicic <riba@google.com>
Add Python hypervisor instance state

Add 'HvInstanceState' which represents the state of an instance
(either 'running' or 'shutdown') and fix the remaining hypervisor
backends to return a value of this type.  Before this patch, each
backend was returning their own value, some were returning strings,
others integers.  However, the value that represents the state of an
instance was never actually used in Ganeti, until instance shutdown
detection became necessary.

Signed-off-by: Jose A. Lopes <jabolopes@google.com>
Reviewed-by: Hrvoje Ribicic <riba@google.com>
Add Haskell hypervisor instance state

Add 'InstanceState' datatype which is the Haskell counterpart of the
Python type 'HvInstanceState'.

Signed-off-by: Jose A. Lopes <jabolopes@google.com>
Reviewed-by: Hrvoje Ribicic <riba@google.com>
Preserve Xen domain after shutdown

Change Xen domain configuration to preserve the domain state after
shutdown, as opposed to automatic reboot, which is the default
behaviour.

Signed-off-by: Jose A. Lopes <jabolopes@google.com>
Reviewed-by: Hrvoje Ribicic <riba@google.com>
Add instance state 'USER_down'

Add instance state 'USER_down' which is a state used in reporting only
and it represents the situation in which the user has shutdown the
instance but Ganeti's configuration still has this instance marked as
'ADMIN_up'.

Signed-off-by: Jose A. Lopes <jabolopes@google.com>
Reviewed-by: Hrvoje Ribicic <riba@google.com>
Xen handle domain shutdown

Update Xen backend to properly recognize when a domain has been
shutdown by the user and to properly cleanup a shutdown domain when
Ganeti requests Xen to stop this domain.

Signed-off-by: Jose A. Lopes <jabolopes@google.com>
Reviewed-by: Hrvoje Ribicic <riba@google.com>
Prevent instance start when user down

Prevent starting a given instance when that instance has been shutdown
by the user, given that the instance must be first properly shutdown.

Signed-off-by: Jose A. Lopes <jabolopes@google.com>
Reviewed-by: Hrvoje Ribicic <riba@google.com>
Python instance queries report 'USER_down'

Update instance queries on the Python codebase to report 'USER_down'
in the situation where the user has shutdown a Xen domain but Ganeti
still marks this domain as 'ADMIN_up' in its configuration file.

Signed-off-by: Jose A. Lopes <jabolopes@google.com>
Reviewed-by: Hrvoje Ribicic <riba@google.com>
Haskell instance queries report 'USER_down'

Update instance queries on the Haskell codebase to report 'USER_down',
similarly to the Python instance queries.

Signed-off-by: Jose A. Lopes <jabolopes@google.com>
Reviewed-by: Hrvoje Ribicic <riba@google.com>
Watcher cleans user shutdown domains

Update watcher to destroy shutdown domains when it detects that a
domain is in the state 'USER_down'.  This requires adding logic
similar to that of restart instance, that is tracking the number of
cleanup attempts in the watcher's state and give up if a given number
of retries has been reached.

Signed-off-by: Jose A. Lopes <jabolopes@google.com>
Reviewed-by: Hrvoje Ribicic <riba@google.com>
Update tests

Update hypervisor unit tests.

Signed-off-by: Jose A. Lopes <jabolopes@google.com>
Reviewed-by: Hrvoje Ribicic <riba@google.com>
Fix class methods in KVM hypervisor

Several methods in KVM hypervisor behave like 'classmethods', however,
they did not have the '@classmethod' annotation.  This patch adds
'@classmethod' annotations to several of these methods with the goal
of making '_StopInstance' available to the QA.  This step is necessary
for the QA test for instance shutdown detection on KVM.

Signed-off-by: Jose A. Lopes <jabolopes@google.com>
Reviewed-by: Hrvoje Ribicic <riba@google.com>
Add QA tests for instance shutdown detection

Add QA tests for instance shutdown detection with Xen PVM and HVM
hypervisors.

Signed-off-by: Jose A. Lopes <jabolopes@google.com>
Reviewed-by: Hrvoje Ribicic <riba@google.com>
Fix instance info

Signed-off-by: Jose A. Lopes <jabolopes@google.com>
Reviewed-by: Hrvoje Ribicic <riba@google.com>