コード例 #1
0
ファイル: test_lib.py プロジェクト: cocoy/littlechef
 def test_get_nodes(self):
     """Should return all configured nodes"""
     expected = [
         {
             'name': 'testnode1',
             'chef_environment': 'production',
             'run_list': ['recipe[subversion]']
         },
         {
             'chef_environment': 'staging',
             'name': 'testnode2',
             'other_attr': {
                 'deep_dict': {
                     'deep_key1': 'node_value1'
                 }
             },
             'subversion': {
                 'password': '******',
                 'user': '******'
             },
             'run_list': ['role[all_you_can_eat]']
         },
         {
             'name': 'testnode3.mydomain.com',
             "chef_environment": "production",
             'run_list': ['recipe[subversion]', 'recipe[vim]']
         },
     ]
     self.assertEquals(lib.get_nodes(), expected)
コード例 #2
0
ファイル: runner.py プロジェクト: abrookins/littlechef
def get_ips():
    """Ping all nodes and update their 'ipaddress' field"""
    import subprocess
    for node in lib.get_nodes():
        # For each node, ping the hostname
        env.host_string = node['name']
        proc = subprocess.Popen(['ping', '-c', '1', node['name']],
                    stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        resp, error = proc.communicate()
        if not error:
            # Get lines from output and parse the first line to get the IP
            lines = resp.split("\n")
            # IP Address Regex http://www.regular-expressions.info/examples.html
            ip_matches = re.findall(r'\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b', lines[0])
            ip = ip_matches[0] if ip_matches else None
            if not ip:
                print "Warning: could not get IP address from node {0}".format(
                    node['name'])
                continue
            print "Node {0} has IP {1}".format(node['name'], ip)
            # Update with the ipaddress field in the corresponding node.json
            del node['name']
            node['ipaddress'] = ip
            os.remove(chef.save_config(node, ip))
        else:
            print "Warning: could not resolve node {0}".format(node['name'])
コード例 #3
0
def node(*nodes):
    """Selects and configures a list of nodes. 'all' configures all nodes"""
    chef.build_node_data_bag()
    if not len(nodes) or nodes[0] == '':
        abort('No node was given')
    elif nodes[0] == 'all':
        # Fetch all nodes and add them to env.hosts
        for node in lib.get_nodes(env.chef_environment):
            env.hosts.append(node['name'])
        if not len(env.hosts):
            abort('No nodes found in /nodes/')
        message = "Are you sure you want to configure all nodes ({0})".format(
            len(env.hosts))
        if env.chef_environment:
            message += " in the {0} environment".format(env.chef_environment)
        message += "?"
        if not __testing__:
            if not lib.global_confirm(message):
                abort('Aborted by user')
    else:
        # A list of nodes was given
        env.hosts = list(nodes)
    env.all_hosts = list(env.hosts)  # Shouldn't be needed

    # Check whether another command was given in addition to "node:"
    if not (littlechef.__cooking__ and 'node:' not in sys.argv[-1]
            and 'nodes_with_role:' not in sys.argv[-1]):
        # If user didn't type recipe:X, role:Y or deploy_chef,
        # configure the nodes
        with settings():
            execute(_node_runner)
        chef.remove_local_node_data_bag()
コード例 #4
0
def node(*nodes):
    """Selects and configures a list of nodes. 'all' configures all nodes"""
    chef.build_node_data_bag()
    if not len(nodes) or nodes[0] == '':
        abort('No node was given')
    elif nodes[0] == 'all':
        # Fetch all nodes and add them to env.hosts
        for node in lib.get_nodes(env.chef_environment):
            env.hosts.append(node['name'])
        if not len(env.hosts):
            abort('No nodes found in /nodes/')
        message = "Are you sure you want to configure all nodes ({0})".format(
            len(env.hosts))
        if env.chef_environment:
            message += " in the {0} environment".format(env.chef_environment)
        message += "?"
        if not __testing__:
            if not lib.global_confirm(message):
                abort('Aborted by user')
    else:
        # A list of nodes was given
        env.hosts = list(nodes)
    env.all_hosts = list(env.hosts)  # Shouldn't be needed

    # Check whether another command was given in addition to "node:"
    if not(littlechef.__cooking__ and
            'node:' not in sys.argv[-1] and
            'nodes_with_role:' not in sys.argv[-1]):
        # If user didn't type recipe:X, role:Y or deploy_chef,
        # configure the nodes
        with settings():
            execute(_node_runner)
        chef.remove_local_node_data_bag()
コード例 #5
0
ファイル: test_lib.py プロジェクト: MrTomato8/littlechef
 def test_get_nodes(self):
     """Should return all configured nodes when no environment is given"""
     found_nodes = lib.get_nodes()
     self.assertEqual(len(found_nodes), len(self.nodes))
     expected_keys = ['name', 'chef_environment', 'run_list']
     for node in found_nodes:
         self.assertTrue(all([key in node for key in expected_keys]))
コード例 #6
0
ファイル: test_lib.py プロジェクト: n2uitive/littlechef
 def test_get_nodes(self):
     """Should return all configured nodes when no environment is given"""
     found_nodes = lib.get_nodes()
     self.assertEqual(len(found_nodes), len(self.nodes))
     expected_keys = ['name', 'chef_environment', 'run_list']
     for node in found_nodes:
         self.assertTrue(all([key in node for key in expected_keys]))
コード例 #7
0
ファイル: test_lib.py プロジェクト: bicherele/littlechef
 def test_get_nodes(self):
     """Should return all configured nodes"""
     expected = [
         {
             'name': 'testnode1',
             'chef_environment': 'production',
             'run_list': ['recipe[subversion]']
         },
         {
             'chef_environment': 'staging', 'name': 'testnode2',
             'other_attr': {'deep_dict': {'deep_key1': 'node_value1'}},
             'subversion': {
                 'password': '******', 'user': '******'
             },
             'run_list': ['role[all_you_can_eat]']
         },
         {
             'name': 'testnode3.mydomain.com',
             "chef_environment": "production",
             'run_list': ['recipe[subversion]', 'recipe[vim]']
         },
         {
             'dummy': True,
             'chef_environment': 'production',
             'name': 'testnode4',
             'run_list': ['recipe[man]']
         },
     ]
     self.assertEquals(lib.get_nodes(), expected)
コード例 #8
0
ファイル: runner.py プロジェクト: uggedal/littlechef
def node(*nodes):
    """Selects and configures a list of nodes. 'all' configures all nodes"""
    if not len(nodes) or nodes[0] == '':
        abort('No node was given')
    elif nodes[0] == 'all':
        # Fetch all nodes and add them to env.hosts
        for node in lib.get_nodes():
            env.hosts.append(node['name'])
        if not len(env.hosts):
            abort('No nodes found in /nodes/')
    else:
        # A list of nodes was given
        env.hosts = nodes
    env.all_hosts = list(env.hosts)

    # Check whether another command was given in addition to "node:"
    execute = True
    if 'node:' not in sys.argv[-1]:
        execute = False
    # If user didn't type recipe:X, role:Y or deploy_chef, just run configure
    if execute:
        for hostname in env.hosts:
            env.host = hostname
            env.host_string = hostname
            lib.print_header("Configuring {0}".format(env.host))
            # Read node data and configure node
            node = lib.get_node(env.host)
            chef.sync_node(node)
コード例 #9
0
ファイル: chef.py プロジェクト: paneq/littlechef
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
コード例 #10
0
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
コード例 #11
0
ファイル: runner.py プロジェクト: sirlantis/littlechef
def node(host):
    """Select a node"""
    if host == "all":
        for node in lib.get_nodes():
            env.hosts.append(node["name"])
        if not len(env.hosts):
            abort("No nodes found")
    else:
        env.hosts = [host]
コード例 #12
0
def node(host):
    """Select a node"""
    if host == 'all':
        for node in lib.get_nodes():
            env.hosts.append(node['name'])
        if not len(env.hosts):
            abort('No nodes found')
    else:
        env.hosts = [host]
コード例 #13
0
ファイル: runner.py プロジェクト: VanL/littlechef
def node(host):
    """Select a node"""
    if host == 'all':
        for node in lib.get_nodes():
            env.hosts.append(node['name'])
        if not len(env.hosts):
            abort('No nodes found')
    else:
        env.hosts = [host]
コード例 #14
0
ファイル: test_lib.py プロジェクト: uggedal/littlechef
    def test_list_nodes(self):
        """Should list all configured nodes"""
        expected = [
            {'name': 'testnode1', 'run_list': ['recipe[subversion]']},
            {'name': 'testnode2',
                'subversion': {'password': '******', 'user': '******'},
                'run_list': ['role[all_you_can_eat]']},
            {'name': 'testnode3.mydomain.com', 'run_list': ['recipe[subversion]']},
        ]

        self.assertEquals(lib.get_nodes(), expected)
コード例 #15
0
ファイル: runner.py プロジェクト: pombredanne/littlechef
def list_nodes_with_recipe(recipe):
    """Show all nodes which have asigned a given recipe"""
    for node in lib.get_nodes():
        if recipe in lib.get_recipes_in_node(node):
            lib.print_node(node)
        else:
            for role in lib.get_roles_in_node(node):
                with open('roles/' + role + '.json', 'r') as f:
                    roles = json.loads(f.read())
                    # Reuse _get_recipes_in_node to extract recipes in a role
                    if recipe in lib.get_recipes_in_node(roles):
                        lib.print_node(node)
                        break
コード例 #16
0
def list_nodes_with_recipe(recipe):
    """Show all nodes which have asigned a given recipe"""
    for node in lib.get_nodes():
        if recipe in lib.get_recipes_in_node(node):
            lib.print_node(node)
        else:
            for role in lib.get_roles_in_node(node):
                with open('roles/' + role + '.json', 'r') as f:
                    roles = json.loads(f.read())
                    # Reuse _get_recipes_in_node to extract recipes in a role
                    if recipe in lib.get_recipes_in_node(roles):
                        lib.print_node(node)
                        break
コード例 #17
0
ファイル: chef.py プロジェクト: uggedal/littlechef
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
コード例 #18
0
ファイル: chef.py プロジェクト: bnikolaus/littlechef
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))
コード例 #19
0
ファイル: runner.py プロジェクト: wamcvey/littlechef
def node(*nodes):
    """Selects and configures a list of nodes. 'all' configures all nodes"""
    if not len(nodes) or nodes[0] == '':
        abort('No node was given')
    elif nodes[0] == 'all':
        # Fetch all nodes and add them to env.hosts
        for node in lib.get_nodes(env.chef_environment):
            env.hosts.append(node['name'])
        if not len(env.hosts):
            abort('No nodes found in /nodes/')
        message = "Are you sure you want to configure all nodes ({0})".format(
            len(env.hosts))
        if env.chef_environment:
            message += " in the {0} environment".format(env.chef_environment)
        message += "?"
        if not __testing__:
            if not confirm(message):
                abort('Aborted by user')
    else:
        # A list of nodes was given
        env.hosts = list(nodes)
    env.all_hosts = list(env.hosts)  # Shouldn't be needed
    if len(env.hosts) > 1:
        print "Configuring nodes: {0}...".format(", ".join(env.hosts))

    # Check whether another command was given in addition to "node:"
    execute = True
    if not(littlechef.__cooking__ and
            'node:' not in sys.argv[-1] and
            'nodes_with_role:' not in sys.argv[-1]):
        # If user didn't type recipe:X, role:Y or deploy_chef,
        # configure the nodes
        for hostname in env.hosts:
            env.host = hostname
            env.host_string = hostname
            node = lib.get_node(env.host)
            if node.get('dummy'):
                lib.print_header("Skipping dummy: {0}".format(env.host))
            else:
                lib.print_header("Configuring {0}".format(env.host))
                if __testing__:
                    print "TEST: would now configure {0}".format(env.host)
                else:
                    chef.sync_node(node)
