addParameter() public static method

Helper method performs null/empty check on inputParameter and adds to parameterSet
public static addParameter ( int inputParameter, string parameterName, string>.List parameterSet ) : void
inputParameter int
parameterName string
parameterSet string>.List
return void
        /// <summary>
        /// Internal process to manage Post for creating a SecurityGroupRule
        /// </summary>
        /// <param name="protocol">Security Group Rule protocol</param>
        /// <param name="sourceType">Security Group Rule source type</param>
        /// <param name="cidrIPs">Security Group Rule CIDR ips</param>
        /// <param name="groupName">Security Group Rule group name</param>
        /// <param name="groupOwner">Security Group Rule group owner</param>
        /// <param name="startPort">Security Group Rule start port</param>
        /// <param name="endPort">Security Group Rule end port</param>
        /// <param name="icmpCode">Security Group Rule icmp code</param>
        /// <param name="icmpType">Security Group Rule icmp type</param>
        /// <param name="postHref">Post HREF for api call</param>
        /// <param name="securityGroupHref">Security group HREF</param>
        /// <returns>ID of newly created security group rule</returns>
        private static string createPost(string protocol, string sourceType, string cidrIPs, string groupName, string groupOwner, string startPort, string endPort, string icmpCode, string icmpType, string postHref, string securityGroupHref)
        {
            List <string> validSourceTypes = new List <string>()
            {
                "cidr_ips", "group"
            };
            List <String> validProtocols = new List <string>()
            {
                "tcp", "udp", "icmp"
            };
            List <KeyValuePair <string, string> > postParams = new List <KeyValuePair <string, string> >();

            Utility.CheckStringHasValue(protocol);
            Utility.CheckStringHasValue(sourceType);
            Utility.addParameter(cidrIPs, "security_group_rule[cidr_ips]", postParams);
            Utility.addParameter(groupName, "security_group_rule[group_name]", postParams);
            Utility.addParameter(groupOwner, "security_group_rule[group_owner]", postParams);
            Utility.addParameter(protocol, "security_group_rule[protocol]", postParams);
            Utility.addParameter(endPort, "security_group_rule[protocol_details][end_port]", postParams);
            Utility.addParameter(icmpCode, "security_group_rule[protocol_details][icmp_code]", postParams);
            Utility.addParameter(icmpType, "security_group_rule[protocol_details][icmp_type]", postParams);
            Utility.addParameter(startPort, "security_group_rule[protocol_details][start_port]", postParams);
            Utility.addParameter(securityGroupHref, "security_group_rule[security_group_href]", postParams);
            Utility.addParameter(sourceType, "security_group_rule[source_type]", postParams);

            return(Core.APIClient.Instance.Post(postHref, postParams, "location").Last <string>().Split('/').Last <string>());
        }
示例#2
0
        /// <summary>
        /// Create a CloudAccount by passing in the respective credentials for each cloud.
        /// If the cloud is a public non-aws cloud, the cloud_href can be accessed from the 'Clouds' resource. If the cloud is an aws cloud, simply pass the string 'aws'.
        /// </summary>
        /// <param name="cloudID">ID of the Cloud from the 'Clouds' resource - if AWS pass the string 'aws'</param>
        /// <param name="creds">Collection of parameters for registering the cloud.  Specific required fields per cloud can be found on the resource page for CloudAccounts</param>
        /// <param name="token">The cloud token to identify a private cloud</param>
        /// <returns>ID of newly created CloudAccount</returns>
        public static string create(string cloudID, Dictionary <string, string> creds, string token)
        {
            Utility.CheckStringHasValue(cloudID);
            if (creds == null || creds.Count == 0)
            {
                throw new ArgumentException("CloudAccount.create 'creds' parameter must contain a value specific to the CloudAccount being registered");
            }

            List <KeyValuePair <string, string> > postParams = new List <KeyValuePair <string, string> >();
            string cloudIDParameter = string.Empty;

            if (cloudID.ToLower().Trim() == "aws")
            {
                cloudIDParameter = cloudID.ToLower();
            }
            else
            {
                cloudIDParameter = string.Format(APIHrefs.CloudByID, cloudID);
            }
            Utility.addParameter(cloudIDParameter, "cloud_account[cloud_href]", postParams);

            foreach (string k in creds.Keys)
            {
                Utility.addParameter(creds[k], string.Format("cloud_account[creds][{0}]", k), postParams);
            }

            Utility.addParameter(token, "cloud_account[token]", postParams);

            return(Core.APIClient.Instance.Post(APIHrefs.CloudAccount, postParams, "location").Last <string>().Split('/').Last <string>());
        }
