Class: Azure::Armrest::ResourceService

Inherits:
ArmrestService show all
Defined in:
lib/azure/armrest/resource_service.rb

Instance Attribute Summary collapse

Attributes inherited from ArmrestService

#api_version, #armrest_configuration, #base_url

Instance Method Summary collapse

Methods inherited from ArmrestService

configure, #get_provider, #get_subscription, #list_resource_groups, #list_resources, #list_subscriptions, #locations, #tags, #tenants

Constructor Details

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

Creates and returns a new ResourceService object.



9
10
11
# File 'lib/azure/armrest/resource_service.rb', line 9

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

Instance Attribute Details

#providerObject (readonly)

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



5
6
7
# File 'lib/azure/armrest/resource_service.rb', line 5

def provider
  @provider
end

Instance Method Details

#check_resource(resource_name, resource_type) ⇒ Object

Checks to see if the given ‘resource_name’ and ‘resource_type’ is allowed. This returns a JSON string that will indicate the status, including an error code and message on failure.

If you want a simple boolean check, use the check_resource? method instead.



59
60
61
62
63
64
65
66
# File 'lib/azure/armrest/resource_service.rb', line 59

def check_resource(resource_name, resource_type)
  body = JSON.dump(:Name => resource_name, :Type => resource_type)
  url = File.join(Azure::Armrest::RESOURCE, 'providers', provider, 'checkresourcename')
  url << "?api-version=#{@api_version}"

  response = rest_post(url, body)
  response.return!
end

#check_resource?(resource_name, resource_type) ⇒ Boolean

Similar to the check_resource method, but returns a boolean instead.

Returns:

  • (Boolean)


70
71
72
# File 'lib/azure/armrest/resource_service.rb', line 70

def check_resource?(resource_name, resource_type)
  check_resource(resource_name, resource_type)['status'] == 'Allowed'
end

#list(resource_group, options = {}) ⇒ Object

List all the resources for the current subscription in the specified resource group. You can optionally pass :top or :filter options as well to restrict returned results.

Examples:

rs = Azure::Armrest::ResourceService.new
rs.list(your_group, :top => 2)
rs.list(your_group, :filter => "location eq 'centralus'")


23
24
25
26
27
# File 'lib/azure/armrest/resource_service.rb', line 23

def list(resource_group, options = {})
  url = build_url(resource_group, options)
  response = rest_get(url)
  JSON.parse(response)['value'].map { |hash| Azure::Armrest::Resource.new(hash) }
end

#list_all(options = {}) ⇒ Object

Same as Azure::Armrest::ResourceService#list but returns all resources for all resource groups.



32
33
34
35
36
# File 'lib/azure/armrest/resource_service.rb', line 32

def list_all(options = {})
  url = build_url(nil, options)
  response = rest_get(url)
  JSON.parse(response)['value'].map { |hash| Azure::Armrest::Resource.new(hash) }
end

#move(source_group, source_subscription = configuration.subscription_id) ⇒ Object

Move the resources from source_group under source_subscription, which may be a different subscription.



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/azure/armrest/resource_service.rb', line 41

def move(source_group, source_subscription = configuration.subscription_id)
  url = File.join(
    Azure::Armrest::COMMON_URI, source_subscription,
    'resourcegroups', source_group, 'moveresources'
  )

  url << "?api-version=#{@api_version}"

  response = rest_post(url)
  response.return!
end