예제 #1
0
파일: Client.cs 프로젝트: rvanderbrugge/blu
        public Function Add(string clientName)
        {
            ReturnType rt = new ReturnType();

            Logger.log("info", "Attempting to create client: " + clientName);

            ChefRequest cr = new ChefRequest();

            Dictionary<string, string> dictClient = new Dictionary<string, string>()
            {
                { "name", clientName },
                { "admin", "false" }
            };

            string json = JsonConvert.SerializeObject(dictClient, Formatting.Indented);
            string response = cr.Post(ChefConfig.Validator, "clients", json);
            if (response.Contains("409") && response.Contains("Conflict"))
            {
                rt.Result = 3;
                rt.Message = "Client already exists.";
                return rt;
            }
            else if (response.Contains("BEGIN RSA PRIVATE KEY"))
            {
                KeyHelper kh = new KeyHelper();
                rt = kh.Format(response);
                return rt;
            }
            else
            {
                rt.Result = 4;
                rt.Message = "Error creating Client, API response: " + response;
                return rt;
            }
        }
예제 #2
0
파일: BluApp.cs 프로젝트: rvanderbrugge/blu
 private void btnPost_Click(object sender, EventArgs e)
 {
     txtError.Text = String.Empty;
     try
     {
         ChefRequest cr       = new ChefRequest();
         string      nodeName = ChefConfig.NodeName;
         string      json     = cr.Post(nodeName, txtSelect.Text, txtMessage.Text);
         jvResponse.Json = json;
         jvResponse.Text = json;
         jvResponse.ShowTab(Tabs.Text);
     }
     catch (Exception ex)
     {
         MessageBox.Show("Unable to POST: \r\n" + ex.Message + "\r\nCan not find the requested endpoint on the Chef server.",
                         "Chef API Path Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
     }
 }
예제 #3
0
        public Function Add(string nodeName, string environment, List <string> runlist, List <string> roles)
        {
            ReturnType rt = new ReturnType();

            Logger.log("info", "Attempting to create node: " + nodeName);

            ChefRequest cr = new ChefRequest();

            // Convert runlist[] and roles[] to List run_list
            List <string> runList = new List <string>();

            foreach (string run in runlist)
            {
                runList.Add("recipe[" + run + "]");
            }
            foreach (string role in roles)
            {
                runList.Add("role[" + role + "]");
            }

            if (string.IsNullOrEmpty(environment))
            {
                environment = "_default";
            }

            Dictionary <string, dynamic> dictNode = new Dictionary <string, dynamic>()
            {
                { "name", nodeName },
                { "chef_type", "node" },
                { "json_class", "Chef::Node" },
                // { "attributes", dict_node_attributes},
                { "chef_environment", environment }
            };

            if (runList.Count > 0)
            {
                dictNode.Add("run_list", runList);
            }

            string json = JsonConvert.SerializeObject(dictNode, Formatting.Indented);

            Logger.log("info", "Attempting to create Chef Node by POST the following json:");
            Logger.log("data", json);

            string response = cr.Post(ChefConfig.Validator, "nodes", json);

            if (response.Contains("409") && response.Contains("Conflict"))
            {
                rt.Result  = 3;
                rt.Data    = String.Empty;
                rt.Object  = null;
                rt.Message = "Node already exists.";
                return(rt);
            }
            if (response.Contains("uri"))
            {
                rt.Result  = 0;
                rt.Data    = String.Empty;
                rt.Object  = null;
                rt.Message = "Chef Node: " + nodeName + " is created succesfully.";
                return(rt);
            }
            rt.Result  = 4;
            rt.Data    = String.Empty;
            rt.Object  = null;
            rt.Message = "Error creating Node, API response: " + response;
            return(rt);
        }