示例#3
0
        /// <summary>
        /// Create a user. If a user already exists with the same email, that user will be returned.
        /// Creating a user alone will not enable the user to access this account. You have to create 'permissions' for that user before it can be used. Performing a 'show' on a new user will fail unless you immediately create an 'observer' permission on the current account.
        /// Note that information about users and their permissions must be propagated globally across all RightScale clusters, and this can take some time (less than 60 seconds under normal cirucmstances) so the users you create may not be able to login for a minute or two after you create them. However, you may create or destroy permissions for newly-created users with no delay.
        /// To create a user that will login using password authentication, include the 'password' parameter with your request.
        /// To create an SSO-enabled user, you must specify the identity_provider that will be vouching for this user's identity, as well as the principal_uid (SAML NameID or OpenID identity URL) that the identity provider will assert for this user. Identity providers should be specified by their API href; you can obtain a list of the identity providers available to your account by invoking the 'index' action of the identity_providers API resource.
        /// </summary>
        /// <param name="email">Email of user</param>
        /// <param name="firstName">First name of user</param>
        /// <param name="lastName">Last name of user</param>
        /// <param name="phone">Phone number for user</param>
        /// <param name="identityProviderID">The RightScale API href ID of the Identity Provider through which this user will login to RightScale. Required to create an SSO-authenticated user.</param>
        /// <param name="password">The password of this user. Required to create a password-authenticated user</param>
        /// <param name="principalUid">The principal identifier (SAML NameID or OpenID identity URL) of this user. Required to create an SSO-authenticated user</param>
        /// <returns></returns>
        public static string create(string email, string firstName, string lastName, string company, string phone, string password, string identityProviderID, string principalUid)
        {
            Utility.CheckStringHasValue(email);
            Utility.CheckStringHasValue(firstName);
            Utility.CheckStringHasValue(lastName);
            Utility.CheckStringHasValue(phone);
            Utility.CheckStringHasValue(company);
            List <KeyValuePair <string, string> > paramSet = new List <KeyValuePair <string, string> >();

            if (!string.IsNullOrWhiteSpace(phone))
            {
                string phoneValidationRegex = @"^\d+$";
                Utility.CheckStringRegex("phone", phoneValidationRegex, phone);
            }
            Utility.addParameter(email, "user[email]", paramSet);
            Utility.addParameter(firstName, "user[first_name]", paramSet);
            Utility.addParameter(company, "user[company]", paramSet);
            Utility.addParameter(lastName, "user[last_name]", paramSet);
            Utility.addParameter(phone, "user[phone]", paramSet);
            Utility.addParameter(string.Format(APIHrefs.IdentityProviderByID, identityProviderID), "user[identity_provider_href]", paramSet);
            Utility.addParameter(password, "user[password]", paramSet);
            Utility.addParameter(principalUid, "user[principal_uid]", paramSet);

            return(Core.APIClient.Instance.Post(APIHrefs.User, paramSet, "location").Last <string>().Split('/').Last <string>());
        }
        /// <summary>
        /// Publishes a given ServerTemplate and its subordinates
        /// </summary>
        /// <param name="serverTemplateID">ID of the ServerTemplate to publish</param>
        /// <param name="accountGroupIDs">Collection of Account Group IDs to publish to </param>
        /// <param name="allowComments">Allow users to leave comments on this ServerTemplate</param>
        /// <param name="description">Description for this publish</param>
        /// <param name="email_comments">Email me when a user comments on this ServerTemplate</param>
        /// <param name="categories">List of Categories</param>
        /// <returns>ID of the newly created publication</returns>
        public static string publish(string serverTemplateID, List <string> accountGroupIDs, bool allowComments, Description description, bool email_comments, List <string> categories)
        {
            string postHref = string.Format(APIHrefs.ServerTemplatePublish, serverTemplateID);
            List <KeyValuePair <string, string> > postParams = new List <KeyValuePair <string, string> >();

            if (accountGroupIDs != null && accountGroupIDs.Count > 0)
            {
                foreach (string accountGroupID in accountGroupIDs)
                {
                    Utility.addParameter(Utility.accountGroupHrefByID(accountGroupID), "account_group_hrefs[]", postParams);
                }
            }

            Utility.addParameter(allowComments.ToString().ToLower(), "allow_comments", postParams);

            if (categories != null && categories.Count > 0)
            {
                foreach (string category in categories)
                {
                    Utility.addParameter(category, "categories[]", postParams);
                }
            }

            if (description != null)
            {
                postParams.AddRange(description.descriptionParameters("descriptions[{0}]"));
            }

            Utility.addParameter(email_comments.ToString().ToLower(), "email_comments", postParams);

            return(Core.APIClient.Instance.Post(postHref, postParams, "location").Last <string>().Split('/').Last <string>());
        }
