Fix socket permissions after master-failover

When using gnt-cluster master-failover, on the soon-to-be-master the
luxi daemon is started by the node daemon. This makes the luxi
daemon inherit the node daemon's umask 077, making the communication
socket unreadable to group members. When using Ganeti with non-root
users, this causes problems, as reported in issue 477.

To fix this, the socket permissions are set explicitly.

Signed-off-by: Hrvoje Ribicic <riba@google.com>
Reviewed-by: Michele Tartara <mtartara@google.com>
Update NEWS file with socket permission fix info

The NEWS file now contains a 2.8.3 entry, describing the fix of the
previous patch.

Signed-off-by: Hrvoje Ribicic <riba@google.com>
Reviewed-by: Michele Tartara <mtartara@google.com>
Downgrade from 2.10 to 2.9 correctly

Add handling for Open vSwitch related configuration parameters as well
as for the "cpuid" and "soundhw" hypervisor parameters.

Signed-off-by: Thomas Thrainer <thomasth@google.com>
Reviewed-by: Jose A. Lopes <jabolopes@google.com>
Be paranoid about existing keys in cfgupgrade

The cfgupgrade test assumes a very minimal configuration for some of its
tests. This configuration does not contain some of the fields which were
assumed to be present in cfgupgrade. This patch tests for the existence
of those fields before trying to access them.

Signed-off-by: Thomas Thrainer <thomasth@google.com>
Reviewed-by: Jose A. Lopes <jabolopes@google.com>
Mark cluster's IPs as externally reserved

Currently, upon network creation, nodes' and master's IPs
are reserved in the pool.

This leads to pool reservations ('X' in map) that cannot be changed
afterwards, although they may need to (e.g. in case of node
removal/modification). Also, these IPs are not actually handled by
Ganeti in the sense that they are not assigned to the cluster's VMs.

Thus, we should mark the as externally reserved and not just reserved.

Signed-off-by: Dimitris Aragiorgis <dimara@grnet.gr>
Signed-off-by: Thomas Thrainer <thomasth@google.com>
Reviewed-by: Thomas Thrainer <thomasth@google.com>
Allow instances to obtain externally reserved IPs

The administrator should be able to assign an externally reserved IP
to a Ganeti instance manually, if desired. Currently this is not
supported. External reservations should act as holes in the pool and
not just as IPs already used by someone outside of Ganeti.
Automatic allocation with ip=pool will continue to exclude those IPs
as happens now.

To allow such functionality the administrator needs to pass explicitly
the desired IP along with the ``--no-conflicts-check`` option, or else
an error will be produced as happens now.

The aforementioned require the following changes:

 - Make IsReserved() to look either in reservations or external ones.
 - Make Reserve() and Release() to use IsReserved() with external
   argument True or False.
 - Pass extra option to ReserveIp() to bypass checking of external reservations
 - Update man pages and design doc for this change.

Furthermore, a side effect of this patch is that it fixes the
following problem:
Currently, one could not mark an IP as external if it was already
reserved (i.e. belonged to an instance). The code would produce a warning
and fail silently.

Fix config_mock.py so that if network and ip is given then reserve it in
the pool.

Signed-off-by: Dimitris Aragiorgis <dimara@grnet.gr>
Signed-off-by: Thomas Thrainer <thomasth@google.com>
Reviewed-by: Thomas Thrainer <thomasth@google.com>
RAPI: Pass depends body arg (if any) to opcode

Most rlib2 classes override the default _GetDefaultData() method with
custom methods that parse a request's body and query args and return a
(body, specific_static) tuple eventually passed to FillOpCode().
Job dependencies are defined in the `depends` body argument that might
get lost because most of those methods return {} as the body. In order
not to modify every custom method we update the returned body with
the `depends` argument of the original request body for all RAPI calls
inside OpcodeResource._GenericHandler(). It's up to the client to
include the `depends` argument with the job dependencies if desired.

Signed-off-by: Dimitris Aragiorgis <dimara@grnet.gr>
Reviewed-by: Hrvoje Ribicic <riba@google.com>
RAPI: Make use of request_body in Reboot/Remove

Until now, the shutdown_timeout parameter could only be passed to
ShutdownInstance() inside kwargs, causing it to be included in the
request body. Based on that, extend RebootInstance() and
RemoveInstance() so that they can take extra arguments (e.g.
shutdown_timeout) and pass them eventually to the corresponding opcode.

Signed-off-by: Dimitris Aragiorgis <dimara@grnet.gr>
Reviewed-by: Hrvoje Ribicic <riba@google.com>
Add an aggregate NIC VLAN field to Python queries

As all other NIC fields have an aggregate retrieval field, add one for
the VLANs as well.

