azure-armrest 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 198f8903222b20b0bbea81928db29aab7436dbae
4
- data.tar.gz: 25a4b584d105a275782a32635e69faa78e6d6250
3
+ metadata.gz: f8b26339221636eee239e6934d67cf0c4ee3bbb9
4
+ data.tar.gz: 1a6c35bd8f5a4af7ec2bd68d3734978add667981
5
5
  SHA512:
6
- metadata.gz: d6c3ab976bc6b91665dafccfcfc5e317023c9feddeb61ec580764fe07858d095be9cb8bb8d715c8c4cf53ec589ae76b8cb6657f759152a014f11c729a0f0d11e
7
- data.tar.gz: 9023b4532602c882d34282208cf4941b7cf5bd130e641d7da11b3c8fdca5235a075df763454bded12bc389df91ebd21aa0b4185dfa45ca3a2ff2bc2c9b17beb4
6
+ metadata.gz: 1a130d2af6d31ca1b55b40dbe528103b359022ac7a9b685d4954ea3144f1ec6bbc5be7247aaa9f2e23963819d308d322159f46d3390b74c81caf3ee8c3dec7fc
7
+ data.tar.gz: fe7a7347b7bd16877848d8125ff496504d2e96822487ba0a70f62fc157798373767b9852ba5b89d3a0314e797803493745c77697b2b373eea86716e6b4086e52
data/CHANGES CHANGED
@@ -1,3 +1,8 @@
1
+ = 0.0.9 - 17-Dec-2015
2
+ * Added AlertService and EventService classes.
3
+ * Added tables, table_info and table_data methods to the StorageAccount model.
4
+ * Updates to the README.
5
+
1
6
  = 0.0.8 - 10-Nov-2015
2
7
  * Added the list_private_images method to the StorageAccountService class.
3
8
  * Added the list_all method to the ResourceGroupService class.
data/README.md CHANGED
@@ -15,6 +15,7 @@ require 'azure/armrest'
15
15
 
16
16
  # Create a configuration object. All service objects will then use the
17
17
  # information you set here.
18
+ #
18
19
  # A token will be retrieved based on the information you provided
19
20
 