示例#5
0
        /// <summary>
        /// Create an enterprise ChildAccount for this Account. The User will by default get an 'admin' role on the ChildAccount to enable him/her to add, delete Users and Permissions
        /// </summary>
        /// <param name="name">Name of the child account to be created</param>
        /// <returns>ID of the newly created child account</returns>
        public static string create(string name)
        {
            Utility.CheckStringHasValue(name);
            List <KeyValuePair <string, string> > postParams = new List <KeyValuePair <string, string> >();

            Utility.addParameter(name, "child_account[name]", postParams);
            return(Core.APIClient.Instance.Post(APIHrefs.ChildAccount, postParams, "location").Last <string>().Split('/').Last <string>());
        }
示例#6
0
        /// <summary>
        /// Creates a new ssh key
        /// </summary>
        /// <param name="cloudID">ID of cloud in which to create SSH key</param>
        /// <param name="name">name of Ssh key</param>
        /// <returns>ID of newly created SSH key</returns>
        public static string create(string cloudID, string name)
        {
            string postHref = string.Format(APIHrefs.SshKey, cloudID);
            List <KeyValuePair <string, string> > postParams = new List <KeyValuePair <string, string> >();

            Utility.addParameter(name, "ssh_key[name]", postParams);
            return(Core.APIClient.Instance.Post(postHref, postParams, "location").Last <string>().Split('/').Last <string>());
        }
        /// <summary>
        /// Creates a new ServerTemplate with the given parameters
        /// </summary>
        /// <param name="name">The name of the ServerTemplate to be created</param>
        /// <param name="description">The description of the ServerTemplate to be created</param>
        /// <returns>ID of the newly created ServerTemplate</returns>
        public static string create(string name, string description)
        {
            List <KeyValuePair <string, string> > postParams = new List <KeyValuePair <string, string> >();

            Utility.addParameter(description, "server_template[description]", postParams);
            Utility.addParameter(name, "server_template[name]", postParams);
            return(Core.APIClient.Instance.Post(APIHrefs.ServerTemplate, postParams, "location").Last <string>().Split('/').Last <string>());
        }
        /// <summary>
        /// Private centralized caller for updating MultiCloudImage
        /// </summary>
        /// <param name="putHref">API Href fragment to perform PUT operation against</param>
        /// <param name="name">updated name for the MultiCloudImage</param>
        /// <param name="description">updated description for the MultiCloudImage</param>
        /// <returns>true if updated, false if not</returns>
        private static bool updatePut(string putHref, string name, string description)
        {
            List <KeyValuePair <string, string> > putParams = new List <KeyValuePair <string, string> >();

            Utility.addParameter(name, "multi_cloud_image[name]", putParams);
            Utility.addParameter(description, "multi_cloud_image[description]", putParams);
            return(Core.APIClient.Instance.Put(putHref, putParams));
        }
