0
votes

i use chef-api for express js and i wanna get only the ip address of node " server 1 " from a chef-server

im sending a request like this

Code :


chef.partialSearch("node", "name:server1",{"ip":"ipaddress"} ,function(err, res){

  if (err){console.log(error);}

  else{console.log(res);}

});

Or

chef.partialSearch("node", { q: "name:server1"} ,{"ip":"ipaddress"} ,function(err, res){
....
});

=> Response :

received status code 400 invalid  value 'ipaddress' for no_key

function in code source :

partialSearch: function(index, qs, data, fn){
            http_methods.post([config.host_url, "search", index].join("/"), qs, data, function(err, response){
                return fn(err, response);
            });
        }

and i cant understand the correct syntax for the request (http) from the official website doc api_chef_server
Can you please give a valid syntax with example . Thanks

2
Are you always planning to access a single node at a time?coderanger

2 Answers

0
votes

What you probably want is something like this:

chef.getNode('server1', function(err, node) {
    if(err) throw err;
    console.log(node.automatic.ipaddress);
});
0
votes

Finaly i found the correct syntax for both request

Simple Search :

    chef.search("node", {q: "name:server1" }, function(err, res){

       if (err){console.log(error);}

       else{console.log(res);}

     });

Partial Search :

chef.partialSearch("node", "chef_environment:prod", { name: ['name'] , 'ipaddress': ['ipaddress'] }, function(err, res){

        if (err){console.log(error);}

        else{console.log(res);}


    });

Hope this can help someone else who is still looking .