azure-armrest 0.5.2 → 0.6.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 73beabef1814841487327de9d64c582c7dabd35a
4
- data.tar.gz: 6cdc3b6d754f2974c41de3b8cb57c8bc6aa64a07
3
+ metadata.gz: 1924d7500a8f68134dca99b63ce6b541bf14a028
4
+ data.tar.gz: 41aec5ac6cdedc2c040f82f170b75da8d5960ad8
5
5
  SHA512:
6
- metadata.gz: c3a3cf9f3f4b5d0b8fc38b4e46d79c6686259e3ec5a24a1263a4c0543dcf802ad0d0c17a82fb759b58f38a8a560b78089176bf9670ecf0927e9d4316291575d4
7
- data.tar.gz: 7230dcf6df9ade9181e5d18f222578a75ff4b37fb7dbd56d04a096c013f99080f4280999e31700dff409949ce2269898bd06c0995a10a64b63360a8912ca66ab
6
+ metadata.gz: d849b4b4c4e55c61ad0766246cec6302307f071bef3ba821cd970f9ab2365cb9bf983e34b3af8c3d59702633da2f47630505d43b7638bd30a0c8bc043fc28c7d
7
+ data.tar.gz: 8f70bf2cee8c8d105846ebd83bef0deefb3f1ebb7563e21124893b1b2e302130761c32e327aacefd652e3cf0cd43490fa2bd9bfd7e2e60eaeb5135468f1f7a58
@@ -0,0 +1,4 @@
1
+ inherit_from:
2
+ - https://raw.githubusercontent.com/ManageIQ/guides/master/.rubocop_base.yml
3
+ # put all local rubocop config into .rubocop_local.yml as it will be loaded by .rubocop_cc.yml as well
4
+ - .rubocop_local.yml
File without changes
data/CHANGES CHANGED
@@ -1,3 +1,13 @@
1
+ = 0.6.0 - 6-Jan-2017
2
+ * Revamped the Role::AssignmentService and Role::DefinitionService which were
3
+ mostly broken. These are now each subclassed from a RoleService base class
4
+ that implements various scope-based methods.
5
+ * The Insights::MetricsService class was updated to add the list_metrics and
6
+ list_definitions methods. These use the newer API from Azure that is easier
7
+ to use, but returns fewer definitions.
8
+ * Added the ResourceProviderService#registered? method.
9
+ * Some rubocop updates.
10
+
1
11
  = 0.5.2 - 22-Dec-2016
2
12
  * The Configuration#hash method, which is used internally to cache auth
3
13
  tokens, was modified to include the environment name. This prevents
@@ -45,6 +45,7 @@ require 'azure/armrest/network/route_table_service'
45
45
  require 'azure/armrest/network/route_service'
46
46
  require 'azure/armrest/network/virtual_network_service'
47
47
  require 'azure/armrest/network/subnet_service'
48
+ require 'azure/armrest/role'
48
49
  require 'azure/armrest/role/assignment_service'
49
50
  require 'azure/armrest/role/definition_service'
50
51
  require 'azure/armrest/sql/sql_server_service'
@@ -5,13 +5,15 @@ module Azure
5
5
  # Creates and returns a new MetricsService object.
6
6
  #
7
7
  def initialize(armrest_configuration, options = {})
8
- options['api_version'] = '2014-04-01' # Must hard code for now
9
- super(armrest_configuration, 'metricDefinitions', 'Microsoft.Insights', options)
8
+ super(armrest_configuration, 'metrics', 'Microsoft.Insights', options)
10
9
  end
11
10
 
12
11
  # Return the metric definitions for the given +provider+, +resource_type+,
13
12
  # and +resource_name+ for +resource_group+. You may pass a :filter option as well.
14
13
  #
14
+ # NOTE: This uses the older REST API. If you want the newer API, use the
15
+ # list_definitions method below.
16
+ #
15
17
  # Example:
16
18
  #