コード例 #20
0
ファイル: test_lib.py プロジェクト: justinlundy/littlechef
 def test_get_nodes(self):
     """Should return all configured nodes"""
     expected = [
         {"name": "testnode1", "chef_environment": "production", "run_list": ["recipe[subversion]"]},
         {
             "chef_environment": "staging",
             "name": "testnode2",
             "other_attr": {"deep_dict": {"deep_key1": "node_value1"}},
             "subversion": {"password": "******", "user": "******"},
             "run_list": ["role[all_you_can_eat]"],
         },
         {
             "name": "testnode3.mydomain.com",
             "chef_environment": "production",
             "run_list": ["recipe[subversion]", "recipe[vim]"],
         },
         {"dummy": True, "chef_environment": "production", "name": "testnode4", "run_list": ["recipe[man]"]},
     ]
     self.assertEquals(lib.get_nodes(), expected)
コード例 #21
0
def node(*nodes):
    """Selects and configures a list of nodes. 'all' configures all nodes"""
    if not len(nodes) or nodes[0] == '':
        abort('No node was given')
    elif nodes[0] == 'all':
        # Fetch all nodes and add them to env.hosts
        for node in lib.get_nodes(env.chef_environment):
            env.hosts.append(node['name'])
        if not len(env.hosts):
            abort('No nodes found in /nodes/')
        message = "Are you sure you want to configure all nodes ({0})".format(
            len(env.hosts))
        if env.chef_environment:
            message += " in the {0} environment".format(env.chef_environment)
        message += "?"
        if not __testing__:
            if not confirm(message):
                abort('Aborted by user')
    else:
        # A list of nodes was given
        env.hosts = list(nodes)
    env.all_hosts = list(env.hosts)  # Shouldn't be needed
    if len(env.hosts) > 1:
        print "Configuring nodes: {0}...".format(", ".join(env.hosts))

    # Check whether another command was given in addition to "node:"
    execute = True
    if not (littlechef.__cooking__ and 'node:' not in sys.argv[-1]
            and 'nodes_with_role:' not in sys.argv[-1]):
        # If user didn't type recipe:X, role:Y or deploy_chef,
        # configure the nodes
        for hostname in env.hosts:
            env.host = hostname
            env.host_string = hostname
            node = lib.get_node(env.host)
            lib.print_header("Configuring {0}".format(env.host))
            if __testing__:
                print "TEST: would now configure {0}".format(env.host)
            else:
                chef.sync_node(node)
