Пример #1
0
        public Function Delete(string nodeName)
        {
            ReturnType rt = new ReturnType();

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

            ChefRequest cr       = new ChefRequest();
            string      response = cr.Delete(ChefConfig.Validator, "nodes/" + nodeName);

            if (response.Contains("Response status code does not indicate success"))
            {
                rt.Result  = 4;
                rt.Data    = String.Empty;
                rt.Object  = null;
                rt.Message = "Unable to delete node.";
            }
            else
            {
                rt.Result  = 0;
                rt.Data    = String.Empty;
                rt.Object  = null;
                rt.Message = "Node: " + nodeName + " is deleted.";
            }
            return(rt);
        }
Пример #2
0
        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;
            }
        }
Пример #3
0
        public Function Delete(string clientName)
        {
            ReturnType rt = new ReturnType();

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

            ChefRequest cr = new ChefRequest();
            string response = cr.Delete(ChefConfig.Validator, "clients/" + clientName);

            if (response.Contains("Response status code does not indicate success"))
            {
                rt.Result = 4;
                rt.Data = null;
                rt.Object = null;
                rt.Message = "Unable to delete client.";
            }
            else
            {
                rt.Result = 0;
                rt.Data = response;
                rt.Object = null;
                rt.Message = "Client: " + clientName + " is deleted.";
            }
            return rt;
        }
Пример #4
0
 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);
     }
 }
Пример #5
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);
        }