Class: Azure::Armrest::ResourceGroupBasedService

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

Overview

Base class for services that need to run in a resource group

Instance Attribute Summary

Attributes inherited from ArmrestService

#api_version, #armrest_configuration, #base_url, #provider

Instance Method Summary collapse

Methods inherited from ArmrestService

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

Constructor Details

This class inherits a constructor from Azure::Armrest::ArmrestService

Instance Method Details

#create(name, rgroup = configuration.resource_group, options = {}) ⇒ Object Also known as: update



5
6
7
8
9
10
11
12
13
# File 'lib/azure/armrest/resource_group_based_service.rb', line 5

def create(name, rgroup = configuration.resource_group, options = {})
  validate_resource_group(rgroup)
  validate_resource(name)

  url = build_url(rgroup, name)
  url = yield(url) || url if block_given?
  response = rest_put(url, options.to_json)
  model_class.new(response) unless response.empty?
end

#delete(name, rgroup = configuration.resource_group) ⇒ Object



53
54
55
56
57
58
59
60
61
# File 'lib/azure/armrest/resource_group_based_service.rb', line 53

def delete(name, rgroup = configuration.resource_group)
  validate_resource_group(rgroup)
  validate_resource(name)

  url = build_url(rgroup, name)
  url = yield(url) || url if block_given?
  rest_delete(url)
  nil
end

#get(name, rgroup = configuration.resource_group) ⇒ Object



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

def get(name, rgroup = configuration.resource_group)
  validate_resource_group(rgroup)
  validate_resource(name)

  url = build_url(rgroup, name)
  url = yield(url) || url if block_given?
  response = rest_get(url)
  model_class.new(response)
end

#list(rgroup = configuration.resource_group) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/azure/armrest/resource_group_based_service.rb', line 17

def list(rgroup = configuration.resource_group)
  validate_resource_group(rgroup)

  url = build_url(rgroup)
  url = yield(url) || url if block_given?
  response = rest_get(url)
  JSON.parse(response)['value'].map { |hash| model_class.new(hash) }
end

#list_all(filter = {}) ⇒ Object

Use a single call to get all resources for the service. You may optionally provide a filter on various properties to limit the result set.

Example:

vms = Azure::Armrest::VirtualMachineService.new(conf)
vms.list_all(:location => "eastus", :resource_group => "rg1")


35
36
37
38
39
40
41
# File 'lib/azure/armrest/resource_group_based_service.rb', line 35

def list_all(filter = {})
  url = build_url
  url = yield(url) || url if block_given?
  response = rest_get(url)
  results = JSON.parse(response)['value'].map { |hash| model_class.new(hash) }
  filter.empty? ? results : results.select { |obj| filter.all? { |k, v| obj.public_send(k) == v } }
end