示例#9
0
        /// <summary>
        /// Updates the committed tag for all of the VolumeSnapshots in the given Backup to the given value.
        /// </summary>
        /// <param name="backupID">ID of the backup to be updated</param>
        /// <param name="committed">Setting this to 'true' will update the 'rs_backup:committed=false' tag to 'rs_backup:committed=true' on all the snapshots</param>
        /// <returns>true if updated, false if not</returns>
        public static bool update(string backupID, bool committed)
        {
            string putHref = string.Format(APIHrefs.BackupByID, backupID);
            List <KeyValuePair <string, string> > putParams = new List <KeyValuePair <string, string> >();

            Utility.addParameter(committed.ToString().ToLower(), "backup[committed]", putParams);
            return(Core.APIClient.Instance.Put(putHref, putParams));
        }
示例#10
0
        /// <summary>
        /// Updates attributes of a given ServerTemplate.  Only HEAD revisions can be updated (revision 0).  Currently the attributes you can update are only the 'direct' attributes of a ServerTemplate.  To manage multi cloud images of a ServerTemplate, please see the 'ServerTemplateMultiCloudImages' object.
        /// </summary>
        /// <param name="serverTemplateId"></param>
        /// <param name="name"></param>
        /// <param name="description"></param>
        /// <returns></returns>
        public static bool update(string serverTemplateId, string name, string description)
        {
            string putHref = string.Format(APIHrefs.ServerTemplateByID, serverTemplateId);
            List <KeyValuePair <string, string> > putParams = new List <KeyValuePair <string, string> >();

            Utility.addParameter(name, "server_template[name]", putParams);
            Utility.addParameter(description, "server_template[description]", putParams);
            return(Core.APIClient.Instance.Put(putHref, putParams));
        }
示例#11
0
        /// <summary>
        /// Update an enterprise ChildAccount for this Account.
        /// </summary>
        /// <param name="childAccountID">ID of the ChildAccount to be updates</param>
        /// <param name="name">New name for ChildAccount specified</param>
        /// <returns>true if successful, false if not</returns>
        public static bool update(string childAccountID, string name)
        {
            Utility.CheckStringHasValue(childAccountID);
            string putHref = string.Format(APIHrefs.ChildAccountByID, childAccountID);
            List <KeyValuePair <string, string> > putParams = new List <KeyValuePair <string, string> >();

            Utility.addParameter(name, "child_account[name]", putParams);
            return(Core.APIClient.Instance.Put(putHref, putParams));
        }
示例#12
0
        /// <summary>
        /// Private method to centrally handle PUT calls to Rightscale API
        /// </summary>
        /// <param name="putHref">API href to all for action</param>
        /// <param name="description">The Updated Description for the server</param>
        /// <param name="name">The updated Server name</param>
        /// <param name="optimized">A flag indicating whether Instances of this Server should support optimized Volumes (e.g. Volumes supporting a specified number of IOPS). Not supported in all Clouds.</param>
        /// <returns></returns>
        private static bool updatePut(string putHref, string description, string name, bool optimized)
        {
            List <KeyValuePair <string, string> > paramSet = new List <KeyValuePair <string, string> >();

            Utility.addParameter(description, "server[description]", paramSet);
            Utility.addParameter(name, "server[name]", paramSet);
            Utility.addParameter(optimized.ToString().ToLower(), "server[optimized]", paramSet);

            return(Core.APIClient.Instance.Put(putHref, paramSet));
        }