17
19
  # metrics = Azure::Armrest::Insights::MetricsService.new(conf)
@@ -28,11 +30,90 @@ module Azure
28
30
 
29
31
  response = rest_get(url)
30
32
 
31
- JSON.parse(response)['value'].map { |hash| Azure::Armrest::Insights::Metric.new(hash) }
33
+ Azure::Armrest::ArmrestCollection.create_from_response(
34
+ response,
35
+ Azure::Armrest::Insights::MetricDefinition
36
+ )
37
+ end
38
+
39
+ # Returns a list metrics for +resource_id+, which can be
40
+ # either a resource object or a plain resource string. You
41
+ # may also provide a +filter+ to limit the results.
42
+ #
43
+ # If no filter expression is defined, the first metric defined
44
+ # for that resource will be returned using the primary aggregation
45
+ # type in the metric defintion over a time period of the last hour.
46
+ #
47
+ # vms = Azure::Armrest::VirtualMachineService.new(conf)
48
+ # mts = Azure::Armrest::Insights::MetricService.new(conf)
49
+ #
50
+ # vm = vms.get('your_vm', 'your_resource_group')
51
+ #
52
+ # filter = "name.value eq 'Percentage CPU' and startTime "
53
+ # filter << "eq 2017-01-03 and endTime eq 2017-01-04"
54
+ #
55
+ # definitions = mts.list_metrics(vm.id)
56
+ #
57
+ def list_metrics(resource, filter = nil)
58
+ resource_id = resource.respond_to?(:id) ? resource.id : resource
59
+
60
+ url = File.join(
61
+ configuration.environment.resource_url,
62
+ resource_id,
63
+ 'providers/microsoft.insights/metrics'
64
+ )
65
+
66
+ url << "?api-version=#{api_version}"
67
+ url << "&$filter=#{filter}" if filter
68
+
69
+ response = rest_get(url)
70
+
71
+ Azure::Armrest::ArmrestCollection.create_from_response(response, Azure::Armrest::Insights::Metric)
72
+ end
73
+
74
+ # Get a list of metrics definitions for +resource_id+, which can be
75
+ # either a resource object or a plain resource string. You may also
76
+ # provide a +filter+ to limit the results.
77
+ #
78
+ # Note that the output for this method is different than the list
79
+ # method, which uses an older api-version.
80
+ #
81
+ # Example:
82
+ #
83
+ # vms = Azure::Armrest::VirtualMachineService.new(conf)
84
+ # mts = Azure::Armrest::Insights::MetricService.new(conf)
85
+ #
86
+ # vm = vms.get('your_vm', 'your_resource_group')
87
+ #
88
+ # # With or without filter
89
+ # definitions = mts.list_definitions(vm.id)
90
+ # definitions = mts.list_definitions(vm.id, "name.value eq 'Percentage CPU'")
91
+ #
92
+ def list_definitions(resource, filter = nil)
93
+ resource_id = resource.respond_to?(:id) ? resource.id : resource
94
+ version = configuration.provider_default_api_version(provider, 'metricDefinitions')
95
+
96
+ url = File.join(
97
+ configuration.environment.resource_url,
98
+ resource_id,
99
+ 'providers/microsoft.insights/metricdefinitions'
100
+ )
101
+
102
+ url << "?api-version=#{version}"
103
+ url << "&$filter=#{filter}" if filter
104
+
105
+ response = rest_get(url)
106
+
107
+ Azure::Armrest::ArmrestCollection.create_from_response(
108
+ response,
109
+ Azure::Armrest::Insights::MetricDefinition
110
+ )
32
111
  end
33
112
 
34
113
  private
35
114
 
115
+ # Build a URL for the older version of the metrics definitions API.
116
+ #
36
117
  def build_url(provider, resource_type, resource_name, resource_group, options)
37
118
  url = File.join(
38
119
  base_url,
@@ -45,7 +126,7 @@ module Azure
45
126
  'metricDefinitions'
46
127
  )
