BuildFilterString() public static method

Static method takes a collection of name/value pairs and creates a properly formatted string representing a set of filters for a given RightScale API call
public static BuildFilterString ( List filterSet ) : string
filterSet List list of key value pairs to be built into a filter string when passing filters to the RightScale API
return string
Ejemplo n.º 1
0
        /// <summary>
        /// Lists instance types.
        /// </summary>
        /// <param name="cloudID">ID of the cloud to enumerate instance types for</param>
        /// <param name="filter">Collection of filters for limiting the return set</param>
        /// <param name="view">Specifies how many attributes and/or expanded nested relationships to include</param>
        /// <returns>Collection of InstanceTypes</returns>
        public static List <InstanceType> index(string cloudID, List <Filter> filter, string view)
        {
            string getHref = string.Format(APIHrefs.InstanceType, cloudID);

            if (string.IsNullOrWhiteSpace(view))
            {
                view = "default";
            }
            else
            {
                List <string> validViews = new List <string>()
                {
                    "default"
                };
                Utility.CheckStringInput("view", validViews, view);
            }

            List <string> validFilters = new List <string>()
            {
                "cpu_architecture", "description", "name", "resource_uid"
            };

            Utility.CheckFilterInput("filter", validFilters, filter);

            string queryString = string.Empty;

            if (filter != null && filter.Count > 0)
            {
                queryString += Utility.BuildFilterString(filter);
            }
            queryString += string.Format("view={0}", view);
            string jsonString = Core.APIClient.Instance.Get(getHref, queryString);

            return(deserializeList(jsonString));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Private implementation to centrally manage all calls to index AlertSpecs
        /// </summary>
        /// <param name="getHref">RightScale API Href fragment for indexing AlertSpecs</param>
        /// <param name="filter">Filters for querying AlertSpecs</param>
        /// <param name="view">View name for querying AlertSpecs</param>
        /// <returns>collection of AlertSpecs</returns>
        private static List <AlertSpec> indexGet(string getHref, List <Filter> filter, string view)
        {
            if (string.IsNullOrWhiteSpace(view))
            {
                view = "default";
            }
            else
            {
                List <string> validViews = new List <string>()
                {
                    "default"
                };
                Utility.CheckStringInput("view", validViews, view);
            }

            List <string> validFilters = new List <string>()
            {
                "description", "escalation_name", "name", "subject_href"
            };

            Utility.CheckFilterInput("filter", validFilters, filter);

            string queryString = Utility.BuildFilterString(filter);

            if (!string.IsNullOrEmpty(view))
            {
                queryString += string.Format("view={0}", view);
            }

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

            return(deserializeList(jsonString));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Lists deployments of the account.
        /// Using the available filters, one can select or group which deployments to retrieve. The 'inputs20' view is for retrieving inputs in 2.0 serialization
        /// </summary>
        /// <param name="filter">list of KeyValuePair(string,string) to use as filters to query for deployments</param>
        /// <param name="view">name of the view to be returned</param>
        /// <returns>collection of Deployment objects</returns>
        public static List <Deployment> index(List <Filter> filter, string view)
        {
            string getHref = APIHrefs.Deployment;

            if (string.IsNullOrWhiteSpace(view))
            {
                view = "default";
            }
            else
            {
                List <string> validViews = new List <string>()
                {
                    "default", "inputs", "inputs_2_0"
                };
                Utility.CheckStringInput("view", validViews, view);
            }

            List <string> validFilters = new List <string>()
            {
                "description", "name", "server_tag_scope"
            };

            Utility.CheckFilterInput("filter", validFilters, filter);

            string queryStringValue = string.Empty;

            queryStringValue += string.Format("view={0}&", view);
            queryStringValue += Utility.BuildFilterString(filter);

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

            return(deserializeList(jsonString));
        }
Ejemplo n.º 4
0
        private static List <MultiCloudImage> indexGet(List <Filter> filterList, string getUrl)
        {
            string queryString = string.Empty;

            List <string> validFilters = new List <string>()
            {
                "name", "description", "revision"
            };

            Utility.CheckFilterInput("filter", validFilters, filterList);

            if (filterList != null && filterList.Count > 0)
            {
                queryString += Utility.BuildFilterString(filterList) + "&";
            }

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

            return(deserializeList(jsonString));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// An IpAddress provides an abstraction for IPv4 addresses bindable to Instance resources running in a Cloud.
        /// </summary>
        /// <param name="cloudID">ID of the Cloud where IP addresses are to be retrieved from</param>
        /// <param name="filter">Set of filters for querying IP Addresses</param>
        /// <returns>Collection of IPAddress objects</returns>
        public static List <IPAddress> index(string cloudID, List <Filter> filter)
        {
            string getHref = string.Format("/api/clouds/{0}/ip_addresses", cloudID);

            List <string> validFilters = new List <string>()
            {
                "name"
            };

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

            if (filter != null && filter.Count > 0)
            {
                queryString = Utility.BuildFilterString(filter);
            }
            string jsonString = Core.APIClient.Instance.Get(getHref, queryString);

            return(deserializeList(jsonString));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Lists all Datacenters for a particular cloud.
        /// </summary>
        /// <param name="cloudID">ID of cloud to enumerate DataCenters for</param>
        /// <param name="filter">Filter set to limit return data</param>
        /// <param name="view">Specifies how many attributes and/or expanded nested relationships to include.</param>
        /// <returns>Collection of DataCenter objects</returns>
        public static List <DataCenter> index(string cloudID, List <Filter> filter, string view)
        {
            string getHref = string.Format(APIHrefs.DataCenter, cloudID);

            if (string.IsNullOrWhiteSpace(view))
            {
                view = "default";
            }
            else
            {
                List <string> validViews = new List <string>()
                {
                    "default"
                };
                Utility.CheckStringInput("view", validViews, view);
            }

            List <string> validFilters = new List <string>()
            {
                "name", "resource_uid"
            };

            Utility.CheckFilterInput("filter", validFilters, filter);

            string queryString = string.Empty;

            queryString += Utility.BuildFilterString(filter);

            if (!string.IsNullOrWhiteSpace(view))
            {
                queryString += string.Format("&view={0}", view);
            }

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

            if (jsonString.ToLower().Contains("unsupported resource"))
            {
                throw new RightScaleAPIException("RightScale API Unsupported Exception", getHref + queryString, jsonString);
            }
            return(deserializeList(jsonString));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Lists the AccountGroups owned by this Account.
        /// </summary>
        /// <param name="filter">Set of filters to modify query to return AccountGroups from RightScale API</param>
        /// <param name="view">Defines specific view to limit the AccountGroups returned from RightScale API</param>
        /// <returns>Filtered list of AccuntGroups based on filter and view input</returns>
        public static List <AccountGroup> index(List <Filter> filter, string view)
        {
            if (string.IsNullOrWhiteSpace(view))
            {
                view = "default";
            }
            else
            {
                List <string> validViews = new List <string>()
                {
                    "default"
                };
                Utility.CheckStringInput("view", validViews, view);
            }

            List <string> validFilters = new List <string>()
            {
                "name"
            };

            Utility.CheckFilterInput("filter", validFilters, filter);

            string getUrl      = "/api/account_groups";
            string queryString = string.Empty;

            if (filter != null && filter.Count > 0)
            {
                queryString += Utility.BuildFilterString(filter);
            }

            queryString += string.Format("view={0}", view);

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

            return(deserializeList(jsonString));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Lists the ServerTemplateMultiCloudImages that are available to this account
        /// </summary>
        /// <param name="filter">Set of filters to limit return of query</param>
        /// <param name="view">Specifies how many attributes and/or expanded nested relationships to include</param>
        /// <returns>List of ServerTemplateMultiCloudImage objects</returns>
        public static List <ServerTemplateMultiCloudImage> index(List <Filter> filter, string view)
        {
            if (string.IsNullOrWhiteSpace(view))
            {
                view = "default";
            }
            else
            {
                List <string> validViews = new List <string>()
                {
                    "default"
                };
                Utility.CheckStringInput("view", validViews, view);
            }

            List <string> validFilters = new List <string>()
            {
                "is_default", "multi_cloud_image_href", "server_template_href"
            };

            Utility.CheckFilterInput("filter", validFilters, filter);

            string queryString = string.Empty;

            if (filter != null && filter.Count > 0)
            {
                queryString += Utility.BuildFilterString(filter) + "&";
            }

            queryString += string.Format("view={0}", view);

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

            return(deserializeList(jsonString));
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Lists AuditEntries of the account. Due to the potentially large number of audit entries, a start and end date must be provided during an index call to limit the search. The format of the dates must be YYYY/MM/DD HH:MM:SS [+/-]ZZZZ e.g. 2011/07/11 00:00:00 +0000. A maximum of 1000 records will be returned by each index call.
        /// Using the available filters, one can select or group which audit entries to retrieve.
        /// </summary>
        /// <param name="filter">Filter parameters for index query</param>
        /// <param name="view">Specifies how many attributes and/or expanded nested relationships to include.</param>
        /// <param name="limit">Limit the audit entries to this number. The limit should >= 1 and <= 1000</param>
        /// <param name="start_date">The start date for retrieving audit entries</param>
        /// <param name="end_date">The end date for retrieving audit entries (the format must be the same as start date). The time period between start and end date must be less than 3 months (93 days).</param>
        /// <returns>Collection of AuditEntry objects from the start_time defined with a limit, filter and view as specified</returns>
        public static List <AuditEntry> index(List <Filter> filter, string view, string limit, DateTime start_date, DateTime end_date)
        {
            if (string.IsNullOrWhiteSpace(view))
            {
                view = "default";
            }
            else
            {
                List <string> validViews = new List <string>()
                {
                    "default"
                };
                Utility.CheckStringInput("view", validViews, view);
            }

            List <string> validFilters = new List <string>()
            {
                "auditee_href", "user_email"
            };

            Utility.CheckFilterInput("filter", validFilters, filter);

            int intCheck;

            if (Int32.TryParse(limit, out intCheck))
            {
                if (intCheck >= 1 && intCheck <= 1000)
                {
                    //this is a good thing... should trace this out
                }
                else
                {
                    throw new ArgumentOutOfRangeException("Input 'limit' was out of bounds.  Limit cannot be less than 1 or greater than 1000: value = " + limit);
                }
            }
            else
            {
                throw new ArgumentException("Input 'limit' was non-numeric: {" + limit + "}");
            }

            if (end_date.Subtract(start_date).Days > 93)
            {
                throw new ArgumentException(string.Format("The difference between the start date [{0}] and the end date [{1}] must not be greater than 93 days", start_date, end_date));
            }

            string timeOffset = DateTime.Now.ToString("%K").Replace(":", "");

            string startDateString = start_date.ToString("yyyy/MM/dd HH:mm:ss ") + timeOffset;
            string endDateString   = end_date.ToString("yyyy/MM/dd HH:mm:ss ") + timeOffset;

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

            getParams.Add(new KeyValuePair <string, string>("end_date", endDateString));
            getParams.Add(new KeyValuePair <string, string>("limit", limit));
            getParams.Add(new KeyValuePair <string, string>("start_date", startDateString));
            if (!string.IsNullOrWhiteSpace(view))
            {
                getParams.Add(new KeyValuePair <string, string>("view", view));
            }

            string queryString = Utility.BuildGetQueryString(getParams);

            if (filter != null && filter.Count > 0)
            {
                queryString += Utility.BuildFilterString(filter);
            }

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

            return(deserializeList(jsonString));
        }