/// <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); }
/// <summary> /// Updates a generic cloud setting /// </summary> /// <param name="multiCloudImageID">ID of the MultiCloudImage</param> /// <param name="cloudID">ID of the Cloud</param> /// <param name="imageID">ID of the Image</param> /// <param name="instanceTypeID">ID of the InstanceType</param> /// <param name="kernelImageID">ID of kernel image</param> /// <param name="ramdiskImageID">ID of ramdisk image</param> /// <param name="userData">User data that RightScale automaticaly passes to your instance at boot time</param> /// <returns>True if updated, false if not</returns> public static bool update(string multiCloudImageID, string cloudID, string imageID, string instanceTypeID, string kernelImageID, string ramdiskID, string userData) { Utility.CheckStringHasValue(multiCloudImageID); string putHref = string.Format(APIHrefs.MultiCloudImageSettings, multiCloudImageID); List <KeyValuePair <string, string> > postParams = new List <KeyValuePair <string, string> >(); Utility.addParameter(Utility.cloudHref(cloudID), "multi_cloud_image_setting[cloud_href]", postParams); Utility.addParameter(Utility.imageHref(cloudID, imageID), "multi_cloud_image_setting[image_href]", postParams); Utility.addParameter(Utility.instanceTypeHref(cloudID, instanceTypeID), "multi_cloud_image_setting[instance_type_href]", postParams); Utility.addParameter(Utility.kernelImageHref(cloudID, kernelImageID), "multi_cloud_image_setting[kernel_image_href]", postParams); Utility.addParameter(Utility.ramdiskImageHref(cloudID, ramdiskID), "multi_cloud_image_setting[ramdisk_image_href", postParams); Utility.addParameter(userData, "multi_cloud_image_setting[user_data]", postParams); return(Core.APIClient.Instance.Put(putHref, postParams)); }