def retrieve_nodegroup(nodegroup, element, configmanager, inputdata): grpcfg = configmanager.get_nodegroup_attributes(nodegroup) if element == 'all': nodes = [] if 'nodes' in grpcfg: nodes = list(grpcfg['nodes']) yield msg.ListAttributes(kv={'nodes': nodes}, desc="The nodes belonging to this group") for attribute in sorted(allattributes.node.iterkeys()): if attribute == 'groups': continue if attribute in grpcfg: val = grpcfg[attribute] else: val = {'value': None} if attribute.startswith('secret.'): yield msg.CryptedAttributes( kv={attribute: val}, desc=allattributes.node[attribute]['description']) elif isinstance(val, list): raise Exception("TODO") else: yield msg.Attributes( kv={attribute: val}, desc=allattributes.node[attribute]['description']) if element == 'current': for attribute in sorted(grpcfg.iterkeys()): currattr = grpcfg[attribute] if attribute == 'nodes': desc = 'The nodes belonging to this group' elif attribute == 'noderange': desc = 'A dynamic noderange that this group refers to in noderange expansion' else: try: desc = allattributes.node[attribute]['description'] except KeyError: desc = 'Unknown' if 'value' in currattr or 'expression' in currattr: yield msg.Attributes(kv={attribute: currattr}, desc=desc) elif 'cryptvalue' in currattr: yield msg.CryptedAttributes( kv={attribute: currattr}, desc=desc) elif isinstance(currattr, set): yield msg.ListAttributes( kv={attribute: list(currattr)}, desc=desc) elif isinstance(currattr, list): yield msg.ListAttributes( kv={attribute: currattr}, desc=desc) else: print attribute print repr(currattr) raise Exception("BUGGY ATTRIBUTE FOR NODEGROUP")
def retrieve_nodes(nodes, element, configmanager, inputdata): attributes = configmanager.get_node_attributes(nodes) if element[-1] == 'all': for node in util.natural_sort(nodes): theattrs = set(allattributes.node).union(set(attributes[node])) for attribute in sorted(theattrs): if attribute in attributes[node]: # have a setting for it val = attributes[node][attribute] elif attribute == 'groups': # no setting, provide a blank val = [] else: # no setting, provide a blank val = {'value': None} if attribute.startswith('secret.') or attribute.startswith( 'crypted.'): yield msg.CryptedAttributes( node, {attribute: val}, allattributes.node.get(attribute, {}).get('description', '')) elif isinstance(val, list): yield msg.ListAttributes( node, {attribute: val}, allattributes.node.get(attribute, {}).get('description', '')) else: yield msg.Attributes( node, {attribute: val}, allattributes.node.get(attribute, {}).get('description', '')) elif element[-1] == 'current': for node in util.natural_sort(list(attributes)): for attribute in sorted(attributes[node]): currattr = attributes[node][attribute] try: desc = allattributes.node[attribute]['description'] except KeyError: desc = '' if 'value' in currattr or 'expression' in currattr: yield msg.Attributes(node, {attribute: currattr}, desc) elif 'cryptvalue' in currattr or 'hashvalue' in currattr: yield msg.CryptedAttributes(node, {attribute: currattr}, desc) elif isinstance(currattr, list): yield msg.ListAttributes(node, {attribute: currattr}, desc) else: print(attribute) print(repr(currattr)) raise Exception("BUGGY ATTRIBUTE FOR NODE")
def retrieve_nodes(nodes, element, configmanager, inputdata): attributes = configmanager.get_node_attributes(nodes) if element[-1] == 'all': for node in nodes: for attribute in sorted(allattributes.node.iterkeys()): if attribute in attributes[node]: # have a setting for it val = attributes[node][attribute] elif attribute == 'groups': # no setting, provide a blank val = [] else: # no setting, provide a blank val = {'value': None} if attribute.startswith('secret.'): yield msg.CryptedAttributes( node, {attribute: val}, allattributes.node[attribute]['description']) elif isinstance(val, list): yield msg.ListAttributes( node, {attribute: val}, allattributes.node[attribute]['description']) else: yield msg.Attributes( node, {attribute: val}, allattributes.node[attribute]['description']) elif element[-1] == 'current': for node in attributes.iterkeys(): for attribute in sorted(attributes[node].iterkeys()): currattr = attributes[node][attribute] try: desc = allattributes.node[attribute]['description'] except KeyError: desc = 'Unknown' if 'value' in currattr or 'expression' in currattr: yield msg.Attributes(node, {attribute: currattr}, desc) elif 'cryptvalue' in currattr: yield msg.CryptedAttributes( node, {attribute: currattr}, desc) elif isinstance(currattr, list): yield msg.ListAttributes( node, {attribute: currattr}, desc) else: print attribute print repr(currattr) raise Exception("BUGGY ATTRIBUTE FOR NODE")
def retrieve_nodegroup(nodegroup, element, configmanager, inputdata): try: grpcfg = configmanager.get_nodegroup_attributes(nodegroup) except KeyError: if not configmanager.is_nodegroup(nodegroup): raise exc.NotFoundException( 'Invalid nodegroup: {0} not found'.format(nodegroup)) raise if element == 'all': theattrs = set(allattributes.node).union(set(grpcfg)) theattrs.add('nodes') for attribute in sorted(theattrs): if attribute == 'groups': continue if attribute == 'nodes': yield msg.ListAttributes( kv={'nodes': list(grpcfg.get('nodes', []))}, desc="The nodes belonging to this group") continue if attribute in grpcfg: val = grpcfg[attribute] else: val = {'value': None} if attribute.startswith('secret.'): yield msg.CryptedAttributes( kv={attribute: val}, desc=allattributes.node[attribute]['description']) elif isinstance(val, list): yield msg.ListAttributes(kv={attribute: val}, desc=allattributes.node.get( attribute, {}).get('description', '')) else: yield msg.Attributes(kv={attribute: val}, desc=allattributes.node.get( attribute, {}).get('description', '')) if element == 'current': for attribute in sorted(list(grpcfg)): currattr = grpcfg[attribute] if attribute == 'nodes': desc = 'The nodes belonging to this group' elif attribute == 'noderange': desc = 'A dynamic noderange that this group refers to in noderange expansion' else: try: desc = allattributes.node[attribute]['description'] except KeyError: desc = '' if 'value' in currattr or 'expression' in currattr: yield msg.Attributes(kv={attribute: currattr}, desc=desc) elif 'cryptvalue' in currattr: yield msg.CryptedAttributes(kv={attribute: currattr}, desc=desc) elif isinstance(currattr, set): yield msg.ListAttributes(kv={attribute: list(currattr)}, desc=desc) elif isinstance(currattr, list): yield msg.ListAttributes(kv={attribute: currattr}, desc=desc) else: print attribute print repr(currattr) raise Exception("BUGGY ATTRIBUTE FOR NODEGROUP")