FormatInputCollection() public static method

Helper method reformats inputs from simple key/value collection to proper API formatting. Also prepends text: in front of all inputs if it or another standard prefix is not in place
public static FormatInputCollection ( List inputSet ) : string>>.List
inputSet List Raw key/value set of inputs
return string>>.List
コード例 #1
0
        /// <summary>
        /// Launches the "next" instance of this server. This function is equivalent to invoking the launch action on the URL of this servers next_instance. See Instances#launch for details
        /// </summary>
        /// <param name="serverID">ID of the server whose next instance will be launched</param>
        /// <param name="inputs">collection of inputs to be passed into the launch process</param>
        /// <returns>True if success, false if not</returns>
        public static bool launch(string serverID, List <Input> inputs)
        {
            List <KeyValuePair <string, string> > inputParams = Utility.FormatInputCollection(inputs);
            string postHref = string.Format(APIHrefs.ServerLaunch, serverID);

            return(Core.APIClient.Instance.Post(postHref, inputParams));
        }
コード例 #2
0
        /// <summary>
        /// Private method to centralize buildout of parameters to post to RightScale API when creating a server
        /// </summary>
        /// <param name="deploymentID">ID of the deployment which the server will be added</param>
        /// <param name="description">The Server Description</param>
        /// <param name="cloudID">ID of the cloud that the server should be added to</param>
        /// <param name="datacenterID">ID of the Datacenter/zone</param>
        /// <param name="imageID">ID of the image to use</param>
        /// <param name="inputs">collection of inputs in name/value format</param>
        /// <param name="instanceTypeID">ID of the instance type</param>
        /// <param name="kernelImageID">ID of the kernel image</param>
        /// <param name="multiCloudImageID">ID of the multiCloudImage to use</param>
        /// <param name="ramdiskImageID">ID of the ramdisk image</param>
        /// <param name="securityGroupIDs">collection of security group IDs</param>
        /// <param name="serverTemplateID">ID of the ServerTemplate</param>
        /// <param name="sshKeyID">ID of the SSH key to use</param>
        /// <param name="userData">USer data that RightScale automaticall passes to your instanece at boot time</param>
        /// <param name="name">The name of the server</param>
        /// <param name="optimized">A flag indicating whether instances of this Server should support optimized Volumes</param>
        /// <returns>Collection of parameters for post process to create server</returns>
        private static List <KeyValuePair <string, string> > createGetParameterSet(string deploymentid, string description, string cloudID, string datacenterID, string imageID, List <Input> inputs, string instanceTypeID, string kernelImageID, string multiCloudImageID, string ramdiskImageID, List <string> securityGroupIDs, string serverTemplateID, string sshKeyID, string userData, string name, bool optimized)
        {
            //check required inputs

            string errorString = string.Empty;

            if (string.IsNullOrWhiteSpace(cloudID))
            {
                errorString += "CloudID is a required input" + Environment.NewLine;
            }
            if (string.IsNullOrWhiteSpace(name))
            {
                errorString += "Name is a required input" + Environment.NewLine;
            }
            if (string.IsNullOrWhiteSpace(serverTemplateID))
            {
                errorString += "ServerTemplateID is a required input" + Environment.NewLine;
            }
            if (string.IsNullOrWhiteSpace(deploymentid))
            {
                errorString += "DeploymentID is a required input" + Environment.NewLine;
            }

            if (!string.IsNullOrWhiteSpace(errorString))
            {
                throw new ArgumentException("Errors were found when parsing inputs for Server.create() : " + Environment.NewLine + errorString);
            }

            //populate return value
            List <KeyValuePair <string, string> > retVal = new List <KeyValuePair <string, string> >();

            retVal.AddRange(Utility.FormatInputCollection(inputs));
            Utility.addParameter(Utility.deploymentHref(deploymentid), "server[deployment_href]", retVal);
            Utility.addParameter(description, "server[description]", retVal);
            Utility.addParameter(Utility.cloudHref(cloudID), "server[instance][cloud_href]", retVal);
            Utility.addParameter(Utility.imageHref(cloudID, imageID), "server[instance][image_href]", retVal);
            Utility.addParameter(Utility.instanceTypeHref(cloudID, instanceTypeID), "server[instance][instance_type_href]", retVal);
            Utility.addParameter(Utility.kernelImageHref(cloudID, kernelImageID), "server[instance][kernel_image_href]", retVal);
            Utility.addParameter(Utility.multiCloudImageHref(multiCloudImageID), "server[instance][multi_cloud_image_href]", retVal);
            Utility.addParameter(Utility.ramdiskImageHref(cloudID, ramdiskImageID), "server[instance][ramdisk_image_href]", retVal);
            Utility.addParameter(Utility.serverTemplateHref(serverTemplateID), "server[instance][server_template_href]", retVal);
            Utility.addParameter(Utility.sshKeyHref(cloudID, sshKeyID), "server[instance][ssh_key_href]", retVal);
            Utility.addParameter(name, "server[name]", retVal);
            Utility.addParameter(optimized.ToString().ToLower(), "server[optimized]", retVal);

            if (securityGroupIDs != null && securityGroupIDs.Count > 0)
            {
                foreach (string s in securityGroupIDs)
                {
                    Utility.addParameter(s, "server[instance][security_group_hrefs][]", retVal);
                }
            }

            return(retVal);
        }
コード例 #3
0
ファイル: Input.cs プロジェクト: jmlewis1/RightScaleNetAPI
        /// <summary>
        /// Private multi update method to centralize logic of handling input mutli_update
        /// </summary>
        /// <param name="putHref">href to put to</param>
        /// <param name="inputs">collection of inputs to update</param>
        /// <returns>true if successful, false if not</returns>
        private static bool multi_updatePut(string putHref, List <Input> inputs)
        {
            List <KeyValuePair <string, string> > putParams = Utility.FormatInputCollection(inputs);

            return(Core.APIClient.Instance.Put(putHref, putParams));
        }