-
-class InventoryException(Exception):
- def __init__(self, value):
- self.value = value
-
- def __str__(self):
- return self.value
+ def get_node_counts(self):
+ """
+ Return numbers of controller and compute nodes in inventory
+ :param inventory: node inventory data structure
+ :return: number of controller and compute nodes in inventory
+ """
+ nodes = self['nodes']
+ num_control = 0
+ num_compute = 0
+ for node in nodes:
+ if 'profile:control' in node['capabilities']:
+ num_control += 1
+ elif 'profile:compute' in node['capabilities']:
+ num_compute += 1
+ else:
+ raise ApexInventoryException("Node missing capabilities "
+ "key: {}".format(node))
+ return num_control, num_compute
+
+
+class ApexInventoryException(Exception):
+ pass