47
128
 
48
- url << "?api-version=#{@api_version}"
129
+ url << "?api-version=2014-04-01"
49
130
  url << "&$filter=#{options[:filter]}" if options[:filter]
50
131
 
51
132
  url
@@ -224,6 +224,7 @@ module Azure
224
224
  class Diagnostic < BaseModel; end
225
225
  class Event < BaseModel; end
226
226
  class Metric < BaseModel; end
227
+ class MetricDefinition < BaseModel; end
227
228
  end
228
229
 
229
230
  module Network
@@ -123,6 +123,15 @@ module Azure
123
123
  nil
124
124
  end
125
125
 
126
+ # Returns whether or not the +namespace+ provider is registered. If
127
+ # the provider cannot be found, false is returned.
128
+ #
129
+ def registered?(namespace)
130
+ get(namespace).registration_state.casecmp("registered").zero?
131
+ rescue Azure::Armrest::NotFoundException
132
+ false
133
+ end
134
+
126
135
  private
127
136
 
128
137
  def build_url(namespace = nil, *args)
@@ -0,0 +1,104 @@
1
+ module Azure
2
+ module Armrest
3
+ # Abstract base class for use by role related service classes.
4
+ class RoleService < ArmrestService
5
+ # Most methods accept any one the following options, and their possible
6
+ # values, that defines the scope for that operation:
7
+ #
8
+ # :subscription => Set to true for subscription level scope
9
+ # :resource_group => Name of resource group
10
+ # :resource => A resource.id string
11
+ #
12
+ # The options you define determine the scope of the request:
13
+ #
14
+ # :subscription => /subscriptions/{subscription-id}
15
+ # :resource_group => /subscriptions/{subscription-id}/resourceGroups/some_group
16
+ # :resource => /subscriptions/{subscription-id}/resourceGroups/some_group/providers/Microsoft.Web/sites/mysite1
17
+ #
18
+ # Lastly, you can supply a :filter in order to filter results.
19
+ #
20
+ # Various list methods have been provided for convenience as well, such
21
+ # as the list_all method, which lists all roles at the subscription level.
22
+
23
+ # Gets information for the role assignment by name, where the "name"
24
+ # is really just the last portion (GUID) of an ID string.
25
+ #
26
+ def get_by_name(role_name, options = {})
27
+ url = build_url(options.merge(:subscription => true), role_name)
28
+ response = rest_get(url)
29
+ model_class.new(response.body)
30
+ end
31
+
32
+ alias get get_by_name
33
+
34
+ # Gets information for the role assignment via a resource string ID.
35
+ #
36
+ def get_by_id(role_id, options = {})
37
+ url = build_url(options.merge(:resource => role_id))
38
+ response = rest_get(url)
39
+ model_class.new(response.body)
40
+ end
41
+
42
+ alias get_by_resource get_by_id
43
+
44
+ # List all role assignments for the current subscription.
45
+ #
46
+ def list_all(options = {})
47
+ url = build_url(options.merge(:subscription => true))
48
+ response = rest_get(url)
49
+ Azure::Armrest::ArmrestCollection.create_from_response(response, model_class)
50
+ end
51
+
52
+ alias list_for_subscription list_all
53
+
54
+ # List all role assignments for the given +resource_group+.
55
+ #
56
+ def list(resource_group, options = {})
57
+ url = build_url(options.merge(:resource_group => resource_group))
58
+ response = rest_get(url)
59
+ Azure::Armrest::ArmrestCollection.create_from_response(response, model_class)
60
+ end
61
+
62
+ alias list_for_resource_group list
63
+
64
+ # List all role assignments for the given +resource+.
65
+ #
66
+ # Example:
67
+ #
68
+ # vms = Azure::Armrest::VirtualMachineService.new(conf)
69
+ # ads = Azure::Armrest::Role::AssignmentService.new(conf)
70
+ #
71
+ # vm = vms.get('some_vm', 'some_group')
72
+ # ads.list_for_resource(vm.id)
73
+ #
74
+ def list_for_resource(resource, options = {})
75
+ url = build_url(options.merge(:resource => resource))
76
+ response = rest_get(url)
77
+ Azure::Armrest::ArmrestCollection.create_from_response(response, model_class)
78
+ end
79
+
80
+ private
81
+
82
+ def build_url(options = {}, property = nil)
83
+ resource = options.delete(:resource)
84
+ resource_group = options.delete(:resource_group)
85
+ subscription = options.delete(:subscription)
86
+
87
+ if subscription
88
+ url = File.join(base_url, 'providers', provider, service_name)
89
+ elsif resource_group
90
+ url = File.join(base_url, 'resourceGroups', resource_group, 'providers', provider, service_name)
91
+ else # resource
92
+ url = File.join(configuration.environment.resource_url, resource, 'providers', provider, service_name)
93
+ end
94
+
95
+ url = File.join(url, property) if property
96
+ url = "#{url}?api-version=#{api_version}"
97
+
98
+ options.each { |key, value| url << "&$#{key}=#{value}" }
99
+
100
+ url
101
+ end
102
+ end #RoleService
103
+ end
104
+ end
@@ -5,13 +5,13 @@ module Azure
5
5
  # Role namespace