示例#13
0
        /// <summary>
        /// Commits a given ServerTemplate.  Only HEAD revisions (revision 0) that are owned by the account can be committed.
        /// </summary>
        /// <param name="serverTemplateID">ID of the ServerTemplate to be committed</param>
        /// <param name="commit_head_dependencies">Commit all HEAD revisions (if any) of the associated MultiCloud images, RightScripts and Chef repo sequences.</param>
        /// <param name="commit_message">The message associated with the commit.</param>
        /// <param name="freeze_repositories">Freeze the repositories</param>
        /// <returns>ID of the committed ServerTemplate</returns>
        public static string commit(string serverTemplateID, bool commit_head_dependencies, string commit_message, bool freeze_repositories)
        {
            string postHref = string.Format(APIHrefs.ServerTemplateCommit, serverTemplateID);
            List <KeyValuePair <string, string> > postParams = new List <KeyValuePair <string, string> >();

            Utility.addParameter(commit_head_dependencies.ToString().ToLower(), "commit_head_dependencies", postParams);
            Utility.addParameter(commit_message, "commit_message", postParams);
            Utility.addParameter(freeze_repositories.ToString().ToLower(), "freeze_repositories", postParams);
            return(Core.APIClient.Instance.Post(postHref, postParams, "location").Last <string>().Split('/').Last <string>());
        }
示例#14
0
        /// <summary>
        /// Clones a given servertemplate and assigns a new name and description as specified
        /// </summary>
        /// <param name="serverID">ID of the servertemplate to be cloned</param>
        /// <param name="name">Name of the new ServerTemplate</param>
        /// <param name="description">Description of the new ServerTemplate</param>
        /// <returns>ID of the newly created servertemplate</returns>
        public static string clone(string servertemplateID, string name, string description)
        {
            Utility.CheckStringHasValue(name);
            string postHref = string.Format(APIHrefs.ServerTemplateClone, servertemplateID);
            List <KeyValuePair <string, string> > postParams = new List <KeyValuePair <string, string> >();

            Utility.addParameter(name, "server_template[name]", postParams);
            Utility.addParameter(description, "server_template[description]", postParams);
            return(clonePost(postHref, postParams));
        }
示例#15
0
        /// <summary>
        /// Creates a new Security Group in the specified cloud
        /// </summary>
        /// <param name="cloudID">ID of the cloud where the Security Group will be created</param>
        /// <param name="name">Name of the Security Group to be created</param>
        /// <param name="description">Description for the newly created security group</param>
        /// <returns>ID of the newly created Security Group</returns>
        public static string create(string cloudID, string name, string description)
        {
            string postHref = string.Format(APIHrefs.SecurityGroup, cloudID);
            List <KeyValuePair <string, string> > postParams = new List <KeyValuePair <string, string> >();

            Utility.CheckStringHasValue(name);
            Utility.addParameter(name, "security_group[name]", postParams);
            Utility.addParameter(description, "security_group[description]", postParams);
            return(Core.APIClient.Instance.Post(postHref, postParams, "location").Last <string>().Split('/').Last <string>());
        }
示例#16
0
        /// <summary>
        /// Update call consisting of the name, value and description
        /// </summary>
        /// <param name="credentialID">ID of the Credential to update</param>
        /// <param name="name">new name of the Credential</param>
        /// <param name="value">new value for the Credential</param>
        /// <param name="description">new description for the Credential</param>
        /// <returns>true if updated, false if not</returns>
        public static bool update(string credentialID, string name, string value, string description)
        {
            string putHref = string.Format(APIHrefs.CredentialByID, Core.API10Client.Instance.accountId, credentialID);
            List <KeyValuePair <string, string> > putParams = new List <KeyValuePair <string, string> >();

            Utility.addParameter(name, "credential[name]", putParams);
            Utility.addParameter(value, "credential[value]", putParams);
            Utility.addParameter(description, "credential[description]", putParams);
            return(Core.API10Client.Instance.Put(putHref, putParams));
        }