Signed-off-by: Hrvoje Ribicic <riba@google.com>
Reviewed-by: Thomas Thrainer <thomasth@google.com>
Introduce --hotplug-if-possible option

This will be useful for an external entity using RAPI that
wants to modify devices of instances.

The common use case for that is:
"I want to add a NIC/disk to an instance. If it is running
then try to hotplug the device. If not, then just add it to config."

Another use case is that if we are unaware of the instance's
hypervisor: "I want do add a NIC/disk to an instance and if
its hypervisor is KVM try to hotplug it."

For all those cases just print a warning in CheckPrereq() and
disable any further hotplug related actions (and let
modifications take place after reboot).

Add NoHoplugSupport and HotplugIfPossible unittests an modify
existing by explicitly creating successful RPC results for
call_hotplug_supported.

Signed-off-by: Dimitris Aragiorgis <dimara@grnet.gr>
Signed-off-by: Thomas Thrainer <thomasth@google.com>
Reviewed-by: Thomas Thrainer <thomasth@google.com>
Fix net-common script in case of routed mode

setup_route should run in case or routed mode and not
openvswitch.

Signed-off-by: Dimitris Aragiorgis <dimara@grnet.gr>
Signed-off-by: Thomas Thrainer <thomasth@google.com>
Reviewed-by: Thomas Thrainer <thomasth@google.com>
Export tags via GetTags() to network scripts

Use GetTags() instance method in order to export instance tags
to NIC configuration scripts and files of kvm and xen hypervisors.

Signed-off-by: Dimitris Aragiorgis <dimara@grnet.gr>
Signed-off-by: Thomas Thrainer <thomasth@google.com>
Reviewed-by: Thomas Thrainer <thomasth@google.com>
Use HooksDict() to export network options in Xen

Remove duplicate code that exports network options to environment
variables.

Signed-off-by: Dimitris Aragiorgis <dimara@grnet.gr>
Signed-off-by: Thomas Thrainer <thomasth@google.com>
Reviewed-by: Thomas Thrainer <thomasth@google.com>
Export NIC's UUID and name to network scripts

In case of kvm None values are not allowed in env dict
so we have to add name only if not None.

In case of Xen since we are writing on a file that
is going to be sourced we should not add INTERFACE_NAME=None.

Fix IP=None case.

Signed-off-by: Dimitris Aragiorgis <dimara@grnet.gr>
Signed-off-by: Thomas Thrainer <thomasth@google.com>
Reviewed-by: Thomas Thrainer <thomasth@google.com>
Schedule 2.10~beta1 release in NEWS file

Schedule the 2.10~beta1 release for November 27th.

Signed-off-by: Thomas Thrainer <thomasth@google.com>
Reviewed-by: Helga Velroyen <helgav@google.com>
Version bump for 2.10~beta1

Bump version for the upcoming 2.10~beta1 release.

Signed-off-by: Thomas Thrainer <thomasth@google.com>
Reviewed-by: Helga Velroyen <helgav@google.com>
KVM: use custom KVM path if set for version checking

This commit fixes two TODOs from 2008 about using the hardcoded
"default" path for KVM where a custom one could've been set through
`gnt-cluster modify`.

As a result, `gnt-cluster verify` will no longer fail if a custom
path was set in such a manner.

Signed-off-by: Santi Raffa <rsanti@google.com>
Signed-off-by: Klaus Aehlig <aehlig@google.com>
Reviewed-by: Klaus Aehlig <aehlig@google.com>
Ganeti.Rpc: use brackets for ipv6 addresses

We detect an IPv6 vs V4 address based on columns, rather than passing
the family from the cluster object to be more future proof (in case
we'll ever support mixed clusters).

Unfortunately quite a bit more code is required to test this: we need an
arbitrary node that does the right thing w.r.t. ip addresses and also
test-only exports. As such we'll do this out of the stable branch.

Signed-off-by: Guido Trotter <ultrotter@google.com>
Reviewed-by: Michele Tartara <mtartara@google.com>
eta-reduce isIpV6

This is not only better style, but also fixes a lint error.
Also use the infix form of `elem` to increase readability.

Signed-off-by: Klaus Aehlig <aehlig@google.com>
Reviewed-by: Michele Tartara <mtartara@google.com>
Fix NODE/NODE_RES locking in LUInstanceCreate

Both NODE and NODE_RES locks were acquired opportunistically if so
requested by the user. LUInstanceCreate requires, however, that the
actually locked elements on NODE and NODE_RES level are the same.

This patch changes the locking of NODE_RES such that those locks are not
acquired opportunistically any more. Instead, the mandatory locks are
set to the acquired NODE locks once they are actually granted.

This fixes issue 622.

Signed-off-by: Thomas Thrainer <thomasth@google.com>
Reviewed-by: Petr Pudlak <pudlak@google.com>