def _process_node_groups(self, template_json=None, cluster=None):
        # get node_groups from config
        if template_json and not cluster:
            for group in template_json['host_role_mappings']:
                node_group = NodeGroup(group['name'])
                for component in group['components']:
                    node_group.add_component(component['name'])
                for host in group['hosts']:
                    if 'predicate' in host:
                        node_group.predicate = host['predicate']
                    if 'cardinality' in host:
                        node_group.cardinality = host['cardinality']
                    if 'default_count' in host:
                        node_group.count = host['default_count']
                self.node_groups[node_group.name] = node_group

        if cluster:
            self.node_groups = {}
            node_groups = cluster.node_groups
            for ng in node_groups:
                node_group = NodeGroup(ng.name)
                node_group.count = ng.count
                node_group.id = ng.id
                node_group.components = ng.node_processes[:]
                for instance in ng.instances:
                    node_group.instances.add(Instance(instance))
                self.node_groups[node_group.name] = node_group
dataset/ETHPy150Open openstack/sahara/sahara/plugins/hdp/clusterspec.py/ClusterSpec._process_node_groups/original