Commit 6f547f96 authored by Guido Trotter's avatar Guido Trotter
Browse files

Remove dumb-allocator



- Remove the actual code
- Remove mentions of it from iallocator.rst, and use hail instead
- Also remove mentions of "etch-image" and use "debootstrap+default"
- Mention htools as the reference implementation in iallocator.rst
Signed-off-by: default avatarGuido Trotter <ultrotter@google.com>
Reviewed-by: default avatarRené Nussbaumer <rn@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent e1ab08db
......@@ -402,7 +402,6 @@ EXTRA_DIST = \
doc/examples/ganeti-kvm-poweroff.initd.in \
doc/examples/ganeti.cron.in \
doc/examples/gnt-config-backup.in \
doc/examples/dumb-allocator \
doc/examples/ganeti.default \
doc/examples/ganeti.default-debug \
doc/examples/hooks/ethers \
......
#!/usr/bin/python
#
# Copyright (C) 2008 Google Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
"""Simple first-fit allocator for ganeti instance allocation framework.
This allocator just iterates over the nodes and selects the first one
that fits in both memory and disk space, without any consideration for
equal spread or VCPU oversubscription.
"""
import simplejson
import sys
def SelectNode(nodes, request, to_skip):
"""Select a node for the given instance
"""
disk_size = request["disk_space_total"]
selected = None
for nname, ninfo in nodes.iteritems():
if nname in to_skip:
continue
if request["memory"] > ninfo["free_memory"]:
continue
if disk_size > ninfo["free_disk"]:
continue
selected = nname
break
return selected
def OutputError(text, exit_code=1):
"""Builds an error response with a given info message.
"""
error = {
"success": False,
"info": text,
"nodes": [],
}
print simplejson.dumps(error, indent=2)
return exit_code
def main():
"""Main function.
"""
if len(sys.argv) < 2:
print >> sys.stderr, "Usage: %s cluster.json" % (sys.argv[0])
return 1
data = simplejson.load(open(sys.argv[1]))
nodes = data["nodes"]
request = data["request"]
req_type = request["type"]
offline_nodes = [name for name in nodes if nodes[name]["offline"]]
drained_nodes = [name for name in nodes if nodes[name]["offline"]]
if req_type == "allocate":
forbidden_nodes = offline_nodes + drained_nodes
inst_data = request
elif req_type == "relocate":
idict = data["instances"][request["name"]]
forbidden_nodes = idict["nodes"] + offline_nodes + drained_nodes
inst_data = idict
inst_data["disk_space_total"] = request["disk_space_total"]
else:
return OutputError("Unsupported allocator mode '%s'" % req_type)
result_nodes = []
while len(result_nodes) < request["required_nodes"]:
new_selection = SelectNode(nodes, inst_data, result_nodes+forbidden_nodes)
if new_selection is None:
return OutputError("Can't find a suitable node for position %s"
" (already selected: %s)" %
(len(result_nodes) + 1, ", ".join(result_nodes)),
exit_code=0)
result_nodes.append(new_selection)
result = {
"success": True,
"info": "Allocation successful",
"nodes": result_nodes,
}
print simplejson.dumps(result, indent=2)
return 0
if __name__ == "__main__":
sys.exit(main())
......@@ -322,7 +322,7 @@ Input message, new instance allocation::
"disk_template": "drbd",
"memory": 2048,
"disk_space_total": 3328,
"os": "etch-image"
"os": "debootstrap+default"
},
"cluster_name": "cluster1.example.com",
"instances": {
......@@ -352,7 +352,7 @@ Input message, new instance allocation::
"nodes": [
"nodee1.com"
],
"os": "etch-image"
"os": "debootstrap+default"
},
"instance2.example.com": {
"tags": [],
......@@ -381,7 +381,7 @@ Input message, new instance allocation::
"node2.example.com",
"node3.example.com"
],
"os": "etch-image"
"os": "debootstrap+default"
}
},
"version": 1,
......@@ -483,18 +483,26 @@ Command line messages
~~~~~~~~~~~~~~~~~~~~~
::
# gnt-instance add -t plain -m 2g --os-size 1g --swap-size 512m --iallocator dumb-allocator -o etch-image instance3
# gnt-instance add -t plain -m 2g --os-size 1g --swap-size 512m --iallocator hail -o debootstrap+default instance3
Selected nodes for the instance: node1.example.com
* creating instance disks...
[...]
# gnt-instance add -t plain -m 3400m --os-size 1g --swap-size 512m --iallocator dumb-allocator -o etch-image instance4
# gnt-instance add -t plain -m 3400m --os-size 1g --swap-size 512m --iallocator hail -o debootstrap+default instance4
Failure: prerequisites not met for this operation:
Can't compute nodes using iallocator 'dumb-allocator': Can't find a suitable node for position 1 (already selected: )
Can't compute nodes using iallocator 'hail': Can't find a suitable node for position 1 (already selected: )
# gnt-instance add -t drbd -m 1400m --os-size 1g --swap-size 512m --iallocator dumb-allocator -o etch-image instance5
# gnt-instance add -t drbd -m 1400m --os-size 1g --swap-size 512m --iallocator hail -o debootstrap+default instance5
Failure: prerequisites not met for this operation:
Can't compute nodes using iallocator 'dumb-allocator': Can't find a suitable node for position 2 (already selected: node1.example.com)
Can't compute nodes using iallocator 'hail': Can't find a suitable node for position 2 (already selected: node1.example.com)
Reference implementation
~~~~~~~~~~~~~~~~~~~~~~~~
Ganeti's default iallocator is "hail" which is part of the separate
ganeti-htools project. In order to see its source code please clone
``git://git.ganeti.org/htools.git``. Note that htools is implemented
using the Haskell programming language.
.. vim: set textwidth=72 :
.. Local Variables:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment