+def _get_node_counts(inventory):
+ """
+ Return numbers of controller and compute nodes in inventory
+
+ :param inventory: node inventory data structure
+ :return: number of controller and compute nodes in inventory
+ """
+ if not inventory:
+ raise ApexDeployException("Empty inventory")
+
+ nodes = inventory['nodes']
+ num_control = 0
+ num_compute = 0
+ for node in nodes:
+ if node['capabilities'] == 'profile:control':
+ num_control += 1
+ elif node['capabilities'] == 'profile:compute':
+ num_compute += 1
+ else:
+ # TODO(trozet) do we want to allow capabilities to not exist?
+ logging.error("Every node must include a 'capabilities' key "
+ "tagged with either 'profile:control' or "
+ "'profile:compute'")
+ raise ApexDeployException("Node missing capabilities "
+ "key: {}".format(node))
+ return num_control, num_compute
+
+