示例#17
0
        /// <summary>
        /// Creates a new Credential with a name and value
        /// </summary>
        /// <param name="name">name for the new Credential</param>
        /// <param name="value">value for the new Credential</param>
        /// <param name="description">description for the new Credential</param>
        /// <returns>string ID of the newly created Credential</returns>
        public static string create(string name, string value, string description)
        {
            string postHref = string.Format(APIHrefs.Credential, Core.API10Client.Instance.accountId);
            List <KeyValuePair <string, string> > putParams = new List <KeyValuePair <string, string> >();

            Utility.addParameter(name, "credential[name]", putParams);
            Utility.addParameter(value, "credential[value]", putParams);
            Utility.addParameter(description, "credential[description]", putParams);
            return(Core.API10Client.Instance.Post(postHref, putParams, "Location").Last <string>().Split('/').Last <string>());
        }
示例#18
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);
        }
示例#19
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>());
        }
        /// <summary>
        /// Centralized method to handle all create posts
        /// </summary>
        /// <param name="postHref">api href for making a request to create a new MultiCloud Image</param>
        /// <param name="name">Name of the MultiCloud Image</param>
        /// <param name="description">Description for this MultiCloud Image</param>
        /// <returns>ID of the newly created MultiCloud Image</returns>
        private static string createPost(string postHref, string name, string description)
        {
            List <KeyValuePair <string, string> > postParams = new List <KeyValuePair <string, string> >();

            Utility.addParameter(description, "multi_cloud_image[description]", postParams);
            Utility.addParameter(name, "multi_cloud_image[name]", postParams);
            string        outStr  = string.Empty;
            List <string> strList = Core.APIClient.Instance.Post(postHref, postParams, "location", out outStr);

            return(strList.Last <string>().Split('/').Last <string>());
        }
示例#21
0
        /// <summary>
        /// Create a permission, thereby granting some user a particular role with respect to the current account.
        /// The 'observer' role has a special status; it must be granted before a user is eligible for any other permission in a given account.
        /// When provisioning users, always create the observer permission FIRST; creating any other permission before it will result in an error.
        /// For more information about the roles available and the privileges they confer, please refer to the following page of the RightScale support portal: http://support.rightscale.com/15-References/Lists/ListofUser_Roles
        /// </summary>
        /// <param name="roleTitle">Title of the role to be granted to the specified user</param>
        /// <param name="userID">ID of the User to be granted the role specifieed</param>
        /// <returns>ID of the newly created permission</returns>
        public static string create(string roleTitle, string userID)
        {
            string userHref = string.Format(APIHrefs.UserByID, userID);

            Utility.CheckStringHasValue(roleTitle);
            Utility.CheckStringHasValue(userID);
            List <KeyValuePair <string, string> > postParams = new List <KeyValuePair <string, string> >();

            Utility.addParameter(roleTitle, "permission[role_title]", postParams);
            Utility.addParameter(userHref, "permission[user_href]", postParams);
            return(Core.APIClient.Instance.Post(APIHrefs.Permission, postParams, "location").Last <string>().Split('/').Last <string>());
        }
