CheckStringHasValue() public static method

Method checks to ensure that the string passed in has a value
public static CheckStringHasValue ( string requiredString ) : bool
requiredString string string to check
return bool
Ejemplo n.º 1
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>());
        }
Ejemplo n.º 2
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>());
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Lists subnets of a given cloud.
        /// </summary>
        /// <param name="cloudID">ID of the cloud where subnets are to be queried from</param>
        /// <param name="filter">Set of filters to limit the number of subnets returned</param>
        /// <returns>List of populated Subnet objects based on input filters</returns>
        public static List <Subnet> index(string cloudID, List <Filter> filter)
        {
            Utility.CheckStringHasValue(cloudID);
            string getHref = string.Format(APIHrefs.Subnet, cloudID);

            return(indexGet(filter, getHref));
        }
Ejemplo n.º 4
0
        /// <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>());
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Updates attributes of a given deployment.
        /// </summary>
        /// <param name="deploymentID">ID of the deployment to update</param>
        /// <param name="name">The updated name for the deployment</param>
        /// <param name="description">The updated description for the deployment</param>
        /// <param name="server_tag_scope">The routing scope for tags for servers in the deployment</param>
        /// <returns>True if update successful, false if not</returns>
        public static bool update(string deploymentID, string name, string description, string server_tag_scope)
        {
            Utility.CheckStringHasValue(deploymentID);
            string putHref = string.Format(APIHrefs.DeploymentByID, deploymentID);

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

            if (!string.IsNullOrWhiteSpace(name))
            {
                updateParams.Add(new KeyValuePair <string, string>("deployment[name]", name));
            }
            if (!string.IsNullOrWhiteSpace(description))
            {
                updateParams.Add(new KeyValuePair <string, string>("deployment[description]", description));
            }
            if (!string.IsNullOrWhiteSpace(server_tag_scope))
            {
                List <string> validValues = new List <string>()
                {
                    "deployment", "account"
                };
                Utility.CheckStringInput("server_tag_scope", validValues, server_tag_scope);
                updateParams.Add(new KeyValuePair <string, string>("deployment[server_tag_scope]", server_tag_scope));
            }
            if (updateParams.Count > 0)
            {
                return(Core.APIClient.Instance.Put(putHref, updateParams));
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 6
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>());
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Deletes a MultiCloudImage setting
        /// </summary>
        /// <param name="multiCloudImageID">ID of the MultiCloudImage</param>
        /// <param name="multiCloudImageSettingID">ID of the MultiCloudImageSetting</param>
        /// <returns></returns>
        public static bool destroy(string multiCloudImageID, string multiCloudImageSettingID)
        {
            Utility.CheckStringHasValue(multiCloudImageID);
            Utility.CheckStringHasValue(multiCloudImageSettingID);
            string deleteHref = string.Format(APIHrefs.MultiCloudImageSettingsByID, multiCloudImageID, multiCloudImageSettingID);

            return(Core.APIClient.Instance.Delete(deleteHref));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Lists subnets of a given cloud for a specific Instance.
        /// </summary>
        /// <param name="cloudID">ID of the cloud where subnets are to be queried from</param>
        /// <param name="instanceID">ID of the Instance where the subnet(s) is attached</param>
        /// <param name="filter">Set of filters to limit the number of subnets returned</param>
        /// <returns>List of populated Subnet objects based on input filters</returns>
        public static List <Subnet> index_Instance(string cloudID, string instanceID, List <Filter> filter)
        {
            Utility.CheckStringHasValue(cloudID);
            Utility.CheckStringHasValue(instanceID);
            string getHref = string.Format(APIHrefs.InstanceSubnetByID, cloudID, instanceID);

            return(indexGet(filter, getHref));
        }
Ejemplo n.º 9
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));
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Shows attributes of a signle subnet
        /// </summary>
        /// <param name="cloudID">ID of the cloud where the subnet is located</param>
        /// <param name="subnetID">ID of the subnet to be displayed</param>
        /// <returns>Instance of a populated Subnet object</returns>
        public static Subnet show(string cloudID, string subnetID)
        {
            Utility.CheckStringHasValue(cloudID);
            Utility.CheckStringHasValue(subnetID);
            string getHref    = string.Format(APIHrefs.SubnetByID, cloudID, subnetID);
            string jsonString = Core.APIClient.Instance.Get(getHref);

            return(deserialize(jsonString));
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Shows information about a single MultiCloudImage Setting
        /// </summary>
        /// <param name="multiCloudImageID">ID of the MultiCloudImage</param>
        /// <param name="multiCloudImageSettingID">ID of the MultiCloudImage Setting</param>
        /// <returns>Populated instance of MultiCloudImageSetting</returns>
        public static MultiCloudImageSetting show(string multiCloudImageID, string multiCloudImageSettingID)
        {
            Utility.CheckStringHasValue(multiCloudImageID);
            Utility.CheckStringHasValue(multiCloudImageSettingID);

            string getHref    = string.Format(APIHrefs.MultiCloudImageSettingsByID, multiCloudImageID, multiCloudImageSettingID);
            string jsonString = Core.APIClient.Instance.Get(getHref);

            return(deserialize(jsonString));
        }
Ejemplo n.º 12
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>());
        }