6
6
  module Role
7
7
  # Base class for managing Role Assignments
8
- class AssignmentService < ResourceGroupBasedService
8
+ class AssignmentService < RoleService
9
9
  # Create and return a new AssignmentService instance.
10
10
  #
11
11
  def initialize(armrest_configuration, options = {})
12
12
  super(armrest_configuration, 'roleAssignments', 'Microsoft.Authorization', options)
13
13
  end
14
- end # AssignmentService
15
- end # Role
16
- end # Armrest
17
- end # Azure
14
+ end
15
+ end
16
+ end
17
+ end
@@ -5,13 +5,13 @@ module Azure
5
5
  # Role namespace
6
6
  module Role
7
7
  # Base class for managing Role Definitions
8
- class DefinitionService < ResourceGroupBasedService
8
+ class DefinitionService < RoleService
9
9
  # Create and return a new DefinitionService instance.
10
10
  #
11
11
  def initialize(armrest_configuration, options = {})
12
12
  super(armrest_configuration, 'roleDefinitions', 'Microsoft.Authorization', options)
13
13
  end
14
- end # DefinitionService
15
- end # Role
16
- end # Armrest
17
- end # Azure
14
+ end
15
+ end
16
+ end
17
+ end
@@ -1,6 +1,6 @@
1
1
  module Azure
2
2
  module Armrest
3
3
  # The version of the azure-armrest library.
4
- VERSION = '0.5.2'.freeze
4
+ VERSION = '0.6.0'.freeze
5
5
  end
6
6
  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.5.2
4
+ version: 0.6.0
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: 2016-12-22 00:00:00.000000000 Z
14
+ date: 2017-02-07 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: json
@@ -224,6 +224,8 @@ extra_rdoc_files: []
224
224
  files:
225
225
  - ".gitignore"
226
226
  - ".rspec"
227
+ - ".rubocop.yml"
228
+ - ".rubocop_local.yml"
227
229
  - ".travis.yml"
228
230
  - CHANGES
229
231
  - Gemfile
@@ -261,6 +263,7 @@ files:
261
263
  - lib/azure/armrest/resource_group_service.rb
262
264
  - lib/azure/armrest/resource_provider_service.rb
263
265
  - lib/azure/armrest/resource_service.rb
266
+ - lib/azure/armrest/role.rb
264
267
  - lib/azure/armrest/role/assignment_service.rb
265
268
  - lib/azure/armrest/role/definition_service.rb
266
269
  - lib/azure/armrest/sql/sql_database_service.rb