/// <summary>
        /// Get a default resource location for a given resource type
        /// </summary>
        /// <param name="client">The resource management client</param>
        /// <param name="resourceType">The type of resource to create</param>
        /// <returns>A location where this resource type is supported for the current subscription</returns>
        public static async Task <string> GetResourceLocation(ArmClient client, string resourceType, FeaturesInfo.Type feature = FeaturesInfo.Type.Default)
        {
            SubscriptionResource subscription = await client.GetDefaultSubscriptionAsync();

            HashSet <string> supportedLocations = null;

            switch (feature)
            {
            case FeaturesInfo.Type.Default:
                supportedLocations = FeaturesInfo.DefaultLocations;
                break;

            case FeaturesInfo.Type.All:
                supportedLocations = FeaturesInfo.AllFeaturesSupportedLocations;
                break;

            case FeaturesInfo.Type.IPv6:
                supportedLocations = FeaturesInfo.IPv6SupportedLocations;
                break;

            case FeaturesInfo.Type.MultiCA:
                supportedLocations = FeaturesInfo.DefaultLocations;
                break;
            }
            string[] parts                    = resourceType.Split('/');
            string   providerName             = parts[0];
            ResourceProviderResource provider = await subscription.GetResourceProviders().GetAsync(providerName);

            foreach (var resource in provider.Data.ResourceTypes)
            {
                if (string.Equals(resource.ResourceType, parts[1], StringComparison.OrdinalIgnoreCase))
                {
                    return(resource.Locations.FirstOrDefault(supportedLocations.Contains));
                }
            }

            return(null);
        }
Пример #2
0
        /// <summary>
        /// Get default resource location for a given resource type.
        /// Once all tests are moved away from depreciated version of Resource Manager, this method should be removed
        /// and "using Microsoft.Azure.Management.Resources" should be changed to "using Microsoft.Azure.Management.ResourceManager"
        /// </summary>
        /// <param name="client">The resource management client</param>
        /// <param name="resourceType">The type of resource to create</param>
        /// <returns>A location where this resource type is supported for the current subscription</returns>
        public static async Task <string> GetResourceLocation(ResourcesManagementClient client, ProvidersOperations providersOperations, string resourceType, FeaturesInfo.Type feature = FeaturesInfo.Type.Default)
        {
            HashSet <string> supportedLocations = null;

            switch (feature)
            {
            case FeaturesInfo.Type.Default:
                supportedLocations = FeaturesInfo.DefaultLocations;
                break;

            case FeaturesInfo.Type.All:
                supportedLocations = FeaturesInfo.AllFeaturesSupportedLocations;
                break;

            case FeaturesInfo.Type.Ipv6:
                supportedLocations = FeaturesInfo.Ipv6SupportedLocations;
                break;

            case FeaturesInfo.Type.MultiCA:
                supportedLocations = FeaturesInfo.DefaultLocations;
                break;
            }
            string[]            parts        = resourceType.Split('/');
            string              providerName = parts[0];
            Response <Provider> provider     = await providersOperations.GetAsync(providerName);

            foreach (var resource in provider.Value.ResourceTypes)
            {
                if (string.Equals(resource.ResourceType, parts[1], StringComparison.OrdinalIgnoreCase))
                {
                    return(resource.Locations.FirstOrDefault(supportedLocations.Contains));
                }
            }

            return(null);
        }