def build_node_data_bag(): """Tells LittleChef to build the node data bag""" current_dir = os.getcwd() os.chdir(KITCHEN_DIR) try: lib.get_recipes() # This builds metadata.json for all recipes chef.build_node_data_bag() except SystemExit as e: log.error(e) finally: os.chdir(current_dir) return True
def _build_node_data_bag(): """Builds one 'node' data bag item per file found in the 'nodes' directory Automatic attributes for a node item: 'id': It adds data bag 'id', same as filename but with underscores 'name': same as the filename 'fqdn': same as the filename (LittleChef filenames should be fqdns) 'hostname': Uses the first part of the filename as the hostname (until it finds a period) minus the .json extension 'domain': filename minus the first part of the filename (hostname) minus the .json extension In addition, it will contain the merged attributes from: All default cookbook attributes corresponding to the node All attributes found in nodes/<item>.json file Default and override attributes from all roles Returns the node object of the node which is about to be configured, or None if this node object cannot be found. """ current_node = None nodes = lib.get_nodes() node_data_bag_path = os.path.join('data_bags', 'node') # In case there are leftovers _remove_local_node_data_bag() os.makedirs(node_data_bag_path) all_recipes = lib.get_recipes() all_roles = lib.get_roles() for node in nodes: # Dots are not allowed (only alphanumeric), substitute by underscores node['id'] = node['name'].replace('.', '_') # Build extended role list node['role'] = lib.get_roles_in_node(node) node['roles'] = node['role'][:] for role in node['role']: node['roles'].extend(lib.get_roles_in_role(role)) node['roles'] = list(set(node['roles'])) # Build extended recipe list node['recipes'] = lib.get_recipes_in_node(node) # Add recipes found inside each roles in the extended role list for role in node['roles']: node['recipes'].extend(lib.get_recipes_in_role(role)) node['recipes'] = list(set(node['recipes'])) # Add node attributes _add_merged_attributes(node, all_recipes, all_roles) _add_automatic_attributes(node) # Save node data bag item with open( os.path.join('data_bags', 'node', node['id'] + '.json'), 'w') as f: f.write(json.dumps(node)) if node['name'] == env.host_string: current_node = node return current_node
def test_list_recipes(self): recipes = lib.get_recipes() self.assertEquals(len(recipes), 6) self.assertEquals(recipes[1]["name"], "subversion") self.assertEquals(recipes[1]["description"], "Includes the client recipe. Modified by site-cookbooks") self.assertEquals(recipes[2]["name"], "subversion::client") self.assertEquals(recipes[2]["description"], "Subversion Client installs subversion and some extra svn libs") self.assertEquals(recipes[3]["name"], "subversion::server") self.assertIn("subversion::testrecipe", [r["name"] for r in recipes])
def _build_node_data_bag(): """Builds one 'node' data bag item per file found in the 'nodes' directory Automatic attributes for a node item: 'id': It adds data bag 'id', same as filename but with underscores 'name': same as the filename 'fqdn': same as the filename (LittleChef filenames should be fqdns) 'hostname': Uses the first part of the filename as the hostname (until it finds a period) minus the .json extension 'domain': filename minus the first part of the filename (hostname) minus the .json extension In addition, it will contain the merged attributes from: All default cookbook attributes corresponding to the node All attributes found in nodes/<item>.json file Default and override attributes from all roles Returns the node object of the node which is about to be configured, or None if this node object cannot be found. """ current_node = None nodes = lib.get_nodes() node_data_bag_path = os.path.join('data_bags', 'node') # In case there are leftovers _remove_local_node_data_bag() os.makedirs(node_data_bag_path) all_recipes = lib.get_recipes() all_roles = lib.get_roles() for node in nodes: # Dots are not allowed (only alphanumeric), substitute by underscores node['id'] = node['name'].replace('.', '_') # Build extended role list node['role'] = lib.get_roles_in_node(node) node['roles'] = node['role'][:] for role in node['role']: node['roles'].extend(lib.get_roles_in_role(role)) node['roles'] = list(set(node['roles'])) # Build extended recipe list node['recipes'] = lib.get_recipes_in_node(node) # Add recipes found inside each roles in the extended role list for role in node['roles']: node['recipes'].extend(lib.get_recipes_in_role(role)) node['recipes'] = list(set(node['recipes'])) # Add node attributes _add_merged_attributes(node, all_recipes, all_roles) _add_automatic_attributes(node) # Save node data bag item with open(os.path.join( 'data_bags', 'node', node['id'] + '.json'), 'w') as f: f.write(json.dumps(node)) if node['name'] == env.host_string: current_node = node return current_node
def test_list_recipes(self): recipes = lib.get_recipes() self.assertEquals(len(recipes), 5) self.assertEquals(recipes[1]['name'], 'subversion') self.assertEquals(recipes[1]['description'], 'Includes the client recipe. Modified by site-cookbooks') self.assertEquals(recipes[2]['name'], 'subversion::client') self.assertEquals(recipes[2]['description'], 'Subversion Client installs subversion and some extra svn libs') self.assertEquals(recipes[3]['name'], 'subversion::server')
def test_list_recipes(self): recipes = lib.get_recipes() self.assertEquals(len(recipes), 5) self.assertEquals(recipes[1]['name'], 'subversion') self.assertEquals( recipes[1]['description'], 'Includes the client recipe. Modified by site-cookbooks') self.assertEquals(recipes[2]['name'], 'subversion::client') self.assertEquals( recipes[2]['description'], 'Subversion Client installs subversion and some extra svn libs') self.assertEquals(recipes[3]['name'], 'subversion::server')
def _build_node_data_bag(): """Builds one 'node' data bag item per file found in the 'nodes' directory Attributes for a node item: 'id': It adds data bag 'id' using the first part of the filename (until it finds a period) minus the .json extension 'name': same as the filename 'fqdn': same as the filename (as LittleChef filenames should be fqdns) 'hostname': same as the filename all attributes found in nodes/<item>.json file Returns the node object of the node which is about to be configured, or None if this node object cannot be found. """ current_node = None nodes = lib.get_nodes() node_data_bag_path = os.path.join('data_bags', 'node') _remove_node_data_bag() os.makedirs(node_data_bag_path) all_recipes = lib.get_recipes() all_roles = lib.get_roles() for node in nodes: node['id'] = node['name'].split('.')[0] # Build extended role list node['role'] = lib.get_roles_in_node(node) node['roles'] = node['role'][:] for role in node['role']: node['roles'].extend(lib.get_roles_in_role(role)) node['roles'] = list(set(node['roles'])) # Build extended recipe list node['recipes'] = lib.get_recipes_in_node(node) # Add recipes found inside each roles in the extended role list for role in node['roles']: node['recipes'].extend(lib.get_recipes_in_role(role)) node['recipes'] = list(set(node['recipes'])) # Add node attributes _add_merged_attributes(node, all_recipes, all_roles) _add_automatic_attributes(node) # Save node data bag item with open(os.path.join( 'data_bags', 'node', node['id'] + '.json'), 'w') as f: f.write(json.dumps(node)) if node['name'] == env.host_string: current_node = node return current_node
def build_node_data_bag(): """Builds one 'node' data bag item per file found in the 'nodes' directory Automatic attributes for a node item: 'id': It adds data bag 'id', same as filename but with underscores 'name': same as the filename 'fqdn': same as the filename (LittleChef filenames should be fqdns) 'hostname': Uses the first part of the filename as the hostname (until it finds a period) minus the .json extension 'domain': filename minus the first part of the filename (hostname) minus the .json extension In addition, it will contain the merged attributes from: All default cookbook attributes corresponding to the node All attributes found in nodes/<item>.json file Default and override attributes from all roles """ nodes = lib.get_nodes() node_data_bag_path = os.path.join("data_bags", "node") # In case there are leftovers remove_local_node_data_bag() os.makedirs(node_data_bag_path) all_recipes = lib.get_recipes() all_roles = lib.get_roles() for node in nodes: # Dots are not allowed (only alphanumeric), substitute by underscores node["id"] = node["name"].replace(".", "_") # Build extended role list node["role"] = lib.get_roles_in_node(node) node["roles"] = node["role"][:] for role in node["role"]: node["roles"].extend(lib.get_roles_in_role(role)) node["roles"] = list(set(node["roles"])) # Build extended recipe list node["recipes"] = lib.get_recipes_in_node(node) # Add recipes found inside each roles in the extended role list for role in node["roles"]: node["recipes"].extend(lib.get_recipes_in_role(role)) node["recipes"] = list(set(node["recipes"])) # Add node attributes _add_merged_attributes(node, all_recipes, all_roles) _add_automatic_attributes(node) # Save node data bag item with open(os.path.join("data_bags", "node", node["id"] + ".json"), "w") as f: f.write(json.dumps(node))
def list_recipes_detailed(): """Show detailed information for all recipes""" for recipe in lib.get_recipes(): lib.print_recipe(recipe)
def list_recipes(): """Show a list of all available recipes""" for recipe in lib.get_recipes(): margin_left = lib.get_margin(len(recipe['name'])) print("{0}{1}{2}".format( recipe['name'], margin_left, recipe['description']))
def list_recipes(): """Show a list of all available recipes""" for recipe in lib.get_recipes(): margin_left = lib.get_margin(len(recipe['name'])) print("{0}{1}{2}".format(recipe['name'], margin_left, recipe['description']))