serverTemplateHref() public static method

Helper method returns properly formatted server_template_href
public static serverTemplateHref ( string objectID ) : string
objectID string ServerTempalte ID
return string
Esempio n. 1
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);
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a new ServerTemplateMultiCloudImage with the given parameters
        /// </summary>
        /// <param name="multiCloudImageID">ID of the MultiCloudImage</param>
        /// <param name="serverTemplateID">ID of the ServerTemplate</param>
        /// <returns>ID of the newly created ServerTemplateMultiCloudImage object</returns>
        public static string create(string multiCloudImageID, string serverTemplateID)
        {
            List <KeyValuePair <string, string> > postParams = new List <KeyValuePair <string, string> >();

            Utility.addParameter(Utility.multiCloudImageHref(multiCloudImageID), "server_template_multi_cloud_image[multi_cloud_image_href]", postParams);
            Utility.addParameter(Utility.serverTemplateHref(serverTemplateID), "server_template_multi_cloud_image[server_template_href]", postParams);
            string        outString = string.Empty;
            List <string> retVal    = Core.APIClient.Instance.Post(APIHrefs.ServerTemplateMultiCloudImages, postParams, "location", out outString);

            return(retVal.Last <string>().Split('/').Last <string>());
        }