Class: Azure::Armrest::ResourceGroupService

Inherits:
ArmrestService show all
Defined in:
lib/azure/armrest/resource_group_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 = {}) ⇒ ResourceGroupService

Creates and returns a new ResourceGroupService object.



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

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’



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

def provider
  @provider
end

Instance Method Details

#create(group, location, tags = nil) ⇒ Object

Creates a new group in location for the current subscription. You may optionally apply tags.



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

def create(group, location, tags = nil)
  body = {:location => location, :tags => tags}.to_json
  url = build_url(group)

  response = rest_put(url, body)

  Azure::Armrest::ResourceGroup.new(response)
end

#delete(group) ⇒ Object

Delete a resource group from the current subscription.



47
48
49
50
51
# File 'lib/azure/armrest/resource_group_service.rb', line 47

def delete(group)
  url = build_url(group)
  response = rest_delete(url)
  response.return!
end

#get(group) ⇒ Object

Returns information for the given resource group.



55
56
57
58
59
# File 'lib/azure/armrest/resource_group_service.rb', line 55

def get(group)
  url = build_url(group)
  response = rest_get(url)
  Azure::Armrest::ResourceGroup.new(response)
end

#list(options = {}) ⇒ Object

List all the resources for the current subscription. You can optionally pass :top or :filter options as well to restrict returned results. The :filter option only applies to tags.

Examples:

rgs = ResourceGroupService.new
rgs.list(:top => 2)
rgs.list(:filter => "sometag eq 'value'")


23
24
25
26
27
28
29
30
31
# File 'lib/azure/armrest/resource_group_service.rb', line 23

def list(options = {})
  url = build_url
  url << "&$top=#{options[:top]}" if options[:top]
  url << "&$filter=#{options[:filter]}" if options[:filter]

  response = rest_get(url)

  JSON.parse(response)['value'].map { |hash| Azure::Armrest::ResourceGroup.new(hash) }
end

#update(group, tags) ⇒ Object

Updates the tags for the given resource group.



63
64
65
66
67
68
# File 'lib/azure/armrest/resource_group_service.rb', line 63

def update(group, tags)
  body = {:tags => tags}.to_json
  url = build_url(group)
  response = rest_patch(url, body)
  response.return!
end