Now "gnt-instance recreate-disks" uses the default iallocator when "." is
specified as the iallocator. For uniformity, the same behavior applies to
these commands:
gnt-node evacuate
gnt-instance migrate
gnt-instance add
"." is used instead of "default" becuse the latter could be a valid name for
an iallocator
Check that at most one of (iallocator, node) is specified. If none is
- specified, then the LU's opcode's iallocator slot is filled with the
- cluster-wide default iallocator.
+ specified, or the iallocator is constants.DEFAULT_IALLOCATOR_SHORTCUT,
+ then the LU's opcode's iallocator slot is filled with the cluster-wide
+ default iallocator.
@type iallocator_slot: string
@param iallocator_slot: the name of the opcode iallocator slot
@@ -1621,11 +1622,14 @@ def _CheckIAllocatorOrNode(lu, iallocator_slot, node_slot):
"""
node = getattr(lu.op, node_slot, None)
ialloc = getattr(lu.op, iallocator_slot, None)
+ if node == []:
+ node = None
if node is not None and ialloc is not None:
raise errors.OpPrereqError("Do not specify both, iallocator and node",
errors.ECODE_INVAL)
- elif node is None and ialloc is None:
+ elif ((node is None and ialloc is None) or
+ ialloc == constants.DEFAULT_IALLOCATOR_SHORTCUT):
default_iallocator = lu.cfg.GetDefaultIAllocator()
if default_iallocator:
setattr(lu.op, iallocator_slot, default_iallocator)
@@ -7137,9 +7141,10 @@ class LUInstanceRecreateDisks(LogicalUnit):
" once: %s" % utils.CommaJoin(duplicates),
errors.ECODE_INVAL)
- if self.op.iallocator and self.op.nodes:
- raise errors.OpPrereqError("Give either the iallocator or the new"
- " nodes, not both", errors.ECODE_INVAL)
+ # We don't want _CheckIAllocatorOrNode selecting the default iallocator
+ # when neither iallocator nor nodes are specified
+ if self.op.iallocator or self.op.nodes:
+ _CheckIAllocatorOrNode(self, "iallocator", "nodes")
"gnt-instance replace-disks" now behaves like the other commands, and uses
the default iallocator when "." is passed as the iallocator parameter.
Signed-off-by: Bernardo Dal Seno <bdals...@google.com>
---
lib/cmdlib.py | 42 ++++++++++++++++++------------------------
1 files changed, 18 insertions(+), 24 deletions(-)
diff --git a/lib/cmdlib.py b/lib/cmdlib.py
index 89fb526..2083d90 100644
--- a/lib/cmdlib.py
+++ b/lib/cmdlib.py
@@ -10649,8 +10649,24 @@ class LUInstanceReplaceDisks(LogicalUnit):
REQ_BGL = False
def CheckArguments(self):
- TLReplaceDisks.CheckArguments(self.op.mode, self.op.remote_node,
- self.op.iallocator)
+ """Check arguments.
+
+ """
+ remote_node = self.op.remote_node
+ ialloc = self.op.iallocator
+ if self.op.mode == constants.REPLACE_DISK_CHG:
+ if remote_node is None and ialloc is None:
+ raise errors.OpPrereqError("When changing the secondary either an"
+ " iallocator script must be used or the"
+ " new node given", errors.ECODE_INVAL)
+ else:
+ _CheckIAllocatorOrNode(self, "iallocator", "remote_node")
+
+ elif remote_node is not None or ialloc is not None:
+ # Not replacing the secondary
+ raise errors.OpPrereqError("The iallocator and new node options can"
+ " only be used when changing the"
+ " secondary node", errors.ECODE_INVAL)
@staticmethod
- def CheckArguments(mode, remote_node, ialloc):
- """Helper function for users of this class.
-
- """
- # check for valid parameter combination
- if mode == constants.REPLACE_DISK_CHG:
- if remote_node is None and ialloc is None:
- raise errors.OpPrereqError("When changing the secondary either an"
- " iallocator script must be used or the"
- " new node given", errors.ECODE_INVAL)
-
- if remote_node is not None and ialloc is not None:
- raise errors.OpPrereqError("Give either the iallocator or the new"
- " secondary, not both", errors.ECODE_INVAL)
-
- elif remote_node is not None or ialloc is not None:
- # Not replacing the secondary
- raise errors.OpPrereqError("The iallocator and new node options can"
- " only be used when changing the"
- " secondary node", errors.ECODE_INVAL)
-
- @staticmethod
def _RunAllocator(lu, iallocator_name, instance_name, relocate_from):
"""Compute a new secondary node using an IAllocator.
-def _DestroyInstanceVolumes(instance):
- """Remove all the LVM volumes of an instance.
+def _GetInstanceInfo(instance):
+ """Return information about the actual state of an instance.
- This is used to simulate HW errors (dead nodes, broken disks...); the
- configuration of the instance is not affected.
+ The pieces of information returned are:
+ - "nodes": instance nodes, a list of strings
+ - "volumes": instance volume IDs, a list of strings
+ @type instance: dictionary
+ @param instance: the instance
+ @return: dictionary
"""
master = qa_config.GetMasterNode()
@@ -118,7 +122,21 @@ def _DestroyInstanceVolumes(instance):
vols.append(m.group(1))
assert vols
assert nodes
- for node in nodes:
+ return {"nodes": nodes, "volumes": vols}
+
+
+def _DestroyInstanceVolumes(instance):
+ """Remove all the LVM volumes of an instance.
+
+ This is used to simulate HW errors (dead nodes, broken disks...); the
+ configuration of the instance is not affected.
+ @type instance: dictionary
+ @param instance: the instance
+
+ """
+ info = _GetInstanceInfo(instance)
+ vols = info["volumes"]
+ for node in info["nodes"]:
AssertCommand(["lvremove", "-f"] + vols, node=node)
diff --git a/man/gnt-instance.rst b/man/gnt-instance.rst
index b208954..82b032e 100644
--- a/man/gnt-instance.rst
+++ b/man/gnt-instance.rst
@@ -617,11 +617,11 @@ a hypothetical ``dhcp`` parameter to yes can be achieved by::
gnt-instance add -O dhcp=yes ...
-The ``-I (--iallocator)`` option specifies the instance allocator
-plugin to use. If you pass in this option the allocator will select
-nodes for this instance automatically, so you don't need to pass them
-with the ``-n`` option. For more information please refer to the
-instance allocator documentation.
+The ``-I (--iallocator)`` option specifies the instance allocator plugin
+to use (``.`` means the default allocator). If you pass in this option
+the allocator will select nodes for this instance automatically, so you
+don't need to pass them with the ``-n`` option. For more information
+please refer to the instance allocator documentation.
The ``-t (--disk-template)`` options specifies the disk layout type
for the instance. The available choices are:
@@ -1283,11 +1283,11 @@ of comma-delimited disk indices (zero-based), e.g. 0,2 to replace only
the first and third disks.
The third form (when passing either the ``--iallocator`` or the
-``--new-secondary`` option) is designed to change secondary node of
-the instance. Specifying ``--iallocator`` makes the new secondary be
-selected automatically by the specified allocator plugin, otherwise
-the new secondary node will be the one chosen manually via the
-``--new-secondary`` option.
+``--new-secondary`` option) is designed to change secondary node of the
+instance. Specifying ``--iallocator`` makes the new secondary be
+selected automatically by the specified allocator plugin (use ``.`` to
+indicate the default allocator), otherwise the new secondary node will
+be the one chosen manually via the ``--new-secondary`` option.
Note that it is not possible to select an offline or drained node as a
new secondary.
@@ -1458,10 +1458,10 @@ passed must equal the number of nodes that the instance currently
has. Note that changing nodes is only allowed when all disks are
replaced, e.g. when no ``--disk`` option is passed.
-Another method of chosing which nodes to place the instance on is by
+Another method of choosing which nodes to place the instance on is by
using the specified iallocator, passing the ``--iallocator`` option.
The primary and secondary nodes will be chosen by the specified
-iallocator plugin.
+iallocator plugin, or by the default allocator if ``.`` is specified.
See **ganeti(7)** for a description of ``--submit`` and other common
options.
@@ -1535,6 +1535,8 @@ explicitly specify the target node (which can be any node) using the
``-n`` or ``--target-node`` option, or specify an iallocator plugin
using the ``-I`` or ``--iallocator`` option. If you omit both, the
default iallocator will be used to specify the target node.
+Alternatively, the default iallocator can be requested by specifying
+``.`` as the name of the plugin.
The migration command needs a perfectly healthy instance, as we rely
on the dual-master capability of drbd8 and the disks of the instance
diff --git a/man/gnt-node.rst b/man/gnt-node.rst
index 41eb1e0..885cfd7 100644
--- a/man/gnt-node.rst
+++ b/man/gnt-node.rst
@@ -112,8 +112,8 @@ The new location for the instances can be specified in two ways:
option
- or via the ``-I (--iallocator)`` option, giving a script name as
- parameter, so each instance will be in turn placed on the (per the
- script) optimal node
+ parameter (or ``.`` to use the default allocator), so each instance
+ will be in turn placed on the (per the script) optimal node
The ``--early-release`` changes the code so that the old storage on
node being evacuated is removed early (before the resync is
-- 1.7.7.3
> Check that at most one of (iallocator, node) is specified. If none is
> - specified, then the LU's opcode's iallocator slot is filled with the
> - cluster-wide default iallocator.
> + specified, or the iallocator is constants.DEFAULT_IALLOCATOR_SHORTCUT,
Please use L{} when referring to something in the code. It not only
makes it a link in the HTML output, but also complains if the name
goes away.
On Fri, Oct 05, 2012 at 07:07:40AM +0200, Bernardo Dal Seno wrote:
> Now "gnt-instance recreate-disks" uses the default iallocator when "." is
> specified as the iallocator. For uniformity, the same behavior applies to
> these commands:
> gnt-node evacuate
> gnt-instance migrate
> gnt-instance add
> "." is used instead of "default" becuse the latter could be a valid name for
> an iallocator
I would appreciate a cover letter on patch series.
Can you refresh my memory why we need this value instead of the default
iallocator always being enabled?
On Fri, Oct 5, 2012 at 8:23 PM, Iustin Pop <iu...@k1024.org> wrote:
> I would appreciate a cover letter on patch series.
Sorry, I thought it was short enough to be clear anyway. I will do one
next time.
> Can you refresh my memory why we need this value instead of the default
> iallocator always being enabled?
I'm not sure what you mean with the default iallocator always being
enabled. The problem with recreate-disks and replace-disks is that if
you don't specify an iallocator, no iallocator is used. And for
recreate-disks if you don't specify nodes nor iallocator the disks are
recreated on the same nodes, so the behavior used for example by
gnt-instance add (use the default iallocator if neither an iallocator
nor nodes are specified) is not good. Does this answer your question?
On Fri, Oct 05, 2012 at 10:24:56PM +0200, Bernardo Dal Seno wrote:
> On Fri, Oct 5, 2012 at 8:23 PM, Iustin Pop <iu...@k1024.org> wrote:
> > I would appreciate a cover letter on patch series.
> Sorry, I thought it was short enough to be clear anyway. I will do one
> next time.
It's not a issue; the reason I ask this is that without an explanation
why this change was made, in 1 year it will be unclear why we added this
code.
> > Can you refresh my memory why we need this value instead of the default
> > iallocator always being enabled?
> I'm not sure what you mean with the default iallocator always being
> enabled.
I meant, couldn't we treat a missing -t as "use the default ialloc" in
all commands? Like we already do in a few of them?
> The problem with recreate-disks and replace-disks is that if
> you don't specify an iallocator, no iallocator is used. And for
> recreate-disks if you don't specify nodes nor iallocator the disks are
> recreated on the same nodes, so the behavior used for example by
> gnt-instance add (use the default iallocator if neither an iallocator
> nor nodes are specified) is not good. Does this answer your question?
OK, so the problem is that if we enabled (no -t) to mean "use default",
it would not be possible to specify "keep same nodes" for
recreate-disks; for all other commands this is a correct behaviour.
This is the bit that was missing from the commit message, and that
should be in there for later investigation/archeology.
Furthermore, do I read the patch correctly that now "-t ." is required
to select the default IAllocator in commands that before did not require
it?
On Fri, Oct 5, 2012 at 11:59 PM, Iustin Pop <ius...@google.com> wrote:
> It's not a issue; the reason I ask this is that without an explanation
> why this change was made, in 1 year it will be unclear why we added this
> code.
But that explanation should go in the commits, not in the cover.
Unfortunately I've already pushed it. And more unfortunately, the 3rd
patch contains a stupid mistake. I'm waiting for QA before sending the
patch for review.
> I meant, couldn't we treat a missing -t as "use the default ialloc" in
> all commands? Like we already do in a few of them?
You mean -I, not -t.
> OK, so the problem is that if we enabled (no -t) to mean "use default",
> it would not be possible to specify "keep same nodes" for
> recreate-disks; for all other commands this is a correct behaviour.
Exactly.
> This is the bit that was missing from the commit message, and that
> should be in there for later investigation/archeology.
Any way to add it, beside having this conversation archived?
> Furthermore, do I read the patch correctly that now "-t ." is required
> to select the default IAllocator in commands that before did not require
> it?
Not required. The old behavior still exists, but I added this second
way of specify the default iallocator for uniformity among commands.
On Sat, Oct 06, 2012 at 12:11:48AM +0200, Bernardo Dal Seno wrote:
> On Fri, Oct 5, 2012 at 11:59 PM, Iustin Pop <ius...@google.com> wrote:
> > It's not a issue; the reason I ask this is that without an explanation
> > why this change was made, in 1 year it will be unclear why we added this
> > code.
> But that explanation should go in the commits, not in the cover.
What I meant is that even in cover is fine; in commits is of course much
better.
> Unfortunately I've already pushed it. And more unfortunately, the 3rd
> patch contains a stupid mistake. I'm waiting for QA before sending the
> patch for review.
Heh, no problem.
> > I meant, couldn't we treat a missing -t as "use the default ialloc" in
> > all commands? Like we already do in a few of them?
> You mean -I, not -t.
Indeed I do, thanks.
> > OK, so the problem is that if we enabled (no -t) to mean "use default",
> > it would not be possible to specify "keep same nodes" for
> > recreate-disks; for all other commands this is a correct behaviour.
> Exactly.
> > This is the bit that was missing from the commit message, and that
> > should be in there for later investigation/archeology.
> Any way to add it, beside having this conversation archived?
Nope. We don't have a "very small design changes doc" (which I was
thinking maybe we should, since there are a lot of design choices in the
Haskell code base I don't have where to document…)
> > Furthermore, do I read the patch correctly that now "-t ." is required
> > to select the default IAllocator in commands that before did not require
> > it?
> Not required. The old behavior still exists, but I added this second
> way of specify the default iallocator for uniformity among commands.
Excellent. I was fearing you wanted to make this required for
uniformity, but that (IMHO) would be bad from the UI point of view.