コード例 #22
0
ファイル: runner.py プロジェクト: mheffner/littlechef
def node(*nodes):
    """Selects and configures a list of nodes. 'all' configures all nodes"""
    if not len(nodes) or nodes[0] == "":
        abort("No node was given")
    elif nodes[0] == "all":
        # Fetch all nodes and add them to env.hosts
        for node in lib.get_nodes():
            if env.chef_environment is None or node.get("chef_environment") == env.chef_environment:
                env.hosts.append(node["name"])
        if not len(env.hosts):
            abort("No nodes found in /nodes/")
        message = "Are you sure you want to configure all nodes ({0})".format(len(env.hosts))
        if env.chef_environment:
            message += " in the {0} environment".format(env.chef_environment)
        message += "?"
        if not __testing__:
            if not confirm(message):
                abort("Aborted by user")
    else:
        # A list of nodes was given
        env.hosts = list(nodes)
    env.all_hosts = list(env.hosts)  # Shouldn't be needed
    if len(env.hosts) > 1:
        print "Configuring nodes: {0}...".format(", ".join(env.hosts))

    # Check whether another command was given in addition to "node:"
    execute = True
    if littlechef.__cooking__ and "node:" not in sys.argv[-1] and "nodes_with_role:" not in sys.argv[-1]:
        execute = False
    # If user didn't type recipe:X, role:Y or deploy_chef, just run configure
    if execute:
        for hostname in env.hosts:
            env.host = hostname
            env.host_string = hostname
            lib.print_header("Configuring {0}".format(env.host))
            # Read node data and configure node
            node = lib.get_node(env.host)
            if not __testing__:
                chef.sync_node(node)
