Class: Azure::Armrest::ArmrestService
- Inherits:
- 
      Object
      
        - Object
- Azure::Armrest::ArmrestService
 
- Extended by:
- Gem::Deprecate
- Defined in:
- lib/azure/armrest/armrest_service.rb
Overview
Abstract base class for the other service classes.
Direct Known Subclasses
Billing::UsageService, Insights::DiagnosticService, Insights::EventService, Insights::MetricsService, ResourceGroupBasedService, ResourceGroupService, ResourceProviderService, ResourceService, RoleService, SubscriptionService, VirtualMachineImageService
Instance Attribute Summary collapse
- 
  
    
      #api_version  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    The api-version string for this particular service. 
- 
  
    
      #armrest_configuration  ⇒ Object 
    
    
      (also: #configuration)
    
  
  
  
  
    
    
  
  
  
  
  
  
    Configuration to access azure APIs. 
- 
  
    
      #base_url  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Base url with subscription information used for most REST calls. 
- 
  
    
      #provider  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Provider for service specific API calls. 
- 
  
    
      #service_name  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    The service name for the Service class. 
Class Method Summary collapse
- 
  
    
      .configure(options)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Returns a new Armrest::Configuration object. 
Instance Method Summary collapse
- 
  
    
      #get_provider(provider)  ⇒ Object 
    
    
      (also: #geo_locations, #provider_info)
    
  
  
  
  
  
  
  
  
  
    Returns information about the specific provider namespace.
- 
  
    
      #get_subscription(subscription_id = configuration.subscription_id)  ⇒ Object 
    
    
      (also: #subscription_info)
    
  
  
  
  
  
  
  
  
  
    Return information for the specified subscription ID, or the subscription ID that was provided in the constructor if none is specified. 
- 
  
    
      #initialize(armrest_configuration, service_name, default_provider, options)  ⇒ ArmrestService 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    Do not instantiate directly. 
- 
  
    
      #list_locations  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Returns a list of Location objects for the current subscription. 
- 
  
    
      #list_resource_groups  ⇒ Object 
    
    
      (also: #resource_groups)
    
  
  
  
  
  
  
  
  
  
    Returns an array of ResourceGroup objects for the current subscription. 
- 
  
    
      #list_resources(resource_group = nil)  ⇒ Object 
    
    
      (also: #resources)
    
  
  
  
  
  
  
  
  
  
    Returns an array of Resource objects for the current subscription. 
- 
  
    
      #list_subscriptions  ⇒ Object 
    
    
      (also: #subscriptions)
    
  
  
  
  
  
  
  
  
  
    Returns a list of subscriptions for the current tenant. 
- 
  
    
      #locations(provider = nil)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Returns a list of all locations for all resource types of the given provider.
- 
  
    
      #poll(response)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Poll a resource and return its current operations status. 
- 
  
    
      #tags  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Returns a list of tags for the current subscription. 
- 
  
    
      #tenants  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Returns a list of tenants that can be accessed. 
- 
  
    
      #wait(response, max_time = 60, default_interval = 10)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Wait for the given responseto return a status of 'Succeeded', up to a maximum ofmax_timeseconds, and return the operations status.
Constructor Details
#initialize(armrest_configuration, service_name, default_provider, options) ⇒ ArmrestService
Do not instantiate directly. This is an abstract base class from which all other service classes should subclass, and call super within their own constructors.
| 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | # File 'lib/azure/armrest/armrest_service.rb', line 43 def initialize(armrest_configuration, service_name, default_provider, ) @armrest_configuration = armrest_configuration @service_name = service_name @provider = [:provider] || default_provider if configuration.subscription_id.nil? raise ArgumentError, 'subscription_id must be specified for this Service class' end # Base URL used for REST calls. Modify within method calls as needed. @base_url = File.join( configuration.environment.resource_url, 'subscriptions', configuration.subscription_id ) set_service_api_version(, service_name) end | 
Instance Attribute Details
#api_version ⇒ Object
The api-version string for this particular service
| 29 30 31 | # File 'lib/azure/armrest/armrest_service.rb', line 29 def api_version @api_version end | 
#armrest_configuration ⇒ Object Also known as: configuration
Configuration to access azure APIs
| 15 16 17 | # File 'lib/azure/armrest/armrest_service.rb', line 15 def armrest_configuration @armrest_configuration end | 
#base_url ⇒ Object
Base url with subscription information used for most REST calls.
| 20 21 22 | # File 'lib/azure/armrest/armrest_service.rb', line 20 def base_url @base_url end | 
#provider ⇒ Object
Provider for service specific API calls
| 23 24 25 | # File 'lib/azure/armrest/armrest_service.rb', line 23 def provider @provider end | 
#service_name ⇒ Object
The service name for the Service class
| 26 27 28 | # File 'lib/azure/armrest/armrest_service.rb', line 26 def service_name @service_name end | 
Class Method Details
.configure(options) ⇒ Object
Returns a new Armrest::Configuration object.
This method is deprecated, but is provided for backwards compatibility.
| 35 36 37 | # File 'lib/azure/armrest/armrest_service.rb', line 35 def self.configure() Azure::Armrest::Configuration.new() end | 
Instance Method Details
#get_provider(provider) ⇒ Object Also known as: geo_locations, provider_info
Returns information about the specific provider namespace.
| 72 73 74 | # File 'lib/azure/armrest/armrest_service.rb', line 72 def get_provider(provider) configuration.providers.find { |rp| rp.namespace.casecmp(provider) == 0 } end | 
#get_subscription(subscription_id = configuration.subscription_id) ⇒ Object Also known as: subscription_info
Return information for the specified subscription ID, or the subscription ID that was provided in the constructor if none is specified.
| 117 118 119 120 | # File 'lib/azure/armrest/armrest_service.rb', line 117 def get_subscription(subscription_id = configuration.subscription_id) subs = Azure::Armrest::SubscriptionService.new(configuration) subs.get(subscription_id) end | 
#list_locations ⇒ Object
Returns a list of Location objects for the current subscription.
| 99 100 101 102 103 | # File 'lib/azure/armrest/armrest_service.rb', line 99 def list_locations url = url_with_api_version(configuration.api_version, base_url, 'locations') response = rest_get(url) Azure::Armrest::ArmrestCollection.create_from_response(response, Location) end | 
#list_resource_groups ⇒ Object Also known as: resource_groups
Returns an array of ResourceGroup objects for the current subscription.
| 142 143 144 | # File 'lib/azure/armrest/armrest_service.rb', line 142 def list_resource_groups Azure::Armrest::ResourceGroupService.new(configuration).list end | 
#list_resources(resource_group = nil) ⇒ Object Also known as: resources
Returns an array of Resource objects for the current subscription. If a resource_group is provided, only list resources for that resource group.
| 129 130 131 132 133 134 135 | # File 'lib/azure/armrest/armrest_service.rb', line 129 def list_resources(resource_group = nil) if resource_group Azure::Armrest::ResourceService.new(configuration).list(resource_group) else Azure::Armrest::ResourceService.new(configuration).list_all end end | 
#list_subscriptions ⇒ Object Also known as: subscriptions
Returns a list of subscriptions for the current tenant.
| 106 107 108 | # File 'lib/azure/armrest/armrest_service.rb', line 106 def list_subscriptions Azure::Armrest::SubscriptionService.new(configuration).list end | 
#locations(provider = nil) ⇒ Object
Returns a list of all locations for all resource types of the given provider. If you do not specify a provider, then the locations for all providers will be returned.
If you need individual details on a per-provider basis, use the methods of the ResourceProviderService instead.
Deprecated.
| 89 90 91 92 93 | # File 'lib/azure/armrest/armrest_service.rb', line 89 def locations(provider = nil) list = configuration.providers list = list.select { |rp| rp.namespace.casecmp(provider) == 0 } if provider list.collect { |rp| rp.resource_types.map(&:locations) }.flatten.uniq.sort end | 
#poll(response) ⇒ Object
Poll a resource and return its current operations status. The response argument should be a ResponseHeaders object that contains the :azure_asyncoperation header. It may optionally be an object that returns a URL from a .to_s method.
This is meant to check the status of asynchronous operations, such as create or delete.
| 173 174 175 176 177 178 179 180 181 | # File 'lib/azure/armrest/armrest_service.rb', line 173 def poll(response) return 'Succeeded' if [200, 201].include?(response.response_code) url = response.try(:azure_asyncoperation) || response.try(:location) response = rest_get(url).body unless response.blank? status = JSON.parse(response)['status'] end status || 'Succeeded' # assume succeeded otherwise the wait method may hang end | 
#tags ⇒ Object
Returns a list of tags for the current subscription.
| 151 152 153 154 155 | # File 'lib/azure/armrest/armrest_service.rb', line 151 def url = url_with_api_version(configuration.api_version, base_url, 'tagNames') resp = rest_get(url) JSON.parse(resp.body)["value"].map{ |hash| Azure::Armrest::Tag.new(hash) } end | 
#tenants ⇒ Object
Returns a list of tenants that can be accessed.
| 159 160 161 162 163 | # File 'lib/azure/armrest/armrest_service.rb', line 159 def tenants url = url_with_api_version(configuration.api_version, configuration.environment.resource_url, 'tenants') resp = rest_get(url) JSON.parse(resp.body)['value'].map{ |hash| Azure::Armrest::Tenant.new(hash) } end | 
#wait(response, max_time = 60, default_interval = 10) ⇒ Object
Wait for the given response to return a status of 'Succeeded', up to a maximum of max_time seconds, and return the operations status. The first argument must be a ResponseHeaders object that contains the azure_asyncoperation header.
Internally this will poll the response header every :retry_after seconds (or 10 seconds if that header isn't found), up to a maximum of 60 seconds by default. There is no timeout limit if max_time is 0.
For most resources the max_time argument should be more than sufficient. Certain resources, such as virtual machines, could take longer.
| 195 196 197 198 199 200 201 202 203 204 205 206 | # File 'lib/azure/armrest/armrest_service.rb', line 195 def wait(response, max_time = 60, default_interval = 10) sleep_time = response.respond_to?(:retry_after) ? response.retry_after.to_i : default_interval total_time = 0 until (status = poll(response)) =~ /^succe/i # success or succeeded total_time += sleep_time break if max_time > 0 && total_time >= max_time sleep sleep_time end status end |