Revision 27579978 doc/examples/dumb-allocator

b/doc/examples/dumb-allocator
74 74
  request = data["request"]
75 75
  req_type = request["type"]
76 76
  if req_type != "allocate":
77
    print >> sys.stderr, "Unsupported allocator mode '%s'" % req_type
78
    return 1
79

  
80
  npri = SelectNode(nodes, request, [])
81
  if npri is None:
82
    return OutputError("Can't find a suitable primary node", exit_code=0)
83

  
84
  result_nodes = [npri]
85
  if request["disk_template"] == "drbd":
86
    nsec = SelectNode(nodes, request, result_nodes)
87
    if nsec is None:
88
      return OutputError("Can't find a suitable secondary node (%s selected"
89
                         " as primary)" % npri, exit_code=0)
90
    result_nodes.append(nsec)
77
    return OutputError("Unsupported allocator mode '%s'" % req_type)
78

  
79
  result_nodes = []
80
  while len(result_nodes) < request["required_nodes"]:
81
    new_selection = SelectNode(nodes, request, result_nodes)
82
    if new_selection is None:
83
      return OutputError("Can't find a suitable node for position %s"
84
                         " (already selected: %s)" %
85
                         (len(result_nodes) + 1, ", ".join(result_nodes)),
86
                         exit_code=0)
87
    result_nodes.append(new_selection)
91 88

  
92 89
  result = {
93 90
          "success": True,

Also available in: Unified diff