Class: Azure::Armrest::ResourceService
- Inherits:
-
ArmrestService
- Object
- ArmrestService
- Azure::Armrest::ResourceService
- Defined in:
- lib/azure/armrest/resource_service.rb
Instance Attribute Summary collapse
-
#provider ⇒ Object
readonly
The provider used in http requests.
Attributes inherited from ArmrestService
#api_version, #armrest_configuration, #base_url, #service_name
Instance Method Summary collapse
-
#check_resource(resource_name, resource_type) ⇒ Object
Checks to see if the given 'resource_name' and 'resource_type' is allowed.
-
#check_resource?(resource_name, resource_type) ⇒ Boolean
Similar to the check_resource method, but returns a boolean instead.
-
#initialize(configuration, options = {}) ⇒ ResourceService
constructor
Creates and returns a new ResourceService object.
-
#list(resource_group, options = {}) ⇒ Object
List all the resources for the current subscription in the specified resource group.
-
#list_all(options = {}) ⇒ Object
Same as Azure::Armrest::ResourceService#list but returns all resources for all resource groups.
-
#move(source_group, source_subscription = configuration.subscription_id) ⇒ Object
Move the resources from
source_group
undersource_subscription
, which may be a different subscription.
Methods inherited from ArmrestService
configure, #get_provider, #get_subscription, #list_locations, #list_resource_groups, #list_resources, #list_subscriptions, #locations, #poll, #tags, #tenants, #wait
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, = {}) super(configuration, 'subscriptions', 'Microsoft.Resources', ) end |
Instance Attribute Details
#provider ⇒ Object (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.
79 80 81 82 83 84 85 86 |
# File 'lib/azure/armrest/resource_service.rb', line 79 def check_resource(resource_name, resource_type) body = JSON.dump(:Name => resource_name, :Type => resource_type) url = File.join(configuration.environment.resource_url, '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.
90 91 92 |
# File 'lib/azure/armrest/resource_service.rb', line 90 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.
Normally this is capped at 1000 results, but you may specify the :all option to get everything.
Examples:
rs = Azure::Armrest::ResourceService.new
rs.list(your_group, :top => 2)
rs.list(your_group, :filter => "location eq 'centralus'")
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/azure/armrest/resource_service.rb', line 26 def list(resource_group, = {}) url = build_url(resource_group, ) response = rest_get(url) if [:all] get_all_results(response) else Azure::Armrest::ArmrestCollection.create_from_response(response, Azure::Armrest::Resource) end end |
#list_all(options = {}) ⇒ Object
Same as Azure::Armrest::ResourceService#list but returns all resources for all resource groups.
Normally this is capped at 1000 results, but you may specify the :all option to get everything.
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/azure/armrest/resource_service.rb', line 43 def list_all( = {}) url = build_url(nil, ) response = rest_get(url) if [:all] get_all_results(response) else Azure::Armrest::ArmrestCollection.create_from_response(response, Azure::Armrest::Resource) end 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.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/azure/armrest/resource_service.rb', line 57 def move(source_group, source_subscription = configuration.subscription_id) url = File.join( configuration.environment.resource_url, 'subscriptions', source_subscription, 'resourcegroups', source_group, 'moveresources' ) url << "?api-version=#{@api_version}" response = rest_post(url) response.return! end |