Replace 'DISKLESS' check w/ 'not inst.disks'

The disk templates are going away for the instances, so the new
definition of being diskless is to be actually without any disks
attached.

Signed-off-by: Aaron Karper <akarper@google.com>
Signed-off-by: Michele Tartara <mtartara@google.com>
Reviewed-by: Michele Tartara <mtartara@google.com>
Remove duplication for DiskTemplate/StorageType mapping

Currently both Ganeti.Constants and Ganeti.Types define the mapping of
disk templates and storage types independently. This change automates
the generation of the mapping in Ganeti.Constants.

Signed-off-by: Aaron Karper <akarper@google.com>
Signed-off-by: Michele Tartara <mtartara@google.com>
Reviewed-by: Michele Tartara <mtartara@google.com>
Use @wraps for withLockedLU

This change enables tools like 'nose2' to execute only one single test
method, which is a great help when debugging. Plus using wraps is good
style for a wrapper.

Signed-off-by: Aaron Karper <akarper@google.com>
Signed-off-by: Michele Tartara <mtartara@google.com>
Reviewed-by: Michele Tartara <mtartara@google.com>
Cleanup some haskell code

Use Applicative in disk type parsing

remove unnecessary lambda in THH code

Signed-off-by: Aaron Karper <akarper@google.com>
Signed-off-by: Michele Tartara <mtartara@google.com>
Reviewed-by: Michele Tartara <mtartara@google.com>
Update doc: show relation DiskTemplate <-> DiskLogicalId

The relation between the two is simple, but undocumented, which would
lead to problems with new people working on this.

Signed-off-by: Aaron Karper <akarper@google.com>
Signed-off-by: Michele Tartara <mtartara@google.com>
Reviewed-by: Michele Tartara <mtartara@google.com>
Refactor cmdlib.instance.LUInstanceSetParam#CheckPrereq

The method got out of hand (350 lines with 50+ local variables), this
patch gets it back under control.

Signed-off-by: Aaron Karper <akarper@google.com>
Signed-off-by: Michele Tartara <mtartara@google.com>
Reviewed-by: Michele Tartara <mtartara@google.com>
Make ComputeIPolicySpecViolation take multiple disk types

This requires all callers to provide all disk types of the instance
checked. If that isn't possible, the singleton list can be used. The
function checks that assertion.

Signed-off-by: Aaron Karper <akarper@google.com>
Signed-off-by: Michele Tartara <mtartara@google.com>
Reviewed-by: Michele Tartara <mtartara@google.com>
Avoid using instance disk template in cmdlib.cluster

This patch removes the usages of the instance's disk_template object in
the cmdlib.cluster file. This is independent of other refactors.

Signed-off-by: Aaron Karper <akarper@google.com>
Signed-off-by: Michele Tartara <mtartara@google.com>
Reviewed-by: Michele Tartara <mtartara@google.com>
Avoid using instance disk template in cmdlib.group

This patch removes the uses of the instance's disk_template to classify
instances and uses the disk's device types instead.

Signed-off-by: Aaron Karper <akarper@google.com>
Signed-off-by: Michele Tartara <mtartara@google.com>
Reviewed-by: Michele Tartara <mtartara@google.com>
Avoid using disk template in cmdlib.instance_migration

This patch removes the dependency on the instance disk_template from
cmdlib.instance_migration and replaces it with the disk types.

Signed-off-by: Aaron Karper <akarper@google.com>
Signed-off-by: Michele Tartara <mtartara@google.com>
Reviewed-by: Michele Tartara <mtartara@google.com>
Avoid using disk template in cmdlib.instance_storage

Remove dependency on instance disk_template in cmdlib.instance_storage
to only depend on the disk type.

Signed-off-by: Aaron Karper <akarper@google.com>
Signed-off-by: Michele Tartara <mtartara@google.com>
Reviewed-by: Michele Tartara <mtartara@google.com>
Avoid using instance disk template in cmdlib.node

Remove dependency on instance disk_template and replace it with disk
type in the package cmdlib.node.

Signed-off-by: Aaron Karper <akarper@google.com>
Signed-off-by: Michele Tartara <mtartara@google.com>
Reviewed-by: Michele Tartara <mtartara@google.com>
Avoid using instance disk template in cmdlib.instance

Remove dependency on instance disk_template and replace it with disk
type in the package cmdlib.instance.

Signed-off-by: Aaron Karper <akarper@google.com>
Signed-off-by: Michele Tartara <mtartara@google.com>
Reviewed-by: Michele Tartara <mtartara@google.com>
Add nodes field in class Disk

Add a field called "nodes" in the Disk class. This field will be a list
of Ganeti node UUIDs from which this disk is accessible. Also, update
the Haskell tests in order to adjust to this change.
Populate disk nodes when creating disks

When creating a Disk using the GenerateDiskTemplate function, fill the
nodes field depending on the disk template. There are three cases:

1) Internally mirrored disks (DRBD):
   These disks are accessible from two nodes, so the nodes field will
   include these. Their children (data, meta) are also accessible from
   two nodes, therefore they will inherit the nodes of the parent.
2) Externally mirrored disks (Blockdev, Ext, Gluster, RBD, Shared File):
   These disks should be accessible from any node in the cluster,
   therefore the nodes field will be empty.
3) Single-node disks (Plain, File):
   These disks are accessible from one node only, therefore the nodes
   field will consist only of the primary instance node.
Maintain consistency of nodes field

There are four scenarios in which the nodes field can change after the
disk's creation; when moving, replacing, converting or recreating disks.
For each scenario, update the nodes field accordingly.
Update cfgupgrade tool

Create an upgrade function that adds a nodes field to each disk that is
attached to an instance. Also, add a downgrade function that removes the
nodes field and brings the config to the default state for 2.12.
Update various tests regarding disk creation

Update the tests that deal with disk creation and check if the nodes
field is populated correctly when creating a disk.