Ejemplo n.º 13
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));
        }
Ejemplo n.º 14
0
        public static DataCenter show(string cloudID, string dataCenterID)
        {
            Utility.CheckStringIsNumeric(cloudID);
            Utility.CheckStringHasValue(dataCenterID);

            string getURL = string.Format(APIHrefs.DataCenterByID, cloudID, dataCenterID);

            string jsonString = Core.APIClient.Instance.Get(getURL);

            return(deserialize(jsonString));
        }
Ejemplo n.º 15
0
 /// <summary>
 /// Private Method checks required inputs for formatting and existence within the AlertSpec.create process
 /// </summary>
 /// <param name="condition">The condition (operator) in the condition sentence.</param>
 /// <param name="duration">The duration in minutes of the condition sentence.</param>
 /// <param name="file">The RRD path/file_name of the condition sentence.</param>
 /// <param name="name">The name of the AlertSpec.</param>
 /// <param name="threshold">The threshold of the condition sentence.</param>
 /// <param name="variable">The RRD variable of the condition sentence.</param>
 /// <param name="vote_type">Vote to grow or shrink a ServerArray when the alert is triggered. Must either escalate or vote</param>
 private static void checkCreateInputs(string condition, string duration, string file, string name, string threshold, string variable, string vote_type)
 {
     Utility.CheckStringHasValue(duration);
     Utility.CheckStringIsNumeric(duration);
     Utility.CheckStringHasValue(file);
     Utility.CheckStringHasValue(name);
     Utility.CheckStringHasValue(threshold);
     Utility.CheckStringHasValue(variable);
     Utility.CheckStringHasValue(condition);
     checkInputFormatting(condition, vote_type);
 }
Ejemplo n.º 16
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>());
        }
Ejemplo n.º 17
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));
        }