示例#22
0
        /// <summary>
        /// Private method for centralizing all logic for VolumeAttachment Create clals
        /// </summary>
        /// <param name="postHref">Href fragment for calling RSAPI</param>
        /// <param name="cloudID">ID of Cloud</param>
        /// <param name="device">The device location where the volume will be mounted. Value must be of format /dev/xvd[bcefghij]. This is not reliable and will be deprecated</param>
        /// <param name="instanceID">The ID of the instance to which the volume will be attached to</param>
        /// <param name="volumeID">The ID of the volume to be attached</param>
        /// <returns>ID of newly created VolumeAttachment</returns>
        private static string createPost(string postHref, string cloudID, string device, string instanceID, string volumeID)
        {
            List <KeyValuePair <string, string> > postParams = new List <KeyValuePair <string, string> >();

            Utility.addParameter(Utility.InstanceHref(cloudID, instanceID), "volume_attachment[instance_href]", postParams);
            Utility.addParameter(Utility.VolumeHref(cloudID, volumeID), "volume_attachment[volume_href]", postParams);
            Utility.addParameter(device, "volume_attachment[device]", postParams);
            string outString = string.Empty;

            List <string> retVal = Core.APIClient.Instance.Post(postHref, postParams, "location", out outString);

            return(retVal.Last <string>().Split('/').Last <string>());
        }
        /// <summary>
        /// Commits a given MultiCloudImage.  Only HEAD revisions can be committed.
        /// </summary>
        /// <param name="multiCloudImageID">ID of the MultiCloudImage to be committed</param>
        /// <returns>ID for the committed MultiCloud Image</returns>
        public static string commit(string multiCloudImageID, string message)
        {
            List <KeyValuePair <string, string> > putParams = new List <KeyValuePair <string, string> >();

            string postHref  = string.Format(APIHrefs.MultiCloudImageCommit, multiCloudImageID);
            string outString = string.Empty;

            Utility.addParameter(message, "commit_message", putParams);

            List <string> results = Core.APIClient.Instance.Post(postHref, putParams, "location", out outString);

            return(results.Last <string>().Split('/').Last <string>());
        }
示例#24
0
        /// <summary>
        /// Private method to translate filter lists to convert to a parameter set
        /// </summary>
        /// <param name="filterList">list of filters to push to a parameter set</param>
        /// <returns>list of keyvaluepairs for parameter inputs</returns>
        public static List <KeyValuePair <string, string> > FilterListToParameterSet(List <Filter> filterList)
        {
            List <KeyValuePair <string, string> > retVal = new List <KeyValuePair <string, string> >();

            if (filterList != null && filterList.Count > 0)
            {
                foreach (Filter f in filterList)
                {
                    Utility.addParameter(f.ToString(), "filter[]", retVal);
                }
            }
            return(retVal);
        }
示例#25
0
        /// <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));
        }
示例#26
0
        /// <summary>
        /// Add a list of tags to a list of hrefs. The tags must be either plain_tags or machine_tags. The hrefs can belong to various resource types. If a resource for a href could not be found, an error is returned and no tags are added for any resource.
        /// No error will be raised if the resource already has the tag(s) you are trying to add.
        /// Note: At this point, tags on 'next_instance' are not supported and one has to add tags to the 'server'.
        /// </summary>
        /// <param name="resourceHrefs">Hrefs of the resources for which the tags are to be added</param>
        /// <param name="tags">Tags to be added</param>
        /// <returns>True if successful, false if not</returns>
        public static bool multiAdd(List <string> resourceHrefs, List <Tag> tags)
        {
            List <KeyValuePair <string, string> > postParams = new List <KeyValuePair <string, string> >();

            foreach (string s in resourceHrefs)
            {
                Utility.addParameter(s, "resource_hrefs[]", postParams);
            }
            foreach (Tag t in tags)
            {
                Utility.addParameter(t.ToString(), "tags[]", postParams);
            }

            return(Core.APIClient.Instance.Post(APIHrefs.TagMultiAdd, postParams));
        }
示例#27
0
        /// <summary>
        /// Delete a list of tags on a list of hrefs. The tags must be either plain_tags or machine_tags. The hrefs can belong to various resource types. If a resource for a href could not be found, an error is returned and no tags are deleted for any resource.
        /// Note that no error will be raised if the resource does not have the tag(s) you are trying to delete
        /// </summary>
        /// <param name="resourceHrefs">hrefs of the resources for which tags are to be deleted</param>
        /// <param name="tags">Tags to be deleted</param>
        /// <returns>True if successful, false if not</returns>
        public static bool multiDelete(List <string> resourceHrefs, List <Tag> tags)
        {
            string postHref = "/api/tags/multi_delete";
            List <KeyValuePair <string, string> > postParams = new List <KeyValuePair <string, string> >();

            foreach (string s in resourceHrefs)
            {
                Utility.addParameter(s, "resource_hrefs[]", postParams);
            }
            foreach (Tag t in tags)
            {
                Utility.addParameter(t.ToString(), "tags[]", postParams);
            }
            return(Core.APIClient.Instance.Post(postHref, postParams));
        }
