azure-armrest 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGES +8 -1
- data/README.md +7 -22
- data/Rakefile +3 -3
- data/azure-armrest.gemspec +14 -16
- data/lib/azure/armrest.rb +14 -9
- data/lib/azure/armrest/armrest_service.rb +385 -0
- data/lib/azure/armrest/availability_set_service.rb +100 -0
- data/lib/azure/armrest/{event_manager.rb → event_service.rb} +3 -3
- data/lib/azure/armrest/resource_group_service.rb +86 -0
- data/lib/azure/armrest/resource_provider_service.rb +111 -0
- data/lib/azure/armrest/resource_service.rb +86 -0
- data/lib/azure/armrest/storage_account_service.rb +220 -0
- data/lib/azure/armrest/{subnet_manager.rb → subnet_service.rb} +4 -4
- data/lib/azure/armrest/template_deployment_service.rb +97 -0
- data/lib/azure/armrest/version.rb +1 -1
- data/lib/azure/armrest/{virtual_machine_extension_manager.rb → virtual_machine_extension_service.rb} +9 -5
- data/lib/azure/armrest/{virtual_machine_image_manager.rb → virtual_machine_image_service.rb} +7 -10
- data/lib/azure/armrest/{virtual_machine_manager.rb → virtual_machine_service.rb} +121 -80
- data/lib/azure/armrest/{virtual_network_manager.rb → virtual_network_service.rb} +9 -9
- metadata +64 -30
- data/lib/azure/armrest/armrest_manager.rb +0 -402
- data/lib/azure/armrest/availability_set_manager.rb +0 -50
- data/lib/azure/armrest/storage_account_manager.rb +0 -165
@@ -3,16 +3,16 @@ module Azure
|
|
3
3
|
# Armrest namespace
|
4
4
|
module Armrest
|
5
5
|
# Base class for managing virtual networks
|
6
|
-
class
|
6
|
+
class VirtualNetworkService < ArmrestService
|
7
7
|
|
8
|
-
# Create and return a new
|
9
|
-
# methods for a
|
8
|
+
# Create and return a new VirtualNetworkService instance. Most
|
9
|
+
# methods for a VirtualNetworkService instance will return one or
|
10
10
|
# more VirtualNetwork instances.
|
11
11
|
#
|
12
|
-
def initialize(options = {})
|
12
|
+
def initialize(armrest_configuration, options = {})
|
13
13
|
super
|
14
14
|
|
15
|
-
@base_url += "resourceGroups/#{
|
15
|
+
@base_url += "resourceGroups/#{armrest_configuration.resource_group}/"
|
16
16
|
@base_url += "providers/Microsoft.Network/virtualNetworks"
|
17
17
|
end
|
18
18
|
|
@@ -40,22 +40,22 @@ module Azure
|
|
40
40
|
# :id
|
41
41
|
#--
|
42
42
|
def create(network_name, options = {})
|
43
|
-
@uri += "/#{network_name}?api-version=#{api_version}"
|
43
|
+
@uri += "/#{network_name}?api-version=#{armrest_configuration.api_version}"
|
44
44
|
end
|
45
45
|
|
46
46
|
# Deletes the +network_name+ availability set.
|
47
47
|
def delete(network_name)
|
48
|
-
@uri += "/#{network_name}?api-version=#{api_version}"
|
48
|
+
@uri += "/#{network_name}?api-version=#{armrest_configuration.api_version}"
|
49
49
|
end
|
50
50
|
|
51
51
|
# Retrieves the options of an availability set.
|
52
52
|
def get(network_name)
|
53
|
-
@uri += "/#{network_name}?api-version=#{api_version}"
|
53
|
+
@uri += "/#{network_name}?api-version=#{armrest_configuration.api_version}"
|
54
54
|
end
|
55
55
|
|
56
56
|
# List availability sets.
|
57
57
|
def list
|
58
|
-
@uri += "?api-version=#{api_version}"
|
58
|
+
@uri += "?api-version=#{armrest_configuration.api_version}"
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|
metadata
CHANGED
@@ -1,25 +1,26 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: azure-armrest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel J. Berger
|
8
8
|
- Bronagh Sorota
|
9
9
|
- Greg Blomquist
|
10
|
+
- Bill Wei
|
10
11
|
autorequire:
|
11
|
-
bindir:
|
12
|
+
bindir: bin
|
12
13
|
cert_chain: []
|
13
|
-
date: 2015-
|
14
|
+
date: 2015-09-23 00:00:00.000000000 Z
|
14
15
|
dependencies:
|
15
16
|
- !ruby/object:Gem::Dependency
|
16
|
-
name:
|
17
|
+
name: json
|
17
18
|
requirement: !ruby/object:Gem::Requirement
|
18
19
|
requirements:
|
19
20
|
- - ">="
|
20
21
|
- !ruby/object:Gem::Version
|
21
22
|
version: '0'
|
22
|
-
type: :
|
23
|
+
type: :runtime
|
23
24
|
prerelease: false
|
24
25
|
version_requirements: !ruby/object:Gem::Requirement
|
25
26
|
requirements:
|
@@ -27,35 +28,35 @@ dependencies:
|
|
27
28
|
- !ruby/object:Gem::Version
|
28
29
|
version: '0'
|
29
30
|
- !ruby/object:Gem::Dependency
|
30
|
-
name:
|
31
|
+
name: rest-client
|
31
32
|
requirement: !ruby/object:Gem::Requirement
|
32
33
|
requirements:
|
33
|
-
- - "
|
34
|
+
- - ">="
|
34
35
|
- !ruby/object:Gem::Version
|
35
|
-
version: '
|
36
|
-
type: :
|
36
|
+
version: '0'
|
37
|
+
type: :runtime
|
37
38
|
prerelease: false
|
38
39
|
version_requirements: !ruby/object:Gem::Requirement
|
39
40
|
requirements:
|
40
|
-
- - "
|
41
|
+
- - ">="
|
41
42
|
- !ruby/object:Gem::Version
|
42
|
-
version: '
|
43
|
+
version: '0'
|
43
44
|
- !ruby/object:Gem::Dependency
|
44
|
-
name:
|
45
|
+
name: cache_method
|
45
46
|
requirement: !ruby/object:Gem::Requirement
|
46
47
|
requirements:
|
47
48
|
- - "~>"
|
48
49
|
- !ruby/object:Gem::Version
|
49
|
-
version:
|
50
|
-
type: :
|
50
|
+
version: 0.2.7
|
51
|
+
type: :runtime
|
51
52
|
prerelease: false
|
52
53
|
version_requirements: !ruby/object:Gem::Requirement
|
53
54
|
requirements:
|
54
55
|
- - "~>"
|
55
56
|
- !ruby/object:Gem::Version
|
56
|
-
version:
|
57
|
+
version: 0.2.7
|
57
58
|
- !ruby/object:Gem::Dependency
|
58
|
-
name:
|
59
|
+
name: bundler
|
59
60
|
requirement: !ruby/object:Gem::Requirement
|
60
61
|
requirements:
|
61
62
|
- - ">="
|
@@ -69,13 +70,13 @@ dependencies:
|
|
69
70
|
- !ruby/object:Gem::Version
|
70
71
|
version: '0'
|
71
72
|
- !ruby/object:Gem::Dependency
|
72
|
-
name:
|
73
|
+
name: rake
|
73
74
|
requirement: !ruby/object:Gem::Requirement
|
74
75
|
requirements:
|
75
76
|
- - ">="
|
76
77
|
- !ruby/object:Gem::Version
|
77
78
|
version: '0'
|
78
|
-
type: :
|
79
|
+
type: :development
|
79
80
|
prerelease: false
|
80
81
|
version_requirements: !ruby/object:Gem::Requirement
|
81
82
|
requirements:
|
@@ -83,19 +84,47 @@ dependencies:
|
|
83
84
|
- !ruby/object:Gem::Version
|
84
85
|
version: '0'
|
85
86
|
- !ruby/object:Gem::Dependency
|
86
|
-
name:
|
87
|
+
name: rspec
|
88
|
+
requirement: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - "~>"
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '3.0'
|
93
|
+
type: :development
|
94
|
+
prerelease: false
|
95
|
+
version_requirements: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - "~>"
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '3.0'
|
100
|
+
- !ruby/object:Gem::Dependency
|
101
|
+
name: codeclimate-test-reporter
|
87
102
|
requirement: !ruby/object:Gem::Requirement
|
88
103
|
requirements:
|
89
104
|
- - ">="
|
90
105
|
- !ruby/object:Gem::Version
|
91
106
|
version: '0'
|
92
|
-
type: :
|
107
|
+
type: :development
|
93
108
|
prerelease: false
|
94
109
|
version_requirements: !ruby/object:Gem::Requirement
|
95
110
|
requirements:
|
96
111
|
- - ">="
|
97
112
|
- !ruby/object:Gem::Version
|
98
113
|
version: '0'
|
114
|
+
- !ruby/object:Gem::Dependency
|
115
|
+
name: timecop
|
116
|
+
requirement: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - "~>"
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0.7'
|
121
|
+
type: :development
|
122
|
+
prerelease: false
|
123
|
+
version_requirements: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - "~>"
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0.7'
|
99
128
|
description: |
|
100
129
|
This is a Ruby interface for Azure using the newer REST API. This is
|
101
130
|
different than the current azure gem, which uses the older (XML) interface
|
@@ -104,6 +133,7 @@ email:
|
|
104
133
|
- dberger@redhat.com
|
105
134
|
- bsorota@redhat.com
|
106
135
|
- gblomqui@redhat.com
|
136
|
+
- billwei@redhat.com
|
107
137
|
executables: []
|
108
138
|
extensions: []
|
109
139
|
extra_rdoc_files: []
|
@@ -119,16 +149,20 @@ files:
|
|
119
149
|
- azure-armrest.gemspec
|
120
150
|
- lib/azure-armrest.rb
|
121
151
|
- lib/azure/armrest.rb
|
122
|
-
- lib/azure/armrest/
|
123
|
-
- lib/azure/armrest/
|
124
|
-
- lib/azure/armrest/
|
125
|
-
- lib/azure/armrest/
|
126
|
-
- lib/azure/armrest/
|
152
|
+
- lib/azure/armrest/armrest_service.rb
|
153
|
+
- lib/azure/armrest/availability_set_service.rb
|
154
|
+
- lib/azure/armrest/event_service.rb
|
155
|
+
- lib/azure/armrest/resource_group_service.rb
|
156
|
+
- lib/azure/armrest/resource_provider_service.rb
|
157
|
+
- lib/azure/armrest/resource_service.rb
|
158
|
+
- lib/azure/armrest/storage_account_service.rb
|
159
|
+
- lib/azure/armrest/subnet_service.rb
|
160
|
+
- lib/azure/armrest/template_deployment_service.rb
|
127
161
|
- lib/azure/armrest/version.rb
|
128
|
-
- lib/azure/armrest/
|
129
|
-
- lib/azure/armrest/
|
130
|
-
- lib/azure/armrest/
|
131
|
-
- lib/azure/armrest/
|
162
|
+
- lib/azure/armrest/virtual_machine_extension_service.rb
|
163
|
+
- lib/azure/armrest/virtual_machine_image_service.rb
|
164
|
+
- lib/azure/armrest/virtual_machine_service.rb
|
165
|
+
- lib/azure/armrest/virtual_network_service.rb
|
132
166
|
homepage: http://github.com/ManageIQ/azure-armrest
|
133
167
|
licenses:
|
134
168
|
- Apache 2.0
|
@@ -149,7 +183,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
149
183
|
version: '0'
|
150
184
|
requirements: []
|
151
185
|
rubyforge_project:
|
152
|
-
rubygems_version: 2.4.
|
186
|
+
rubygems_version: 2.4.5
|
153
187
|
signing_key:
|
154
188
|
specification_version: 4
|
155
189
|
summary: An interface for ARM/JSON Azure REST API
|
@@ -1,402 +0,0 @@
|
|
1
|
-
module Azure
|
2
|
-
module Armrest
|
3
|
-
# Abstract base class for the other manager classes.
|
4
|
-
class ArmrestManager
|
5
|
-
|
6
|
-
# The subscription ID (billing unit) for your Azure services
|
7
|
-
attr_accessor :subscription_id
|
8
|
-
|
9
|
-
# The resource group within the subscription.
|
10
|
-
attr_accessor :resource_group
|
11
|
-
|
12
|
-
# The API version of the REST interface. The default is 2015-1-1.
|
13
|
-
attr_accessor :api_version
|
14
|
-
|
15
|
-
# Base url used for REST calls.
|
16
|
-
attr_accessor :base_url
|
17
|
-
|
18
|
-
# The bearer token set in the constructor.
|
19
|
-
attr_accessor :token
|
20
|
-
|
21
|
-
# The content-type used for http requests.
|
22
|
-
attr_reader :content_type
|
23
|
-
|
24
|
-
# The accept value used for http requests.
|
25
|
-
attr_reader :accept
|
26
|
-
|
27
|
-
# The oauth2 strategy used for gathering the authentication token.
|
28
|
-
# The default is 'client_credentials'.
|
29
|
-
attr_reader :grant_type
|
30
|
-
|
31
|
-
VALID_OPTIONS = %[
|
32
|
-
client_id
|
33
|
-
client_key
|
34
|
-
tenant_id
|
35
|
-
subscription_id
|
36
|
-
resource_group
|
37
|
-
api_version
|
38
|
-
grant_type
|
39
|
-
content_type
|
40
|
-
accept
|
41
|
-
token
|
42
|
-
]
|
43
|
-
|
44
|
-
@@client_id = nil
|
45
|
-
@@client_key = nil
|
46
|
-
@@tenant_id = nil
|
47
|
-
@@subscription_id = nil
|
48
|
-
@@resource_group = nil
|
49
|
-
@@api_version = '2015-01-01'
|
50
|
-
@@grant_type = 'client_credentials'
|
51
|
-
@@content_type = 'application/json'
|
52
|
-
@@accept = 'application/json'
|
53
|
-
@@token = nil
|
54
|
-
@@providers = {} # Set in constructor
|
55
|
-
|
56
|
-
# Set configuration options globally. If set globally you do not need to
|
57
|
-
# pass configuration options to individual manager classes.
|
58
|
-
#
|
59
|
-
# Possible options are:
|
60
|
-
#
|
61
|
-
# - client_id
|
62
|
-
# - client_key
|
63
|
-
# - tenant_id
|
64
|
-
# - subscription_id
|
65
|
-
# - resource_group
|
66
|
-
# - api_version
|
67
|
-
# - grant_type
|
68
|
-
# - content_type
|
69
|
-
# - accept
|
70
|
-
# - token
|
71
|
-
#
|
72
|
-
# Of these, you should include a client_id, client_key and tenant_id.
|
73
|
-
# The resource_group can be specified here, but many methods allow you
|
74
|
-
# to specify a resource group if you prefer flexibility.
|
75
|
-
#
|
76
|
-
# If no subscription_id is provided then this method will attempt to find
|
77
|
-
# a list of associated subscriptions and use the first one it finds as
|
78
|
-
# the default. If no associated subscriptions are found, an ArgumentError
|
79
|
-
# is raised.
|
80
|
-
#
|
81
|
-
# The other options (grant_type, content_type, accept, token, and
|
82
|
-
# api_version) should generally NOT be set by you except in specific
|
83
|
-
# circumstances. Setting them explicitly will likely cause breakage.
|
84
|
-
# The api_version will typically be overridden on a per-provider/resource
|
85
|
-
# basis within subclasses anyway.
|
86
|
-
#
|
87
|
-
# You may need to associate your application with a subscription using
|
88
|
-
# the new portal or the New-AzureRoleAssignment powershell command.
|
89
|
-
#
|
90
|
-
def self.configure(options)
|
91
|
-
options.each do |k,v|
|
92
|
-
raise ArgumentError, "Invalid key: '#{k}'" unless VALID_OPTIONS.include?(k.to_s)
|
93
|
-
eval("@@#{k} = v")
|
94
|
-
end
|
95
|
-
|
96
|
-
token_url = Azure::Armrest::AUTHORITY + @@tenant_id + "/oauth2/token"
|
97
|
-
|
98
|
-
response = RestClient.post(
|
99
|
-
token_url,
|
100
|
-
:grant_type => @@grant_type,
|
101
|
-
:client_id => @@client_id,
|
102
|
-
:client_secret => @@client_key,
|
103
|
-
:resource => Azure::Armrest::RESOURCE
|
104
|
-
)
|
105
|
-
|
106
|
-
@@token = 'Bearer ' + JSON.parse(response)['access_token']
|
107
|
-
|
108
|
-
# Automatically set a subscription ID if one is not specified.
|
109
|
-
unless @@subscription_id
|
110
|
-
url = File.join(Azure::Armrest::RESOURCE, "subscriptions?api-version=#{@@api_version}")
|
111
|
-
|
112
|
-
response = RestClient.get(
|
113
|
-
url,
|
114
|
-
:content_type => @@content_type,
|
115
|
-
:authorization => @@token,
|
116
|
-
)
|
117
|
-
|
118
|
-
hash = JSON.parse(response.body)["value"].first
|
119
|
-
|
120
|
-
if hash.empty?
|
121
|
-
raise ArgumentError, "No associated subscription found"
|
122
|
-
else
|
123
|
-
@@subscription_id = hash.fetch("subscriptionId")
|
124
|
-
end
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
# Do not instantiate directly. This is an abstract base class from which
|
129
|
-
# all other manager classes should subclass, and call super within their
|
130
|
-
# own constructors.
|
131
|
-
#
|
132
|
-
# The possible options to the constructor are:
|
133
|
-
#
|
134
|
-
# * subscription_id - Your Azure subscription ID. If no subscription
|
135
|
-
# is specifified, then information for all subscriptions will be
|
136
|
-
# collected.
|
137
|
-
#
|
138
|
-
# * resource_group - The resource group within the subscription. If no
|
139
|
-
# resource group is specified, then information for all resource
|
140
|
-
# groups will be gathered.
|
141
|
-
#
|
142
|
-
# * client_id - Your Azure client ID. Mandatory.
|
143
|
-
#
|
144
|
-
# * client_key - The key (secret) for your client ID. Mandatory.
|
145
|
-
#
|
146
|
-
# * tenant_id - Your Azure tenant ID. Mandatory.
|
147
|
-
#
|
148
|
-
# * api_version - The REST API version to use for internal REST calls.
|
149
|
-
# The default is '2015-01-01'. In some cases this value is ignored
|
150
|
-
# in order to get the most recently supported api-version string.
|
151
|
-
#
|
152
|
-
def initialize(options = {})
|
153
|
-
# Mandatory params
|
154
|
-
@client_id = @@client_id || options.fetch(:client_id)
|
155
|
-
@client_key = @@client_key || options.fetch(:client_key)
|
156
|
-
@tenant_id = @@tenant_id || options.fetch(:tenant_id)
|
157
|
-
|
158
|
-
# Optional params
|
159
|
-
@subscription_id = @@subscription_id || options[:subscription_id]
|
160
|
-
@resource_group = @@resource_group || options[:resource_group]
|
161
|
-
@api_version = @@api_version || options[:api_version] || '2015-01-01'
|
162
|
-
@grant_type = @@grant_type || options[:grant_type] || 'client_credentials'
|
163
|
-
|
164
|
-
# The content-type used for all internal http requests
|
165
|
-
@content_type = @@content_type || 'application/json'
|
166
|
-
@accept = @@accept || 'application/json'
|
167
|
-
|
168
|
-
# Call the get_token method to set this.
|
169
|
-
@token = @@token || options[:token]
|
170
|
-
|
171
|
-
# Base URL used for REST calls. Modify within method calls as needed.
|
172
|
-
@base_url = Azure::Armrest::RESOURCE
|
173
|
-
|
174
|
-
set_providers_info
|
175
|
-
end
|
176
|
-
|
177
|
-
# Gets an authentication token, which is then used for all other methods.
|
178
|
-
# This will also set the subscription_id to the first subscription found
|
179
|
-
# if you did not set it in the constructor.
|
180
|
-
#
|
181
|
-
# If you did not call the the ArmrestManager.configure method then you
|
182
|
-
# must call this before calling any other methods.
|
183
|
-
#
|
184
|
-
def get_token
|
185
|
-
return self if @@token || @token
|
186
|
-
|
187
|
-
token_url = Azure::Armrest::AUTHORITY + @tenant_id + "/oauth2/token"
|
188
|
-
|
189
|
-
resp = RestClient.post(
|
190
|
-
token_url,
|
191
|
-
:grant_type => @grant_type,
|
192
|
-
:client_id => @client_id,
|
193
|
-
:client_secret => @client_key,
|
194
|
-
:resource => Azure::Armrest::RESOURCE
|
195
|
-
)
|
196
|
-
|
197
|
-
@token = 'Bearer ' + JSON.parse(resp)['access_token']
|
198
|
-
@@token = @token
|
199
|
-
|
200
|
-
unless @subscription_id
|
201
|
-
@subscription_id = subscriptions.first['subscriptionId']
|
202
|
-
end
|
203
|
-
|
204
|
-
set_providers_info
|
205
|
-
|
206
|
-
self
|
207
|
-
end
|
208
|
-
|
209
|
-
# Returns a list of the available resource providers.
|
210
|
-
#
|
211
|
-
def providers
|
212
|
-
url = url_with_api_version(@@api_version, @base_url, 'providers')
|
213
|
-
resp = rest_get(url)
|
214
|
-
JSON.parse(resp.body)["value"]
|
215
|
-
end
|
216
|
-
|
217
|
-
# Returns information about the specific provider +namespace+.
|
218
|
-
#
|
219
|
-
def provider_info(provider)
|
220
|
-
url = url_with_api_version(@@api_version, @base_url, 'providers', provider)
|
221
|
-
response = rest_get(url)
|
222
|
-
JSON.parse(response.body)
|
223
|
-
end
|
224
|
-
|
225
|
-
alias geo_locations provider_info
|
226
|
-
|
227
|
-
# Returns a list of all locations for all resource types of the given
|
228
|
-
# +provider+. If you do not specify a provider, then the locations for
|
229
|
-
# all providers will be returned.
|
230
|
-
#
|
231
|
-
# If you need individual details on a per-provider basis, use the
|
232
|
-
# provider_info method instead.
|
233
|
-
#--
|
234
|
-
#
|
235
|
-
def locations(provider = nil)
|
236
|
-
array = []
|
237
|
-
|
238
|
-
if provider
|
239
|
-
@@providers[provider].each do |key, data|
|
240
|
-
array << data['locations']
|
241
|
-
end
|
242
|
-
else
|
243
|
-
@@providers.each do |provider, resource_types|
|
244
|
-
@@providers[provider].each do |resource_type, data|
|
245
|
-
array << data['locations']
|
246
|
-
end
|
247
|
-
end
|
248
|
-
end
|
249
|
-
|
250
|
-
array.flatten.uniq
|
251
|
-
end
|
252
|
-
|
253
|
-
# Returns a list of subscriptions for the tenant.
|
254
|
-
#
|
255
|
-
def subscriptions
|
256
|
-
url = url_with_api_version(@@api_version, @base_url, 'subscriptions')
|
257
|
-
resp = rest_get(url)
|
258
|
-
JSON.parse(resp.body)["value"]
|
259
|
-
end
|
260
|
-
|
261
|
-
# Return information for the specified subscription ID, or the
|
262
|
-
# subscription ID that was provided in the constructor if none is
|
263
|
-
# specified.
|
264
|
-
#
|
265
|
-
def subscription_info(subscription_id = @subscription_id)
|
266
|
-
url = url_with_api_version(@@api_version, @base_url, 'subscriptions', subscription_id)
|
267
|
-
resp = rest_get(url)
|
268
|
-
JSON.parse(resp.body)
|
269
|
-
end
|
270
|
-
|
271
|
-
# Returns a list of resources for the current subscription. If a
|
272
|
-
# +resource_group+ is provided, only list resources for that
|
273
|
-
# resource group.
|
274
|
-
#
|
275
|
-
def resources(resource_group = nil)
|
276
|
-
if resource_group
|
277
|
-
url = url_with_api_version(
|
278
|
-
@@api_version, @base_url, 'subscriptions', subscription_id,
|
279
|
-
'resourcegroups', resource_group, 'resources'
|
280
|
-
)
|
281
|
-
else
|
282
|
-
url = url_with_api_version(@base_url, 'subscriptions', subscription_id, 'resources')
|
283
|
-
end
|
284
|
-
|
285
|
-
response = rest_get(url)
|
286
|
-
|
287
|
-
JSON.parse(response.body)["value"]
|
288
|
-
end
|
289
|
-
|
290
|
-
# Returns a list of resource groups for the current subscription.
|
291
|
-
#
|
292
|
-
def resource_groups
|
293
|
-
url = url_with_api_version(
|
294
|
-
@@api_version, @base_url, 'subscriptions',
|
295
|
-
subscription_id, 'resourcegroups'
|
296
|
-
)
|
297
|
-
response = rest_get(url)
|
298
|
-
JSON.parse(response.body)["value"]
|
299
|
-
end
|
300
|
-
|
301
|
-
# Returns information on the specified +resource_group+ for the current
|
302
|
-
# subscription, or the resource group specified in the constructor if
|
303
|
-
# none is provided.
|
304
|
-
#
|
305
|
-
def resource_group_info(resource_group)
|
306
|
-
url = url_with_api_version(
|
307
|
-
@@api_version, @base_url, 'subscriptions',
|
308
|
-
subscription_id, 'resourcegroups', resource_group
|
309
|
-
)
|
310
|
-
|
311
|
-
resp = rest_get(url)
|
312
|
-
JSON.parse(resp.body)
|
313
|
-
end
|
314
|
-
|
315
|
-
# Returns a list of tags for the current subscription.
|
316
|
-
#
|
317
|
-
def tags
|
318
|
-
url = url_with_api_version(@@api_version, @base_url, 'subscriptions', subscription_id, 'tagNames')
|
319
|
-
resp = rest_get(url)
|
320
|
-
JSON.parse(resp.body)["value"]
|
321
|
-
end
|
322
|
-
|
323
|
-
# Returns a list of tenants that can be accessed.
|
324
|
-
#
|
325
|
-
def tenants
|
326
|
-
url = url_with_api_version(@@api_version, @base_url, 'tenants')
|
327
|
-
resp = rest_get(url)
|
328
|
-
JSON.parse(resp.body)
|
329
|
-
end
|
330
|
-
|
331
|
-
private
|
332
|
-
|
333
|
-
# REST verb methods
|
334
|
-
|
335
|
-
def rest_get(url)
|
336
|
-
RestClient.get(
|
337
|
-
url,
|
338
|
-
:accept => @accept,
|
339
|
-
:content_type => @content_type,
|
340
|
-
:authorization => @token,
|
341
|
-
)
|
342
|
-
end
|
343
|
-
|
344
|
-
def rest_put(url, body = '')
|
345
|
-
RestClient.put(
|
346
|
-
url,
|
347
|
-
body,
|
348
|
-
:accept => @accept,
|
349
|
-
:content_type => @content_type,
|
350
|
-
:authorization => @token,
|
351
|
-
)
|
352
|
-
end
|
353
|
-
|
354
|
-
def rest_post(url, body = '')
|
355
|
-
RestClient.post(
|
356
|
-
url,
|
357
|
-
body,
|
358
|
-
:accept => @accept,
|
359
|
-
:content_type => @content_type,
|
360
|
-
:authorization => @token,
|
361
|
-
)
|
362
|
-
end
|
363
|
-
|
364
|
-
def rest_delete(url)
|
365
|
-
RestClient.delete(
|
366
|
-
url,
|
367
|
-
:accept => @accept,
|
368
|
-
:content_type => @content_type,
|
369
|
-
:authorization => @token,
|
370
|
-
)
|
371
|
-
end
|
372
|
-
|
373
|
-
# Take an array of URI elements and join the together with the API version.
|
374
|
-
def url_with_api_version(api_version, *paths)
|
375
|
-
File.join(*paths) << "?api-version=#{api_version}"
|
376
|
-
end
|
377
|
-
|
378
|
-
# Build a one-time lookup table for each provider & resource. This
|
379
|
-
# lets subclasses set api-version strings properly for each method
|
380
|
-
# depending on whichever provider they're using.
|
381
|
-
#
|
382
|
-
# e.g. @@providers['Microsoft.Compute']['virtualMachines']['api_version']
|
383
|
-
#
|
384
|
-
# Note that for methods that don't depend on a resource type should use
|
385
|
-
# the @@api_version class variable instead or set it explicitly as needed.
|
386
|
-
#
|
387
|
-
def set_providers_info
|
388
|
-
if @@providers.empty? && @token
|
389
|
-
providers.each do |info|
|
390
|
-
@@providers[info['namespace']] = {}
|
391
|
-
info['resourceTypes'].each do |resource|
|
392
|
-
@@providers[info['namespace']][resource['resourceType']] = {
|
393
|
-
'api_version' => resource['apiVersions'].first,
|
394
|
-
'locations' => resource['locations'] - [''] # Ignore empty elements
|
395
|
-
}
|
396
|
-
end
|
397
|
-
end
|
398
|
-
end
|
399
|
-
end
|
400
|
-
end # ArmrestManager
|
401
|
-
end # Armrest
|
402
|
-
end # Azure
|