class Azure::Armrest::ResourceProviderService
Attributes
The provider used in http requests. The default is ‘Microsoft.Resources’
Public Class Methods
Creates and returns a new ResourceProviderService
object.
Note that many ResourceProviderService
instance methods are cached.
You can also set the provider. The default is ‘Microsoft.Resources’.
Azure::Armrest::ArmrestService::new
# File lib/azure/armrest/resource_provider_service.rb, line 15 def initialize(configuration, options = {}) super(configuration, 'resourceGroups', 'Microsoft.Resources', options) end
Public Instance Methods
Return information about a specific namespace
provider. The results of this method are cached.
# File lib/azure/armrest/resource_provider_service.rb, line 68 def get(namespace) url = build_url(namespace) body = rest_get(url).body Azure::Armrest::ResourceProvider.new(body) end
List all the providers for the current subscription. The results of this method are cached.
# File lib/azure/armrest/resource_provider_service.rb, line 22 def list(options = {}) url = build_url url << "&$top=#{options[:top]}" if options[:top] url << "&$expand=#{options[:expand]}" if options[:expand] response = rest_get(url) resources = JSON.parse(response)['value'] resources.map{ |hash| Azure::Armrest::ResourceProvider.new(hash) } end
List all the providers for Azure
. This may include results that are not available for the current subscription. The results of this method are cached.
The options
hash takes the following options:
-
:top => Limit the result set to the top x results.
-
:expand => Additional properties to include in the results.
Examples:
rps.list_all # Get everything rps.list_all(:top => 3) # Get first 3 results rps.list_all(:expand => 'metadata') # Include metadata in results
# File lib/azure/armrest/resource_provider_service.rb, line 50 def list_all(options = {}) url = File.join(configuration.environment.resource_url, 'providers') url << "?api-version=#{@api_version}" url << "&$top=#{options[:top]}" if options[:top] url << "&$expand=#{options[:expand]}" if options[:expand] response = rest_get(url) resources = JSON.parse(response)['value'] resources.map{ |hash| Azure::Armrest::ResourceProvider.new(hash) } end
Returns an array of supported api-versions for the given service_name
under the specified namespace
provider.
The results of this method are cached.
Example:
rps.list_api_versions('Microsoft.Resources', 'deployments')
# File lib/azure/armrest/resource_provider_service.rb, line 95 def list_api_versions(namespace, service_name) url = build_url(namespace) response = rest_get(url) JSON.parse(response)['resourceTypes'].find{ |type| type['resourceType'].casecmp(service_name) == 0 }['apiVersions'] rescue NoMethodError raise ArgumentError, "unable to find data for the '#{namespace}/#{service_name}' resource type" end
Returns an array of geo-locations for the given namespace
provider. The results of this method are cached.
# File lib/azure/armrest/resource_provider_service.rb, line 79 def list_geo_locations(namespace) url = build_url(namespace) response = rest_get(url) JSON.parse(response)['resourceTypes'].first['locations'] end
Register the current subscription with the namespace
provider.
# File lib/azure/armrest/resource_provider_service.rb, line 107 def register(namespace) url = build_url(namespace, 'register') rest_post(url) nil end
Returns whether or not the namespace
provider is registered. If the provider cannot be found, false is returned.
# File lib/azure/armrest/resource_provider_service.rb, line 124 def registered?(namespace) get(namespace).registration_state.casecmp("registered").zero? rescue Azure::Armrest::NotFoundException false end
Returns whether or not the given resource_type
is supported by the given namespace
. By default it will search the Microsoft.Compute namespace.
The results of this method are cached.
# File lib/azure/armrest/resource_provider_service.rb, line 136 def supported?(resource_type, namespace = 'Microsoft.Compute') get(namespace).resource_types.map(&:resource_type).map(&:downcase).include?(resource_type.downcase) end
Unregister the current subscription from the namespace
provider.
# File lib/azure/armrest/resource_provider_service.rb, line 115 def unregister(namespace) url = build_url(namespace, 'unregister') rest_post(url) nil end
Private Instance Methods
# File lib/azure/armrest/resource_provider_service.rb, line 144 def build_url(namespace = nil, *args) url = File.join(base_url, 'providers') url = File.join(url, namespace) if namespace url = File.join(url, *args) unless args.empty? url << "?api-version=#{@api_version}" end