Ejemplo n.º 18
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));
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Deletes old backups that meet the given criteria. For example, if a user calls cleanup with keep monthlies set to 12, then the latest backup for each month, for 12 months, will be kept.
        /// </summary>
        /// <param name="lineage">The lineage of the backups that are to be cleaned-up</param>
        /// <param name="keepLast">The number of backups that should be kept</param>
        /// <param name="cloudID">Backups belonging to only this cloud are considered for cleanup. Otherwise, all backups in the account with the same lineage will be considered</param>
        /// <param name="dailies">The number of daily backups(the latest one in each day) that should be kept</param>
        /// <param name="weeklies">The number of weekly backups(the latest one in each week) that should be kept</param>
        /// <param name="monthlies">The number of monthly backups(the latest one in each month) that should be kept</param>
        /// <param name="yearlies">The number of yearly backups(the latest one in each year) that should be kept</param>
        /// <returns>true if succesful, false if not</returns>
        public static bool cleanup(string lineage, int keepLast, string cloudID, int dailies, int weeklies, int monthlies, int yearlies)
        {
            Utility.CheckStringHasValue(lineage);

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

            Utility.addParameter(keepLast, "keep_last", postParams);
            Utility.addParameter(string.Format(APIHrefs.CloudByID, cloudID), "cloud_href", postParams);
            Utility.addParameter(dailies, "dailies", postParams);
            Utility.addParameter(lineage, "lineage", postParams);
            Utility.addParameter(monthlies, "monthlies", postParams);
            Utility.addParameter(weeklies, "weeklies", postParams);
            Utility.addParameter(yearlies, "yearlies", postParams);

            return(Core.APIClient.Instance.Post(APIHrefs.BackupCleanup, postParams));
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Restores the given Backup
        /// </summary>
        /// <param name="backupID">ID of the backup to restore</param>
        /// <param name="instanceID">ID of the instance that the backup will be restored to</param>
        /// <param name="name">Each volume is created with this name instead of the volume snapshot's name</param>
        /// <param name="description">Each volume is created with this description instead of the volume snapshot's description</param>
        /// <param name="size">Each volume is created with this size in gigabytes (GB) instead of the volume snapshot's size (must be equal or larger). Some volume types have predefined sizes and do not allow selecting a custom size on volume creation</param>
        /// <param name="volumeTypeID">The ID of the volume type. Each volume is created with this volume type instead of the default volume type for the cloud. A Name, Resource UID and optional Size is associated with a volume type</param>
        /// <param name="iops">The number of IOPS (I/O Operations Per Second) each volume should support. Only available on clouds supporting performance provisioning</param>
        /// <returns>ID of the Task to follow the status</returns>
        public static string restore(string backupID, string instanceID, string name, string description, int size, string volumeTypeID, int iops)
        {
            Utility.CheckStringHasValue(instanceID);
            Utility.CheckStringHasValue(backupID);

            string postHref = string.Format(APIHrefs.BackupByID, backupID);
            List <KeyValuePair <string, string> > postParams = new List <KeyValuePair <string, string> >();

            Utility.addParameter(description, "backup[description]", postParams);
            Utility.addParameter(iops, "backup[iops]", postParams);
            Utility.addParameter(name, "backup[name]", postParams);
            Utility.addParameter(size, "backup[size]", postParams);
            Utility.addParameter(string.Format(APIHrefs.VolumeTypeByID, volumeTypeID), "backup[volume_type_href]", postParams);
            Utility.addParameter(string.Format(APIHrefs.InstanceByID, instanceID), "instance_href", postParams);
            return(Core.APIClient.Instance.Post(postHref, postParams, "location").Last <string>().Split('/').Last <string>());
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Gives the raw monitoring data for a particular metric. The response will include different variables associated with that metric and the data points for each of those variables.
        /// To get the data for a certain duration, for e.g. for the last 10 minutes(600 secs), provide the variables start="-600" and end="0".
        /// </summary>
        /// <param name="cloudID">ID of the Cloud where the Instance can be found to gather MonitoringMetric data from</param>
        /// <param name="instanceID">ID of the Instance from which to gather MonitoringMetric data</param>
        /// <param name="metricID">Name/ID of the MonitoringMetric whose data is to be retrieved</param>
        /// <param name="endRefSecs">An integer number of seconds from current time e.g. -150 or 0</param>
        /// <param name="startRefSecs">An integer number of seconds from current time e.g. -300</param>
        /// <returns>Data for specific monitoring metric for the given instance between the reference times</returns>
        public static MonitoringMetricData data(string cloudID, string instanceID, string metricID, string endRefSecs, string startRefSecs)
        {
            string getHref = string.Format(APIHrefs.MonitoringMetricData, cloudID, instanceID, metricID);

            Utility.CheckStringHasValue(startRefSecs);
            Utility.CheckStringRegex("startRefSecs", monitoringMetricTimeRegex, startRefSecs);
            Utility.CheckStringHasValue(endRefSecs);
            Utility.CheckStringRegex("endRefSecs", monitoringMetricTimeRegex, endRefSecs);
            string queryString = string.Empty;

            queryString += string.Format("end={0}&", endRefSecs);
            queryString += string.Format("start={0}", startRefSecs);

            string jsonString = Core.APIClient.Instance.Get(getHref, queryString);

            return(MonitoringMetricData.deserialize(jsonString));
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Creates a new volume
        /// </summary>
        /// <param name="cloudID">The Cloud ID of the cloud where this volume will be created</param>
        /// <param name="name">The name for the Volume to be created</param>
        /// <param name="datacenterID">The ID of the datacenter that this Volume will be in</param>
        /// <param name="description">The description of the Volume to be created</param>
        /// <param name="iops">The number of IOPS this volume should support</param>
        /// <param name="parentVolumeID">ID of parent volume</param>
        /// <param name="parentVolumeSnapshotID">ID of parent volume snapshot</param>
        /// <param name="size">Size of volume in GB</param>
        /// <param name="volumeTypeID">VolumeType ID</param>
        /// <returns>Volume ID</returns>
        public static string create(string cloudID, string name, string datacenterID, string description, string iops, string parentVolumeID, string parentVolumeSnapshotID, string size, string volumeTypeID)
        {
            Utility.CheckStringHasValue(name);
            List <KeyValuePair <string, string> > postParams = new List <KeyValuePair <string, string> >();

            Utility.addParameter(name, "volume[name]", postParams);
            Utility.addParameter(Utility.datacenterHref(cloudID, datacenterID), "volume[datacenter_href]", postParams);
            Utility.addParameter(description, "volume[description]", postParams);
            Utility.addParameter(iops, "volume[iops]", postParams);
            Utility.addParameter(size, "volume[size]", postParams);
            Utility.addParameter(Utility.volumeSnapshotHref(cloudID, parentVolumeID, parentVolumeSnapshotID), "volume[parent_volume_snapshot_href]", postParams);
            Utility.addParameter(Utility.volumeTypeHrefByID(cloudID, volumeTypeID), "volume[volume_type_href]", postParams);

            string        postString = string.Format(APIHrefs.Volume, cloudID);
            List <string> retVals    = Core.APIClient.Instance.Post(postString, postParams, "location");

            return(retVals.Last <string>().Split('/').Last <string>());
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Takes in an array of volumeattachment IDs and takes a snapshot of each. The volumeattachment IDs must belong to the same instance.
        /// </summary>
        /// <param name="name">The name to be set on each of the volume snapshots</param>
        /// <param name="volumeAttachmentIDs">List of volume attachment IDs that are to be backed-up</param>
        /// <param name="lineage">A unique value to create backups belonging to a particular system. This will be used to set the tag e.g. 'rs_backup:lineage=prod_mysqldb'</param>
        /// <param name="description">The description to be set on each of the volume snapshots</param>
        /// <param name="fromMaster">Setting this to 'true' will create a tag 'rs_backup:from_master=true' on the snapshots so that one can filter them later</param>
        /// <returns>ID of the newly created Backup object</returns>
        public static string create(string name, List <string> volumeAttachmentIDs, string lineage, string description, bool fromMaster)
        {
            Utility.CheckStringHasValue(name);
            Utility.CheckStringHasValue(lineage);
            if (volumeAttachmentIDs == null || volumeAttachmentIDs.Count == 0)
            {
                throw new ArgumentException("VolumeAttachmentID collection did not contain any VolumeAttachment IDs");
            }

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

            Utility.addParameter(name, "backup[name]", postParams);
            Utility.addParameter(lineage, "backup[lineage]", postParams);
            foreach (string vaid in volumeAttachmentIDs)
            {
                Utility.addParameter("backup[volume_attachment_hrefs]", string.Format(APIHrefs.VolumeAttachmentByID, vaid), postParams);
            }
            Utility.addParameter(description, "backup[description]", postParams);
            Utility.addParameter(fromMaster.ToString().ToLower(), "backup[from_master]", postParams);
            return(Core.APIClient.Instance.Post(APIHrefs.Backup, postParams, "location").Last <string>().Split('/').Last <string>());
        }
Ejemplo n.º 24
0
        /// Lists all of the backups with the given lineage tag. Filters can be used to search for a particular backup. If the 'latest_before' filter is set, only one backup is returned (the latest backup before the given timestamp).
        /// To get the latest completed backup, the 'completed' filter should be set to 'true' and the 'latest_before' filter should be set to the current timestamp. The format of the timestamp must be YYYY/MM/DD HH:MM:SS [+/-]ZZZZ e.g. 2011/07/11 00:00:00 +0000.
        /// To get the latest completed backup just before, say 25 June 2009, then the 'completed' filter should be set to 'true' and the 'latest_before' filter should be set to 2009/06/25 00:00:00 +0000.
        /// <param name="filter">Filters limiting the return set from the API</param>
        /// <param name="lineage">Backups belonging to this lineage</param>
        /// <returns>Collection of Backup objects</returns>
        public static List <Backup> index(List <Filter> filter, string lineage)
        {
            Utility.CheckStringHasValue(lineage);
            List <string> validFilters = new List <string>()
            {
                "cloud_href", "committed", "completed", "from_master", "latest_before"
            };

            Utility.CheckFilterInput("filter", validFilters, filter);
            string queryString = string.Empty;

            if (filter != null && filter.Count > 0)
            {
                foreach (Filter f in filter)
                {
                    queryString += f.ToString() + "&";
                }
            }
            queryString += string.Format("lineage={0}", lineage);
            string jsonString = Core.APIClient.Instance.Get(APIHrefs.Backup, queryString);

            return(deserializeList(jsonString));
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Lists the MultiCloudImageSettings for a MultiCloudImage
        /// </summary>
        /// <param name="multiCloudImageID">ID of the MultiCloudImage to query</param>
        /// <returns>List of MultiCloudImageSettings</returns>
        public static List <MultiCloudImageSetting> index(string multiCloudImageID)
        {
            Utility.CheckStringHasValue(multiCloudImageID);

            return(index(multiCloudImageID, null));
        }
Ejemplo n.º 26
0
 /// <summary>
 /// Creates a new generic cloud setting for an existing MultiCloudImage
 /// </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>
 /// <returns>ID of newly created MultiCloudImageSetting</returns>
 public static string create(string multiCloudImageID, string cloudID, string imageID, string instanceTypeID)
 {
     Utility.CheckStringHasValue(multiCloudImageID);
     return(create(multiCloudImageID, cloudID, imageID, instanceTypeID, string.Empty, string.Empty, string.Empty));
 }