Class: Azure::Armrest::ArmrestService

Inherits:
Object
  • Object
show all
Extended by:
Gem::Deprecate
Defined in:
lib/azure/armrest/armrest_service.rb

Overview

Abstract base class for the other service classes.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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.



36
37
38
39
40
41
42
43
44
45
# File 'lib/azure/armrest/armrest_service.rb', line 36

def initialize(armrest_configuration, service_name, default_provider, options)
  @armrest_configuration = armrest_configuration
  @service_name = service_name
  @provider = options[:provider] || default_provider

  # Base URL used for REST calls. Modify within method calls as needed.
  @base_url = Azure::Armrest::RESOURCE

  set_service_api_version(options, service_name)
end

Instance Attribute Details

#api_versionObject

The api-version string for this particular service



22
23
24
# File 'lib/azure/armrest/armrest_service.rb', line 22

def api_version
  @api_version
end

#armrest_configurationObject Also known as: configuration

Configuration to access azure APIs



11
12
13
# File 'lib/azure/armrest/armrest_service.rb', line 11

def armrest_configuration
  @armrest_configuration
end

#base_urlObject

Base url used for REST calls.



16
17
18
# File 'lib/azure/armrest/armrest_service.rb', line 16

def base_url
  @base_url
end

#providerObject

Provider for service specific API calls



19
20
21
# File 'lib/azure/armrest/armrest_service.rb', line 19

def provider
  @provider
end

Class Method Details

.configure(options) ⇒ Object

Returns a new Armrest::Configuration object.

This method is deprecated, but is provided for backwards compatibility.



28
29
30
# File 'lib/azure/armrest/armrest_service.rb', line 28

def self.configure(options)
  Azure::Armrest::Configuration.new(options)
end

Instance Method Details

#get_provider(provider) ⇒ Object Also known as: geo_locations, provider_info

Returns information about the specific provider namespace.



61
62
63
# File 'lib/azure/armrest/armrest_service.rb', line 61

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.



99
100
101
102
103
104
105
106
107
108
109
# File 'lib/azure/armrest/armrest_service.rb', line 99

def get_subscription(subscription_id = configuration.subscription_id)
  url = url_with_api_version(
    configuration.api_version,
    @base_url,
    'subscriptions',
    subscription_id
  )

  response = rest_get(url)
  Azure::Armrest::Subscription.new(response.body)
end

#list_resource_groupsObject Also known as: resource_groups

Returns an array of ResourceGroup objects for the current subscription.



131
132
133
# File 'lib/azure/armrest/armrest_service.rb', line 131

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.



118
119
120
121
122
123
124
# File 'lib/azure/armrest/armrest_service.rb', line 118

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_subscriptionsObject Also known as: subscriptions

Returns a list of Subscription objects for the tenant.



86
87
88
89
90
# File 'lib/azure/armrest/armrest_service.rb', line 86

def list_subscriptions
  url = url_with_api_version(configuration.api_version, @base_url, 'subscriptions')
  response = rest_get(url)
  JSON.parse(response.body)['value'].map { |hash| Azure::Armrest::Subscription.new(hash) }
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 provider_info method instead. –



77
78
79
80
81
82
# File 'lib/azure/armrest/armrest_service.rb', line 77

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

#tagsObject

Returns a list of tags for the current subscription.



140
141
142
143
144
145
146
147
148
149
150
# File 'lib/azure/armrest/armrest_service.rb', line 140

def tags
  url = url_with_api_version(
    configuration.api_version,
    @base_url,
    'subscriptions',
    configuration.subscription_id,
    'tagNames'
  )
  resp = rest_get(url)
  JSON.parse(resp.body)["value"].map{ |hash| Azure::Armrest::Tag.new(hash) }
end

#tenantsObject

Returns a list of tenants that can be accessed.



154
155
156
157
158
# File 'lib/azure/armrest/armrest_service.rb', line 154

def tenants
  url = url_with_api_version(configuration.api_version, @base_url, 'tenants')
  resp = rest_get(url)
  JSON.parse(resp.body)['value'].map{ |hash| Azure::Armrest::Tenant.new(hash) }
end