コード例 #23
0
ファイル: runner.py プロジェクト: mheffner/littlechef
def get_ips():
    """Ping all nodes and update their 'ipaddress' field"""
    import subprocess

    for node in lib.get_nodes():
        # For each node, ping the hostname
        env.host_string = node["name"]
        proc = subprocess.Popen(["ping", "-c", "1", node["name"]], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        resp, error = proc.communicate()
        if not error:
            # Get lines from output and parse the first line to get the IP
            lines = resp.split("\n")
            ip = lines[0].split()[2].lstrip("(").rstrip(")")
            if not ip:
                print "Warning: could not get IP address from node {0}".format(node["name"])
                continue
            print "Node {0} has IP {1}".format(node["name"], ip)
            # Update with the ipaddress field in the corresponding node.json
            del node["name"]
            node["ipaddress"] = ip
            os.remove(chef.save_config(node, ip))
        else:
            print "Warning: could not resolve node {0}".format(node["name"])
コード例 #24
0
ファイル: runner.py プロジェクト: pombredanne/littlechef
def get_ips():
    """Ping all nodes and update their 'ipaddress' field"""
    import subprocess
    for node in lib.get_nodes():
        # For each node, ping the hostname
        env.host_string = node['name']
        proc = subprocess.Popen(['ping', '-c', '1', node['name']],
                    stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        resp, error = proc.communicate()
        if not error:
            # Split output into lines and parse the first line to get the IP
            ip = lib.parse_ip(resp.split("\n")[0])
            if not ip:
                print "Warning: could not get IP address from node {0}".format(
                    node['name'])
                continue
            print "Node {0} has IP {1}".format(node['name'], ip)
            # Update with the ipaddress field in the corresponding node.json
            del node['name']
            node['ipaddress'] = ip
            os.remove(chef.save_config(node, ip))
        else:
            print "Warning: could not resolve node {0}".format(node['name'])
コード例 #25
0
ファイル: test_lib.py プロジェクト: MrTomato8/littlechef
 def test_get_nodes_in_env(self):
     """Should list all nodes in the given environment"""
     self.assertEqual(len(lib.get_nodes("production")), 3)
     self.assertEqual(len(lib.get_nodes("staging")), 1)
コード例 #26
0
ファイル: runner.py プロジェクト: sirlantis/littlechef
def list_nodes_with_role(role):
    """Show all nodes which have asigned a given role"""
    for node in lib.get_nodes():
        recipename = "role[" + role + "]"
        if recipename in node.get("run_list"):
            lib.print_node(node)
コード例 #27
0
ファイル: test_lib.py プロジェクト: cocoy/littlechef
 def test_get_nodes_in_env(self):
     """Should list all nodes in the given environment"""
     self.assertEquals(len(lib.get_nodes("production")), 2)
     self.assertEquals(len(lib.get_nodes("staging")), 1)
コード例 #28
0
ファイル: runner.py プロジェクト: pombredanne/littlechef
def list_nodes_detailed():
    """Show a detailed list of all nodes"""
    for node in lib.get_nodes():
        lib.print_node(node, detailed=True)
コード例 #29
0
def list_nodes():
    """List all configured nodes"""
    for node in lib.get_nodes():
        lib.print_node(node)
コード例 #30
0
def list_nodes_detailed():
    """Show a detailed list of all nodes"""
    lib.print_nodes(lib.get_nodes(env.chef_environment), detailed=True)
コード例 #31
0
ファイル: runner.py プロジェクト: iancmcc/littlechef
def list_nodes():
    """List all configured nodes"""
    lib.print_nodes(lib.get_nodes(env.chef_environment))
コード例 #32
0
ファイル: runner.py プロジェクト: iancmcc/littlechef
def list_nodes_detailed():
    """Show a detailed list of all nodes"""
    lib.print_nodes(lib.get_nodes(env.chef_environment), detailed=True)
コード例 #33
0
def list_nodes_detailed():
    """Show a detailed list of all nodes"""
    for node in lib.get_nodes():
        lib.print_node(node, detailed=True)
コード例 #34
0
ファイル: runner.py プロジェクト: pombredanne/littlechef
def list_nodes():
    """List all configured nodes"""
    for node in lib.get_nodes():
        lib.print_node(node)
コード例 #35
0
def list_nodes_with_role(role):
    """Show all nodes which have asigned a given role"""
    for node in lib.get_nodes():
        recipename = 'role[' + role + ']'
        if recipename in node.get('run_list'):
            lib.print_node(node)
コード例 #36
0
def list_nodes():
    """List all configured nodes"""
    lib.print_nodes(lib.get_nodes(env.chef_environment))
コード例 #37
0
ファイル: runner.py プロジェクト: uggedal/littlechef
def list_nodes_with_role(role):
    """Show all nodes which have asigned a given role"""
    for node in lib.get_nodes():
        recipename = 'role[' + role + ']'
        if recipename in node.get('run_list'):
            lib.print_node(node)