Revision 20fb929a lib/watcher/__init__.py

b/lib/watcher/__init__.py
643 643
  return constants.EXIT_SUCCESS
644 644

  
645 645

  
646
def _GetAllNodesInGroup(qcl, uuid):
647
  """Get all nodes of a node group.
648

  
649
  This function uses the query client to find out which nodes are in the node
650
  group.
651

  
652
  @type qcl: @C{luxi.Client}
653
  @param qcl: luxi client for queries
654
  @type uuid: string
655
  @param uuid: UUID of the node group
656

  
657
  """
658
  what = constants.QR_NODE
659
  fields = ["name", "bootid", "offline"]
660
  qfilter = [qlang.OP_EQUAL, "group.uuid", uuid]
661

  
662
  result = qcl.Query(what, fields, qfilter)
663
  return result
664

  
665

  
666
def _GetGroupData(cl, qcl, uuid):
646
def _GetGroupData(qcl, uuid):
667 647
  """Retrieves instances and nodes per node group.
668 648

  
669 649
  """
670
  # FIXME: This is an intermediate state where some queries are done via
671
  # the old and some via the new query implementation. This will be beautiful
672
  # again when the transition is complete for all queries.
673
  node_result = _GetAllNodesInGroup(qcl, uuid)
674

  
675
  job = [
676
    # Get all primary instances in group
677
    opcodes.OpQuery(what=constants.QR_INSTANCE,
678
                    fields=["name", "status", "disks_active", "snodes",
679
                            "pnode.group.uuid", "snodes.group.uuid"],
680
                    qfilter=[qlang.OP_EQUAL, "pnode.group.uuid", uuid],
681
                    use_locking=True)
682
    ]
683
  job_id = cl.SubmitJob(job)
684
  results = map(objects.QueryResponse.FromDict,
685
                cli.PollJob(job_id, cl=cl, feedback_fn=logging.debug))
686
  results.append(node_result)
687
  cl.ArchiveJob(job_id)
650
  queries = [
651
      (constants.QR_INSTANCE,
652
       ["name", "status", "disks_active", "snodes",
653
        "pnode.group.uuid", "snodes.group.uuid"],
654
       [qlang.OP_EQUAL, "pnode.group.uuid", uuid]),
655
      (constants.QR_NODE,
656
       ["name", "bootid", "offline"],
657
       [qlang.OP_EQUAL, "group.uuid", uuid]),
658
      ]
659

  
660
  results = []
661
  for what, fields, qfilter in queries:
662
    results.append(qcl.Query(what, fields, qfilter))
688 663

  
689 664
  results_data = map(operator.attrgetter("data"), results)
690 665

  
......
775 750

  
776 751
    _CheckMaster(client)
777 752

  
778
    (nodes, instances) = _GetGroupData(client, query_client, group_uuid)
753
    (nodes, instances) = _GetGroupData(query_client, group_uuid)
779 754

  
780 755
    # Update per-group instance status file
781 756
    _UpdateInstanceStatus(inst_status_path, instances.values())

Also available in: Unified diff