示例#28
0
        /// <summary>
        /// Private method to translate string arrays to convert to a parameter set
        /// </summary>
        /// <param name="filterList">array of string to push to a parameter set</param>
        /// <returns>list of keyvaluepairs for parameter inputs</returns>
        public static List <KeyValuePair <string, string> > StringArrayToParameterSet(string[] paramStrings, string paramName)
        {
            List <KeyValuePair <string, string> > retVal = new List <KeyValuePair <string, string> >();

            if (paramStrings != null && paramStrings.Length > 0)
            {
                foreach (string param in paramStrings)
                {
                    string thisparamName = string.Format("{0}[]", paramName);
                    //TODO:  I think this is not the correct format to pass, we don't need [] for each,  just one with multiple values
                    Utility.addParameter(param.ToString(), thisparamName, retVal);
                }
            }
            return(retVal);
        }
示例#29
0
        /// <summary>
        /// Update a user's information, including SSO information. In order to update a user, they must be linked to one of the identity
        /// </summary>
        /// <param name="userID">ID of the user being updated</param>
        /// <param name="currentEmail">The existing email of this user.</param>
        /// <param name="newEmail">The updated email of this user.</param>
        /// <param name="firstName">Updated First Name for user</param>
        /// <param name="lastName">Updated Last Name for user</param>
        /// <param name="phone">Updated phone for user</param>
        /// <param name="identityProviderID">The updated RightScale API href ID of the associated Identity Provider.</param>
        /// <param name="password">Updated password for user</param>
        /// <param name="principalUid">The updated principal identifier (SAML NameID or OpenID identity URL) of this user</param>
        /// <returns></returns>
        public static bool update(string userID, string currentEmail, string newEmail, string firstName, string lastName, string phone, string identityProviderID, string password, string principalUid)
        {
            string putHref = string.Format(APIHrefs.UserByID, userID);
            List <KeyValuePair <string, string> > paramSet = new List <KeyValuePair <string, string> >();

            Utility.CheckStringHasValue(currentEmail);
            Utility.addParameter(currentEmail, "user[current_email]", paramSet);
            Utility.addParameter(newEmail, "user[new_email]", paramSet);
            Utility.addParameter(firstName, "user[first_name]", paramSet);
            Utility.addParameter(lastName, "user[last_name]", paramSet);
            Utility.addParameter(phone, "user[phone]", paramSet);
            Utility.addParameter(Utility.identityProviderHref(identityProviderID), "user[identity_provider_href]", paramSet);
            Utility.addParameter(password, "user[password]", paramSet);
            Utility.addParameter(principalUid, "user[principal_uid]", paramSet);
            return(Core.APIClient.Instance.Put(putHref, paramSet));
        }
示例#30
0
        /// <summary>
        /// Gets tag for a specific resource.
        /// </summary>
        /// <param name="resource_hrefs">Set of hrefs to retrive tags from</param>
        /// <returns>Not sure yet</returns>
        public static List <Resource> byResource(List <string> resourceHrefs)
        {
            string queryString = string.Empty;

            List <KeyValuePair <string, string> > paramList = new List <KeyValuePair <string, string> >();

            foreach (string s in resourceHrefs)
            {
                Utility.addParameter(s, "resource_hrefs[]", paramList);
            }

            string        retVal = "content";
            List <string> tags   = Core.APIClient.Instance.Post(APIHrefs.TagByResource, paramList, null, out retVal);

            return(Resource.deserializeList(retVal));
        }