20
21
  conf = Azure::Armrest::ArmrestService.configure(
@@ -28,23 +29,19 @@ conf = Azure::Armrest::ArmrestService.configure(
28
29
  # You can add other options specific to the service to be created
29
30
  vms = Azure::Armrest::VirtualMachineService.new(conf, options)
30
31
 
31
- # Create a virtual machine
32
- vmm.create_virtual_machine(
33
- :name => 'some_vm',
34
- :location => 'West US',
35
- :vm_size => 'Standard_A1',
36
- :computer_name => 'whatever',
37
- :admin_username => 'admin_user',
38
- :admin_password => 'adminxxxxxx',
39
- :os_disk => {:name => 'disk_name1', :os_type => 'Linux', :caching => 'read'},
40
- :data_disks => {:name => 'data_disk1', :lun => 0, :caching => 'read'}
41
- )
32
+ # List all virtual machines for a given resource group:
33
+ vms.list(some_group).each do |vm|
34
+ puts vm.name
35
+ puts vm.resource_group
36
+ puts vm.location
37
+ puts vm.properties.hardware_profile.vm_size
38
+ end
42
39
  ```
43
40
 
44
41
  ## Subscriptions
45
42
 
46
- If you do not provide a subscription ID to the constructor, then the first
47
- subscription ID returned from a REST call will be used.
43
+ If you do not provide a subscription ID in your configuration object, then the
44
+ first subscription ID returned from a REST call will be used.
48
45
 
49
46
  ## Notes
50
47
 
data/lib/azure/armrest.rb CHANGED
@@ -33,9 +33,12 @@ require 'azure/armrest/template_deployment_service'
33
33
  require 'azure/armrest/resource_service'
34
34
  require 'azure/armrest/resource_group_service'
35
35
  require 'azure/armrest/resource_provider_service'
36
+ require 'azure/armrest/insights/alert_service'
37
+ require 'azure/armrest/insights/event_service'
36
38
  require 'azure/armrest/network/ip_address_service'
37
39
  require 'azure/armrest/network/network_interface_service'
38
40
  require 'azure/armrest/network/network_security_group_service'
41
+ require 'azure/armrest/network/network_security_rule_service'
39
42
  require 'azure/armrest/network/virtual_network_service'
40
43
  require 'azure/armrest/network/subnet_service'
41
44
 
@@ -0,0 +1,23 @@
1
+ # Azure namespace
2
+ module Azure
3
+ # Armrest namespace
4
+ module Armrest
5
+ # Insights namesspace
6
+ module Insights
7
+ # Base class for managing alert rules.
8
+ class AlertService < ResourceGroupBasedService
9
+ # The provider used in requests when gathering Alert information.
10
+ attr_reader :provider
11
+
12
+ # Create and return a new AlertService instance.
13
+ #
14
+ def initialize(_armrest_configuration, options = {})
15
+ super
16
+ @provider = options[:provider] || 'Microsoft.Insights'
17
+ set_service_api_version(options, 'alertrules')
18
+ @service_name = 'alertRules'
19
+ end
20
+ end # AlertService
21
+ end # Insights
22
+ end # Armrest
23
+ end # Azure
@@ -0,0 +1,76 @@
1
+ # Azure namespace
2
+ module Azure
3
+ # Armrest namespace
4
+ module Armrest
5
+ # Insights namespace
6
+ module Insights
7
+
8
+ # Base class for managing events.
9
+ class EventService < ArmrestService
10
+ # The provider used in requests when gathering Event information.
11
+ attr_reader :provider
12
+
13
+ # Create and return a new EventService instance.
14
+ #
15
+ def initialize(_armrest_configuration, options = {})
16
+ super
17
+ @provider = options[:provider] || 'Microsoft.Insights'
18
+ set_service_api_version(options, 'eventtypes')
19
+ @service_name = 'eventTypes'
20
+ end
21
+
22
+ # Returns a list of management events for the current subscription.
23
+ # The +filter+ option can be used to filter the result set. Additionally,
24
+ # you may restrict the results to only return certain fields using
25
+ # the +select+ option. The possible fields for both filtering and selection
26
+ # are:
27
+ #
28
+ # authorization, channels, claims, correlationId, description, eventDataId,
29
+ # eventName, eventSource, eventTimestamp, httpRequest, level, operationId,
30
+ # operationName, properties, resourceGroupName, resourceProviderName,
31
+ # resourceUri, status, submissionTimestamp, subStatus and subscriptionId.
32
+ #
33
+ # Example:
34
+ #
35
+ # ies = Azure::Armrest::Insights::EventService.new(conf)
36
+ #
37
+ # date = (Time.now - 86400).httpdate
38
+ # filter = "eventTimestamp ge #{date} and eventChannels eq 'Admin, Operation'"
39
+ # select = "resourceGroupName, operationName"
40
+ #
41
+ # ies.list(filter, select).each{ |event|
42
+ # p event
43
+ # }
44
+ #
45
+ def list(filter = nil, select = nil)
46
+ url = build_url(filter, select)
47
+ response = rest_get(url)
48
+ JSON.parse(response.body)['value'].map{ |e| Azure::Armrest::Insights::Event.new(e) }
49
+ end
50
+
51
+ private
52
+
53
+ def build_url(filter = nil, select = nil)
54
+ sub_id = armrest_configuration.subscription_id
55
+
56
+ url = File.join(
57
+ Azure::Armrest::COMMON_URI,
58
+ sub_id,
59
+ 'providers',
60
+ @provider,
61
+ 'eventtypes',
62
+ 'management',
63
+ 'values'
64
+ )
65
+
66
+ url << "?api-version=#{@api_version}"
67
+ url << "&$filter=#{filter}" if filter
68
+ url << "&$select=#{select}" if select
69
+
70
+ url
71
+ end
72
+ end # EventService
73
+
74
+ end # Insights
75
+ end # Armrest
76
+ end # Azure
@@ -182,10 +182,16 @@ module Azure
182
182
  class VirtualMachineImage < BaseModel; end
183
183
  class VirtualMachineSize < BaseModel; end
184
184
 
185
+ module Insights
186
+ class Alert < BaseModel; end
187
+ class Event < BaseModel; end
188
+ end
189
+
185
190
  module Network
186
191
  class IpAddress < BaseModel; end
187
192
  class NetworkInterface < BaseModel; end
188
193
  class NetworkSecurityGroup < BaseModel; end
194
+ class NetworkSecurityRule < NetworkSecurityGroup; end
189
195
  class VirtualNetwork < BaseModel; end
190
196
  class Subnet < VirtualNetwork; end
191
197
  end
@@ -15,6 +15,10 @@ module Azure
15
15
  class BlobServiceStat < BaseModel; end
16
16
  class BlobMetadata < BaseModel; end
17
17
 
18
+ # Classes used to wrap table information
19
+ class Table < BaseModel; end
20
+ class TableData < BaseModel; end
21
+
18
22
  # The version string used in headers sent as part any internal http
19
23
  # request. The default is 2015-02-21.
20
24
  attr_accessor :storage_api_version
@@ -24,6 +28,52 @@ module Azure
24
28
  @storage_api_version = '2015-02-21'
25
29
  end
26
30
 
31
+ # Returns a list of tables for the given storage account +key+. Note
32
+ # that full metadata is returned.
33
+ #
34
+ def tables(key = nil)
35
+ key ||= properties.key1
36
+ response = table_response(key, nil, "Tables")
37
+ JSON.parse(response.body)['value'].map{ |t| Table.new(t) }
38
+ end
39
+
40
+ # Return information about a single table for the given storage
41
+ # account +key+. If you are looking for the entities within the
42
+ # table, use the table_data method instead.
43
+ #
44
+ def table_info(table, key = nil)
45
+ key ||= properties.key1
46
+ response = table_response(key, nil, "Tables('#{table}')")
47
+ Table.new(response.body)
48
+ end
49
+
50
+ # Returns a list of TableData objects for the given table +name+ using
51
+ # account +key+. The exact nature of the TableData object depends on the
52
+ # type of table that it is.
53
+ #
54
+ def table_data(name, key = nil, options = {})
55
+ key ||= properties.key1
56
+
57
+ query = ""
58
+
59
+ hash = {
60
+ "$filter=" => options[:filter],
61
+ "$select=" => options[:select],
62
+ "$top=" => options[:top]
63
+ }
64
+
65
+ hash.each do |key, value|
66
+ if query.include?("$")
67
+ query << "&#{key}#{value}" if value
68
+ else
69
+ query << "#{key}#{value}" if value
70
+ end
71
+ end
72
+
73
+ response = table_response(key, query, name)
74
+ JSON.parse(response.body)['value'].map{ |t| TableData.new(t) }
75
+ end
76
+
27
77
  # Return a list of container names for the given storage account +key+.
28
78
  # If no key is provided, it is assumed that the StorageAccount object
29
79
  # includes the key1 property.
@@ -76,7 +126,7 @@ module Azure
76
126
  url = File.join(properties.primary_endpoints.blob, container, blob)
77
127
  url += "?snapshot=" + options[:date] if options[:date]
78
128
 
79
- headers = build_headers(url, key, :verb => 'HEAD')
129
+ headers = build_headers(url, key, :blob, :verb => 'HEAD')
80
130
  response = RestClient.head(url, headers)
81
131
 
82
132
  BlobProperty.new(response.headers)
@@ -174,7 +224,7 @@ module Azure
174
224
 
175
225
  options = {'x-ms-copy-source' => src_url, 'If-None-Match' => '*', :verb => 'PUT'}
176
226
 
177
- headers = build_headers(dst_url, key, options)
227
+ headers = build_headers(dst_url, key, :blob, options)
178
228
 
179
229
  # RestClient will set the Content-Type to application/x-www-form-urlencoded.
180
230
  # We must override this setting or the request will fail.
@@ -193,7 +243,7 @@ module Azure
193
243
  url = File.join(properties.primary_endpoints.blob, container, blob)
194
244
  url += "?snapshot=" + options[:date] if options[:date]
195
245
 
196
- headers = build_headers(url, key, :verb => 'DELETE')
246
+ headers = build_headers(url, key, :blob, :verb => 'DELETE')
197
247
  response = RestClient.delete(url, headers)
198
248
 
199
249
  true
@@ -206,14 +256,28 @@ module Azure
206
256
  #
207
257
  def blob_response(key, query, *args)
208
258
  url = File.join(properties.primary_endpoints.blob, *args) + "?#{query}"
209
- headers = build_headers(url, key)
259
+ headers = build_headers(url, key, 'blob')
260
+ RestClient.get(url, headers)
261
+ end
262
+
263
+ # Using the blob primary endpoint as a base, join any arguments to the
264
+ # the url and submit an http request.
265
+ def table_response(key, query = nil, *args)
266
+ url = File.join(properties.primary_endpoints.table, *args)
267
+
268
+ headers = build_headers(url, key, 'table')
269
+ headers['Accept'] = 'application/json;odata=fullmetadata'
270
+
271
+ url << "?#{query}" if query # Must happen after headers are built
272
+
210
273
  RestClient.get(url, headers)
211
274
  end
212
275
 
213
276
  # Set the headers needed, including the Authorization header.
214
277
  #
215
- def build_headers(url, key, additional_headers = {})
278
+ def build_headers(url, key, sig_type = nil, additional_headers = {})
216
279
  sig = Signature.new(url, key)
280
+ sig_type ||= 'blob'
217
281
 
218
282
  headers = {
219
283
  'x-ms-date' => Time.now.httpdate,
@@ -222,7 +286,7 @@ module Azure
222
286
  }
223
287
 
224
288
  headers.merge!(additional_headers)
225
- headers['Authorization'] = sig.blob_signature(headers)
289
+ headers['Authorization'] = sig.signature(sig_type, headers)
226
290
 
227
291
  headers
228
292
  end
@@ -0,0 +1,47 @@
1
+ module Azure
2
+ module Armrest
3
+ module Network
4
+ # Base class for managing securityRules
5
+ class NetworkSecurityRuleService < NetworkSecurityGroupService
6
+ # Creates a new +rule_name+ on +security_group+ using the given +options+.
7
+ def create(rule_name, security_group, resource_group = armrest_configuration.resource_group, options = {})
8
+ super(combine(security_group, rule_name), resource_group, options)
9
+ end
10
+
11
+ alias update create
12
+
13
+ # Deletes the given +rule_name+ in +security_group+.
14
+ #
15
+ def delete(rule_name, security_group, resource_group = armrest_configuration.resource_group)
16
+ super(combine(security_group, rule_name), resource_group)
17
+ end
18
+
19
+ # Retrieves information for the provided +rule_name+ in +security_group+ for
20
+ # the current subscription.
21
+ #
22
+ def get(rule_name, security_group, resource_group = armrest_configuration.resource_group)
23
+ super(combine(security_group, rule_name), resource_group)
24
+ end
25
+
26
+ # List available security rules on +security_group+ for the given +resource_group+.
27
+ #
28
+ def list(security_group, resource_group = armrest_configuration.resource_group)
29
+ raise ArgumentError, "must specify resource group" unless resource_group
30
+ raise ArgumentError, "must specify name of the resource" unless security_group
31
+
32
+ url = build_url(resource_group, security_group, 'securityRules')
33
+ response = rest_get(url)
34
+ JSON.parse(response)['value'].map{ |hash| model_class.new(hash) }
35
+ end
36
+
37
+ alias list_all list
38
+
39
+ private
40
+
41
+ def combine(virtual_network, subnet)
42
+ File.join(virtual_network, 'securityRules', subnet)
43
+ end
44
+ end
45
+ end # Network
46
+ end # Armrest
47
+ end # Azure
@@ -1,5 +1,5 @@
1
1
  module Azure
2
2
  module Armrest
3
- VERSION = "0.0.8"
3
+ VERSION = "0.0.9"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: azure-armrest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel J. Berger
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2015-11-10 00:00:00.000000000 Z
14
+ date: 2015-12-17 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: json
@@ -194,11 +194,14 @@ files:
194
194
  - lib/azure/armrest/armrest_service.rb
195
195
  - lib/azure/armrest/availability_set_service.rb
196
196
  - lib/azure/armrest/exception.rb
197
+ - lib/azure/armrest/insights/alert_service.rb
198
+ - lib/azure/armrest/insights/event_service.rb
197
199
  - lib/azure/armrest/model/base_model.rb
198
200
  - lib/azure/armrest/model/storage_account.rb
199
201
  - lib/azure/armrest/network/ip_address_service.rb
200
202
  - lib/azure/armrest/network/network_interface_service.rb
201
203
  - lib/azure/armrest/network/network_security_group_service.rb
204
+ - lib/azure/armrest/network/network_security_rule_service.rb
202
205
  - lib/azure/armrest/network/subnet_service.rb
203
206
  - lib/azure/armrest/network/virtual_network_service.rb
204
207
  - lib/azure/armrest/resource_group_based_service.rb
@@ -231,7 +234,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
231
234
  version: '0'
232
235
  requirements: []
233
236
  rubyforge_project:
234
- rubygems_version: 2.5.0
237
+ rubygems_version: 2.5.1
235
238
  signing_key:
236
239
  specification_version: 4
237
240
  summary: An interface for ARM/JSON Azure REST API