class Azure::Armrest::ResourceGroupService

Attributes

provider[R]

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

Public Class Methods

new(configuration, options = {}) click to toggle source

Creates and returns a new ResourceGroupService object.

Calls superclass method Azure::Armrest::ArmrestService::new
# File lib/azure/armrest/resource_group_service.rb, line 9
def initialize(configuration, options = {})
  super(configuration, 'resourceGroups', 'Microsoft.Resources', options)
end

Public Instance Methods

create(group, location, tags = nil) click to toggle source

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

# File lib/azure/armrest/resource_group_service.rb, line 44
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) click to toggle source

Delete a resource group from the current subscription.

# File lib/azure/armrest/resource_group_service.rb, line 55
def delete(group)
  url = build_url(group)
  response = rest_delete(url)
  response.return!
end
exists?(group) click to toggle source

Returns whether or not the given resource group exists.

# File lib/azure/armrest/resource_group_service.rb, line 15
def exists?(group)
  url = build_url(group)
  rest_head(url) and true
rescue Azure::Armrest::NotFoundException
  false
end
get(group) click to toggle source

Returns information for the given resource group.

# File lib/azure/armrest/resource_group_service.rb, line 63
def get(group)
  url = build_url(group)
  response = rest_get(url)
  Azure::Armrest::ResourceGroup.new(response)
end
list(options = {}) click to toggle source

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'")
# File lib/azure/armrest/resource_group_service.rb, line 32
def list(options = {})
  url = build_url
  url << "&$top=#{options[:top]}" if options[:top]
  url << "&$filter=#{options[:filter]}" if options[:filter]

  response = rest_get(url)
  Azure::Armrest::ArmrestCollection.create_from_response(response, Azure::Armrest::ResourceGroup)
end
update(group, tags) click to toggle source

Updates the tags for the given resource group.

# File lib/azure/armrest/resource_group_service.rb, line 71
def update(group, tags)
  body = {:tags => tags}.to_json
  url = build_url(group)
  response = rest_patch(url, body)
  response.return!
end

Private Instance Methods

build_url(group = nil, *args) click to toggle source
# File lib/azure/armrest/resource_group_service.rb, line 80
def build_url(group = nil, *args)
  url = File.join(base_url, 'resourcegroups')
  url = File.join(url, group) if group
  url = File.join(url, *args) unless args.empty?
  url << "?api-version=#{@api_version}"
end