Class: Azure::Armrest::ResourceProviderService

Inherits:
ArmrestService show all
Extended by:
Memoist
Defined in:
lib/azure/armrest/resource_provider_service.rb

Instance Attribute Summary collapse

Attributes inherited from ArmrestService

#api_version, #armrest_configuration, #base_url, #service_name

Instance Method Summary collapse

Methods inherited from ArmrestService

configure, #get_provider, #get_subscription, #list_locations, #list_resource_groups, #list_resources, #list_subscriptions, #locations, #poll, #tags, #tenants, #wait

Constructor Details

#initialize(configuration, options = {}) ⇒ ResourceProviderService

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’.



15
16
17
# File 'lib/azure/armrest/resource_provider_service.rb', line 15

def initialize(configuration, options = {})
  super(configuration, 'resourceGroups', 'Microsoft.Resources', options)
end

Instance Attribute Details

#providerObject (readonly)

The provider used in http requests. The default is ‘Microsoft.Resources’



7
8
9
# File 'lib/azure/armrest/resource_provider_service.rb', line 7

def provider
  @provider
end

Instance Method Details

#get(namespace) ⇒ Object

Return information about a specific namespace provider. The results of this method are cached.



68
69
70
71
72
# 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(options = {}) ⇒ Object

List all the providers for the current subscription. The results of this method are cached.



22
23
24
25
26
27
28
29
30
31
# 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(options = {}) ⇒ Object

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


50
51
52
53
54
55
56
57
58
59
60
61
# 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

#list_api_versions(namespace, service_name) ⇒ Object

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')


95
96
97
98
99
100
101
# 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

#list_geo_locations(namespace) ⇒ Object

Returns an array of geo-locations for the given namespace provider. The results of this method are cached.



79
80
81
82
83
# 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(namespace) ⇒ Object

Register the current subscription with the namespace provider.



107
108
109
110
111
# File 'lib/azure/armrest/resource_provider_service.rb', line 107

def register(namespace)
  url = build_url(namespace, 'register')
  rest_post(url)
  nil
end

#registered?(namespace) ⇒ Boolean

Returns whether or not the namespace provider is registered. If the provider cannot be found, false is returned.

Returns:

  • (Boolean)


124
125
126
127
128
# 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

#supported?(resource_type, namespace = 'Microsoft.Compute') ⇒ Boolean

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.

Returns:

  • (Boolean)


136
137
138
# 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(namespace) ⇒ Object

Unregister the current subscription from the namespace provider.



115
116
117
118
119
# File 'lib/azure/armrest/resource_provider_service.rb', line 115

def unregister(namespace)
  url = build_url(namespace, 'unregister')
  rest_post(url)
  nil
end