azure 0.6.4 → 0.7.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (110) hide show
  1. checksums.yaml +4 -4
  2. data/.env_sample +11 -0
  3. data/.gitignore +4 -1
  4. data/.travis.yml +3 -1
  5. data/ChangeLog.txt +17 -1
  6. data/LICENSE.txt +202 -0
  7. data/README.md +58 -20
  8. data/Rakefile +27 -35
  9. data/azure.gemspec +17 -13
  10. data/bin/pfxer +35 -0
  11. data/lib/azure.rb +8 -0
  12. data/lib/azure/base_management/base_management_service.rb +24 -26
  13. data/lib/azure/base_management/management_http_request.rb +17 -14
  14. data/lib/azure/base_management/serialization.rb +1 -0
  15. data/lib/azure/blob/auth/shared_access_signature.rb +141 -0
  16. data/lib/azure/blob/blob_service.rb +221 -217
  17. data/lib/azure/cloud_service_management/cloud_service_management_service.rb +27 -30
  18. data/lib/azure/cloud_service_management/serialization.rb +1 -0
  19. data/lib/azure/core.rb +17 -15
  20. data/lib/azure/core/configuration.rb +7 -0
  21. data/lib/azure/core/http/http_error.rb +1 -1
  22. data/lib/azure/core/http/http_request.rb +4 -1
  23. data/lib/azure/core/utility.rb +16 -1
  24. data/lib/azure/queue/queue_service.rb +13 -13
  25. data/lib/azure/service/cors.rb +11 -0
  26. data/lib/azure/service/cors_rule.rb +15 -0
  27. data/lib/azure/service/serialization.rb +69 -10
  28. data/lib/azure/service/storage_service.rb +10 -6
  29. data/lib/azure/service/storage_service_properties.rb +8 -3
  30. data/lib/azure/service_bus/brokered_message.rb +1 -1
  31. data/lib/azure/service_bus/relay.rb +88 -0
  32. data/lib/azure/service_bus/serialization.rb +1 -0
  33. data/lib/azure/service_bus/service_bus_service.rb +70 -4
  34. data/lib/azure/sql_database_management/serialization.rb +1 -0
  35. data/lib/azure/sql_database_management/sql_database_management_service.rb +22 -22
  36. data/lib/azure/storage_management/serialization.rb +34 -14
  37. data/lib/azure/storage_management/storage_account.rb +9 -1
  38. data/lib/azure/storage_management/storage_management_service.rb +74 -32
  39. data/lib/azure/table/batch.rb +6 -6
  40. data/lib/azure/table/table_service.rb +13 -13
  41. data/lib/azure/version.rb +3 -3
  42. data/lib/azure/virtual_machine_image_management/serialization.rb +19 -0
  43. data/lib/azure/virtual_machine_image_management/virtual_machine_image.rb +1 -1
  44. data/lib/azure/virtual_machine_image_management/virtual_machine_image_management_service.rb +30 -7
  45. data/lib/azure/virtual_machine_management/serialization.rb +32 -12
  46. data/lib/azure/virtual_machine_management/virtual_machine.rb +1 -0
  47. data/lib/azure/virtual_machine_management/virtual_machine_management_service.rb +92 -81
  48. data/lib/azure/virtual_network_management/serialization.rb +12 -5
  49. data/lib/azure/virtual_network_management/virtual_network.rb +1 -0
  50. data/lib/azure/virtual_network_management/virtual_network_management_service.rb +11 -11
  51. data/test/fixtures/get_storage_account_properties.xml +6 -4
  52. data/test/fixtures/{list_images.xml → list_os_images.xml} +1 -1
  53. data/test/fixtures/list_storage_accounts.xml +2 -0
  54. data/test/fixtures/list_vm_images.xml +21 -0
  55. data/test/fixtures/metrics.xml +2 -2
  56. data/test/fixtures/sb_default_create_relay_response.xml +15 -0
  57. data/test/fixtures/storage_service_keys.xml +8 -0
  58. data/test/fixtures/storage_service_properties.xml +35 -3
  59. data/test/fixtures/updated_storage_accounts.xml +2 -0
  60. data/test/fixtures/virtual_machine.xml +3 -1
  61. data/test/integration/affinity_group/Affinity_test.rb +1 -1
  62. data/test/integration/affinity_group/Create_Affinity_test.rb +8 -7
  63. data/test/integration/affinity_group/Delete_Affinity_test.rb +3 -3
  64. data/test/integration/affinity_group/List_Affinity_test.rb +1 -1
  65. data/test/integration/affinity_group/Update_Affinity_test.rb +9 -8
  66. data/test/integration/cloud_service/Cloud_Create_test.rb +3 -2
  67. data/test/integration/cloud_service/Cloud_Delete_test.rb +5 -4
  68. data/test/integration/database/create_sql_server_firewall_test.rb +1 -1
  69. data/test/integration/database/create_sql_server_test.rb +1 -1
  70. data/test/integration/database/delete_sql_server_firewall_test.rb +1 -1
  71. data/test/integration/database/delete_sql_server_test.rb +1 -1
  72. data/test/integration/database/list_sql_server_firewall_test.rb +1 -1
  73. data/test/integration/database/list_sql_servers_test.rb +1 -1
  74. data/test/integration/database/reset_password_sql_server_test.rb +1 -1
  75. data/test/integration/service_bus/queues_test.rb +22 -22
  76. data/test/integration/service_bus/relay_test.rb +132 -0
  77. data/test/integration/storage_management/storage_management_test.rb +58 -33
  78. data/test/integration/test_helper.rb +11 -15
  79. data/test/integration/vm/VM_Create_test.rb +17 -18
  80. data/test/integration/vm/VM_Delete_test.rb +2 -4
  81. data/test/integration/vm/VM_Operations_test.rb +1 -2
  82. data/test/integration/vnet/Virtual_Network_Create_test.rb +9 -15
  83. data/test/integration/vnet/Virtual_Network_list_test.rb +4 -9
  84. data/test/support/name_generator.rb +8 -0
  85. data/test/support/virtual_network_helper.rb +2 -2
  86. data/test/test_helper.rb +13 -24
  87. data/test/unit/affinity_group/affinity_group_test.rb +10 -13
  88. data/test/unit/affinity_group/serialization_test.rb +7 -8
  89. data/test/unit/base_management/location_test.rb +1 -2
  90. data/test/unit/blob/auth/shared_access_signature_test.rb +71 -0
  91. data/test/unit/blob/blob_service_test.rb +393 -371
  92. data/test/unit/cloud_service_management/cloud_service_management_service_test.rb +16 -16
  93. data/test/unit/core/auth/shared_key_lite_test.rb +4 -4
  94. data/test/unit/core/auth/shared_key_test.rb +2 -2
  95. data/test/unit/core/http/http_error_test.rb +10 -5
  96. data/test/unit/core/http/http_request_test.rb +72 -25
  97. data/test/unit/database/serialization_test.rb +7 -7
  98. data/test/unit/database/sql_database_server_service_test.rb +43 -47
  99. data/test/unit/service/serialization_test.rb +40 -9
  100. data/test/unit/service/storage_service_test.rb +13 -11
  101. data/test/unit/storage_management/serialization_test.rb +26 -14
  102. data/test/unit/storage_management/storage_management_service_test.rb +48 -62
  103. data/test/unit/virtual_machine_image_management/serialization_test.rb +20 -5
  104. data/test/unit/virtual_machine_image_management/virtual_machine_image_management_service_test.rb +78 -29
  105. data/test/unit/virtual_machine_management/serialization_test.rb +112 -43
  106. data/test/unit/virtual_machine_management/virtual_machine_management_service_test.rb +123 -100
  107. data/test/unit/vnet/serialization_test.rb +7 -7
  108. data/test/unit/vnet/virtual_network_management_service_test.rb +1 -1
  109. metadata +70 -16
  110. data/test/fixtures/certificate.pem +0 -21
data/Rakefile CHANGED
@@ -12,37 +12,34 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
  #--------------------------------------------------------------------------
15
- require "rake/testtask"
16
- require "rubygems/package_task"
15
+ require 'rake/testtask'
16
+ require 'rubygems/package_task'
17
+ require 'dotenv/tasks'
17
18
 
18
- gem_spec = eval(File.read("./azure.gemspec"))
19
+ gem_spec = eval(File.read('./azure.gemspec'))
19
20
  Gem::PackageTask.new(gem_spec) do |pkg|
20
21
  pkg.need_zip = false
21
22
  pkg.need_tar = false
22
23
  end
23
24
 
24
25
  namespace :test do
25
- task :require_environment do
26
+ task :require_environment => :dotenv do
26
27
  unset_environment = [
27
- ENV.fetch("AZURE_STORAGE_ACCOUNT", nil),
28
- ENV.fetch("AZURE_STORAGE_ACCESS_KEY", nil),
29
- # ENV.fetch("AZURE_STORAGE_TABLE_HOST", nil),
30
- # ENV.fetch("AZURE_STORAGE_BLOB_HOST", nil),
31
- # ENV.fetch("AZURE_STORAGE_QUEUE_HOST", nil),
32
- ENV.fetch("AZURE_SERVICEBUS_NAMESPACE", nil),
33
- ENV.fetch("AZURE_SERVICEBUS_ACCESS_KEY", nil),
34
- # ENV.fetch("AZURE_SERVICEBUS_ISSUER", nil)
28
+ ENV.fetch('AZURE_STORAGE_ACCOUNT', nil),
29
+ ENV.fetch('AZURE_STORAGE_ACCESS_KEY', nil),
30
+ ENV.fetch('AZURE_SERVICEBUS_NAMESPACE', nil),
31
+ ENV.fetch('AZURE_SERVICEBUS_ACCESS_KEY', nil),
35
32
  ENV.fetch('AZURE_MANAGEMENT_CERTIFICATE', nil),
36
33
  ENV.fetch('AZURE_SUBSCRIPTION_ID', nil)
37
34
  ].include?(nil)
38
35
 
39
- abort "[ABORTING] Configure your environment to run the integration tests" if unset_environment
36
+ abort '[ABORTING] Configure your environment to run the integration tests' if unset_environment
40
37
  end
41
38
 
42
39
  Rake::TestTask.new :unit do |t|
43
- t.pattern = "test/unit/**/*_test.rb"
40
+ t.pattern = 'test/unit/**/*_test.rb'
44
41
  t.verbose = true
45
- t.libs = ["lib", "test"]
42
+ t.libs = %w(lib test)
46
43
  end
47
44
 
48
45
  namespace :unit do
@@ -50,10 +47,10 @@ namespace :test do
50
47
  Rake::TestTask.new component do |t|
51
48
  t.pattern = "test/unit/#{component}/**/*_test.rb"
52
49
  t.verbose = true
53
- t.libs = ["lib", "test"]
50
+ t.libs = %w(lib test)
54
51
  end
55
52
 
56
- task component => "test:require_environment"
53
+ task component => 'test:require_environment'
57
54
  end
58
55
 
59
56
  component_task :affinity_group
@@ -71,9 +68,9 @@ namespace :test do
71
68
  end
72
69
 
73
70
  Rake::TestTask.new :integration do |t|
74
- t.pattern = "test/integration/**/*_test.rb"
71
+ t.pattern = 'test/integration/**/*_test.rb'
75
72
  t.verbose = true
76
- t.libs = ["lib", "test"]
73
+ t.libs = %w(lib test)
77
74
  end
78
75
 
79
76
  task :integration => :require_environment
@@ -83,10 +80,10 @@ namespace :test do
83
80
  Rake::TestTask.new component do |t|
84
81
  t.pattern = "test/integration/#{component}/**/*_test.rb"
85
82
  t.verbose = true
86
- t.libs = ["lib", "test"]
83
+ t.libs = %w(lib test)
87
84
  end
88
85
 
89
- task component => "test:require_environment"
86
+ task component => 'test:require_environment'
90
87
  end
91
88
 
92
89
  component_task :affinity_group
@@ -103,27 +100,22 @@ namespace :test do
103
100
  end
104
101
 
105
102
  task :cleanup => :require_environment do
106
- $:.unshift "lib"
103
+ $:.unshift 'lib'
107
104
  require 'azure'
108
105
 
109
106
  Azure.configure do |config|
110
- config.access_key = ENV.fetch("AZURE_STORAGE_ACCESS_KEY")
111
- config.account_name = ENV.fetch("AZURE_STORAGE_ACCOUNT")
112
- # config.table_host = ENV.fetch("AZURE_STORAGE_TABLE_HOST")
113
- # config.blob_host = ENV.fetch("AZURE_STORAGE_BLOB_HOST")
114
- # config.queue_host = ENV.fetch("AZURE_STORAGE_QUEUE_HOST")
115
-
116
- config.acs_namespace = ENV.fetch("AZURE_SERVICEBUS_NAMESPACE")
117
- config.sb_access_key = ENV.fetch("AZURE_SERVICEBUS_ACCESS_KEY")
118
- # config.sb_issuer = ENV.fetch("AZURE_SERVICEBUS_ISSUER")
107
+ config.access_key = ENV.fetch('AZURE_STORAGE_ACCESS_KEY')
108
+ config.account_name = ENV.fetch('AZURE_STORAGE_ACCOUNT')
109
+ config.acs_namespace = ENV.fetch('AZURE_SERVICEBUS_NAMESPACE')
110
+ config.sb_access_key = ENV.fetch('AZURE_SERVICEBUS_ACCESS_KEY')
119
111
  config.management_certificate = ENV.fetch('AZURE_MANAGEMENT_CERTIFICATE')
120
- config.management_endpoint = ENV.fetch("AZURE_MANAGEMENT_ENDPOINT")
121
- config.sql_database_management_endpoint = ENV.fetch("AZURE_SQL_DATABASE_MANAGEMENT_ENDPOINT")
122
- config.subscription_id = ENV.fetch("AZURE_SUBSCRIPTION_ID")
112
+ config.management_endpoint = ENV.fetch('AZURE_MANAGEMENT_ENDPOINT')
113
+ config.sql_database_management_endpoint = ENV.fetch('AZURE_SQL_DATABASE_MANAGEMENT_ENDPOINT')
114
+ config.subscription_id = ENV.fetch('AZURE_SUBSCRIPTION_ID')
123
115
  end
124
116
  end
125
117
  end
126
118
 
127
- task :test => ["test:unit", "test:integration"]
119
+ task :test => %w(test:unit test:integration)
128
120
 
129
121
  task :default => :test
@@ -12,32 +12,36 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
  #--------------------------------------------------------------------------
15
- require "date"
15
+ require 'date'
16
16
 
17
17
  require File.expand_path('../lib/azure/version', __FILE__)
18
18
 
19
19
  Gem::Specification.new do |s|
20
- s.name = "azure"
20
+ s.name = 'azure'
21
21
  s.version = Azure::Version
22
-
23
- s.authors = ["Microsoft Corporation", "AppFog"]
24
- s.email = "azureruby@microsoft.com"
25
- s.description = "Windows Azure Client Library for Ruby"
26
- s.summary = "Official ruby client library to consume Windows Azure services."
27
- s.homepage = "http://github.com/WindowsAzure/azure-sdk-for-ruby"
22
+ s.authors = ['Microsoft Corporation', 'AppFog']
23
+ s.email = 'azureruby@microsoft.com'
24
+ s.description = 'Windows Azure Client Library for Ruby'
25
+ s.summary = 'Official ruby client library to consume Windows Azure services.'
26
+ s.homepage = 'http://github.com/azure/azure-sdk-for-ruby'
28
27
  s.license = 'Apache License, Version 2.0'
29
28
  s.files = `git ls-files`.split("\n")
29
+ s.bindir = 'bin'
30
+ s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
30
31
 
31
32
  s.required_ruby_version = '>= 1.9.3'
32
33
 
33
- s.add_runtime_dependency('nokogiri', "~> 1.5")
34
- s.add_runtime_dependency("mime-types", "~> 1.0")
34
+ s.add_runtime_dependency('nokogiri', '~> 1.6')
35
+ s.add_runtime_dependency('mime-types', '~> 1.0')
35
36
  s.add_runtime_dependency('json', '~> 1.8')
36
37
  s.add_runtime_dependency('uuid', '~> 2.0')
37
38
  s.add_runtime_dependency('systemu', '~> 2.6')
39
+ s.add_runtime_dependency('thor', '~> 0.19')
38
40
 
39
- s.add_development_dependency("rake", '~> 10.0')
40
- s.add_development_dependency("minitest", "~> 3.0")
41
+ s.add_development_dependency('rake', '~> 10.0')
42
+ s.add_development_dependency('minitest', '~> 5')
43
+ s.add_development_dependency('minitest-reporters', '~> 1')
41
44
  s.add_development_dependency('mocha', '~> 1.0')
42
- s.add_development_dependency('turn', '~> 0.9')
45
+ s.add_development_dependency('timecop', '~> 0.7')
46
+ s.add_development_dependency('dotenv', '~> 2.0' )
43
47
  end
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env ruby -U
2
+
3
+ require 'azure'
4
+ require 'thor'
5
+ require 'fileutils'
6
+
7
+ module Azure
8
+ class Pfxer < Thor
9
+ desc 'transform', 'Transforms a publish settings file from Azure into a .pfx'
10
+
11
+ long_desc <<-TRANSFORM
12
+
13
+ `transform` will create a .pfx file from an Azure publish settings file. The publish settings file contains a
14
+ pfx, but the pfx is base64 encode within the publish settings xml structure. This is here to make that a little
15
+ easier.
16
+
17
+ TRANSFORM
18
+
19
+ option :in, required: true, desc: 'Path to publish settings file'
20
+ option :out, desc: 'Path to where you want your .pfx'
21
+ def transform
22
+ path = File.expand_path(options[:in])
23
+ if File.exists?(path)
24
+ pub_settings_xml = Nokogiri::XML(File.read(path))
25
+ b64_pfx = pub_settings_xml.css('PublishData PublishProfile Subscription')[0]['ManagementCertificate']
26
+ pfx = Base64.decode64(b64_pfx)
27
+ file_name = File.basename(path, '.publishsettings').downcase.gsub(' ', '_')
28
+ out_path = options[:out] || File.join(File.dirname(path), file_name + '.pfx')
29
+ File.binwrite(File.expand_path(out_path), pfx)
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ Azure::Pfxer.start(ARGV)
@@ -14,6 +14,13 @@
14
14
  #--------------------------------------------------------------------------
15
15
  module Azure; end
16
16
 
17
+ require 'rubygems'
18
+ require 'nokogiri'
19
+ require 'base64'
20
+ require 'openssl'
21
+ require 'uri'
22
+ require 'rexml/document'
23
+
17
24
  require 'azure/core'
18
25
  require 'azure/blob/blob_service'
19
26
  require 'azure/queue/queue_service'
@@ -50,3 +57,4 @@ Azure::StorageManagementService = Azure::StorageManagement::StorageManagementSer
50
57
  Azure::VirtualMachineManagementService = Azure::VirtualMachineManagement::VirtualMachineManagementService
51
58
  Azure::SqlDatabaseManagementService = Azure::SqlDatabaseManagement::SqlDatabaseManagementService
52
59
  Azure::VirtualNetworkManagementService = Azure::VirtualNetworkManagement::VirtualNetworkManagementService
60
+ Azure::Loggerx = Azure::Core::Logger
@@ -12,33 +12,31 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
  #--------------------------------------------------------------------------
15
- require 'rubygems'
16
- require 'nokogiri'
17
- require 'base64'
18
- require 'openssl'
19
- require 'uri'
20
- require 'rexml/document'
15
+
21
16
  require 'azure/base_management/serialization'
22
17
  require 'azure/base_management/location'
23
18
  require 'azure/base_management/affinity_group'
24
19
 
25
- include Azure::BaseManagement
26
- include Azure::Core::Utility
27
- Loggerx = Azure::Core::Logger
28
-
29
20
  module Azure
30
21
  module BaseManagement
31
22
  class BaseManagementService
32
23
  def initialize
33
24
  validate_configuration
34
- cert_file = File.read(Azure.config.management_certificate)
25
+ cert_file = Azure.config.management_certificate
26
+
27
+ if File.file?(cert_file) && cert_file =~ /(pem)$/
28
+ cert_file = File.read(Azure.config.management_certificate)
29
+ else
30
+ cert_file = File.binread(Azure.config.management_certificate)
31
+ end
32
+
35
33
  begin
36
34
  if Azure.config.management_certificate =~ /(pem)$/
37
35
  certificate_key = OpenSSL::X509::Certificate.new(cert_file)
38
36
  private_key = OpenSSL::PKey::RSA.new(cert_file)
39
37
  else
40
38
  # Parse pfx content
41
- cert_content = OpenSSL::PKCS12.new(Base64.decode64(cert_file))
39
+ cert_content = OpenSSL::PKCS12.new(cert_file)
42
40
  certificate_key = OpenSSL::X509::Certificate.new(
43
41
  cert_content.certificate.to_pem
44
42
  )
@@ -76,7 +74,7 @@ module Azure
76
74
  #
77
75
  # Returns an array of Azure::BaseManagement::Location objects
78
76
  def list_locations
79
- request = ManagementHttpRequest.new(:get, '/locations')
77
+ request = Azure::BaseManagement::ManagementHttpRequest.new(:get, '/locations')
80
78
  response = request.call
81
79
  Serialization.locations_from_xml(response)
82
80
  end
@@ -84,12 +82,12 @@ module Azure
84
82
  # Public: Gets a lists the affinity groups associated with
85
83
  # the specified subscription.
86
84
  #
87
- # See http://msdn.microsoft.com/en-us/library/windowsazure/ee460797.aspx
85
+ # See http://msdn.microsoft.com/en-us/library/azure/ee460797.aspx
88
86
  #
89
87
  # Returns an array of Azure::BaseManagement::AffinityGroup objects
90
88
  def list_affinity_groups
91
89
  request_path = '/affinitygroups'
92
- request = ManagementHttpRequest.new(:get, request_path, nil)
90
+ request = Azure::BaseManagement::ManagementHttpRequest.new(:get, request_path, nil)
93
91
  response = request.call
94
92
  Serialization.affinity_groups_from_xml(response)
95
93
  end
@@ -110,7 +108,7 @@ module Azure
110
108
  # * +:description+ - String. A description for the affinity group.
111
109
  # (optional)
112
110
  #
113
- # See http://msdn.microsoft.com/en-us/library/windowsazure/gg715317.aspx
111
+ # See http://msdn.microsoft.com/en-us/library/azure/gg715317.aspx
114
112
  #
115
113
  # Returns: None
116
114
  def create_affinity_group(name, location, label, options = {})
@@ -130,9 +128,9 @@ module Azure
130
128
  label,
131
129
  options)
132
130
  request_path = '/affinitygroups'
133
- request = ManagementHttpRequest.new(:post, request_path, body)
131
+ request = Azure::BaseManagement::ManagementHttpRequest.new(:post, request_path, body)
134
132
  request.call
135
- Loggerx.info "Affinity Group #{name} is created."
133
+ Azure::Loggerx.info "Affinity Group #{name} is created."
136
134
  end
137
135
  end
138
136
 
@@ -151,7 +149,7 @@ module Azure
151
149
  # * +:description+ - String. A description for the affinity group.
152
150
  # (optional)
153
151
  #
154
- # See http://msdn.microsoft.com/en-us/library/windowsazure/gg715316.aspx
152
+ # See http://msdn.microsoft.com/en-us/library/azure/gg715316.aspx
155
153
  #
156
154
  # Returns: None
157
155
  def update_affinity_group(name, label, options = {})
@@ -159,9 +157,9 @@ module Azure
159
157
  if affinity_group(name)
160
158
  body = Serialization.resource_to_xml(label, options)
161
159
  request_path = "/affinitygroups/#{name}"
162
- request = ManagementHttpRequest.new(:put, request_path, body)
160
+ request = Azure::BaseManagement::ManagementHttpRequest.new(:put, request_path, body)
163
161
  request.call
164
- Loggerx.info "Affinity Group #{name} is updated."
162
+ Azure::Loggerx.info "Affinity Group #{name} is updated."
165
163
  end
166
164
  end
167
165
 
@@ -171,15 +169,15 @@ module Azure
171
169
  #
172
170
  # * +name+ - String. Affinity Group name.
173
171
  #
174
- # See http://msdn.microsoft.com/en-us/library/windowsazure/gg715314.aspx
172
+ # See http://msdn.microsoft.com/en-us/library/azure/gg715314.aspx
175
173
  #
176
174
  # Returns: None
177
175
  def delete_affinity_group(name)
178
176
  if affinity_group(name)
179
177
  request_path = "/affinitygroups/#{name}"
180
- request = ManagementHttpRequest.new(:delete, request_path)
178
+ request = Azure::BaseManagement::ManagementHttpRequest.new(:delete, request_path)
181
179
  request.call
182
- Loggerx.info "Deleted affinity group #{name}."
180
+ Azure::Loggerx.info "Deleted affinity group #{name}."
183
181
  end
184
182
  end
185
183
 
@@ -190,13 +188,13 @@ module Azure
190
188
  #
191
189
  # * +name+ - String. Affinity Group name.
192
190
  #
193
- # See http://msdn.microsoft.com/en-us/library/windowsazure/ee460789.aspx
191
+ # See http://msdn.microsoft.com/en-us/library/azure/ee460789.aspx
194
192
  #
195
193
  # Returns: Azure::BaseManagement::AffinityGroup object
196
194
  def get_affinity_group(name)
197
195
  if affinity_group(name)
198
196
  request_path = "/affinitygroups/#{name}"
199
- request = ManagementHttpRequest.new(:get, request_path)
197
+ request = Azure::BaseManagement::ManagementHttpRequest.new(:get, request_path)
200
198
  response = request.call
201
199
  Serialization.affinity_group_from_xml(response)
202
200
  end
@@ -21,6 +21,7 @@ include Azure::Core::Http
21
21
  module Azure
22
22
  module BaseManagement
23
23
  class ManagementHttpRequest < HttpRequest
24
+ include Azure::Core::Utility
24
25
  attr_accessor :uri, :warn, :key, :cert
25
26
 
26
27
  # Public: Creates the ManagementHttpRequest
@@ -34,11 +35,11 @@ module Azure
34
35
  super
35
36
  @warn = false
36
37
  content_length = body ? body.bytesize.to_s : '0'
37
- @headers = {
38
- 'x-ms-version' => '2014-04-01',
39
- 'Content-Type' => 'application/xml',
40
- 'Content-Length' => content_length
41
- }
38
+ @headers.update({
39
+ 'x-ms-version' => '2014-06-01',
40
+ 'Content-Type' => 'application/xml',
41
+ 'Content-Length' => content_length
42
+ })
42
43
  @uri = URI.parse(Azure.config.management_endpoint + Azure.config.subscription_id + path)
43
44
  @key = Azure.config.http_private_key
44
45
  @cert = Azure.config.http_certificate_key
@@ -66,7 +67,7 @@ module Azure
66
67
  def wait_for_completion(response)
67
68
  ret_val = Nokogiri::XML response.body
68
69
  if ret_val.at_css('Error Code') && ret_val.at_css('Error Code').content == 'AuthenticationFailed'
69
- Loggerx.error_with_exit ret_val.at_css('Error Code').content + ' : ' + ret_val.at_css('Error Message').content
70
+ Azure::Loggerx.error_with_exit ret_val.at_css('Error Code').content + ' : ' + ret_val.at_css('Error Message').content
70
71
  end
71
72
  if response.status_code.to_i == 200 || response.status_code.to_i == 201
72
73
  return response
@@ -74,16 +75,18 @@ module Azure
74
75
  rebuild_request response
75
76
  elsif response.status_code.to_i > 201 && response.status_code.to_i <= 299
76
77
  check_completion(response.headers['x-ms-request-id'])
78
+ elsif response.status_code.to_i == 307
79
+ @uri = URI::parse (response.headers['location'])
80
+ call
77
81
  elsif warn && !response.success?
78
- # Loggerx.warn ret_val.at_css('Error Code').content + ' : ' + ret_val.at_css('Error Message').content
79
82
  elsif response.body
80
83
  if ret_val.at_css('Error Code') && ret_val.at_css('Error Message')
81
- Loggerx.error_with_exit ret_val.at_css('Error Code').content + ' : ' + ret_val.at_css('Error Message').content
84
+ Azure::Loggerx.error_with_exit ret_val.at_css('Error Code').content + ' : ' + ret_val.at_css('Error Message').content
82
85
  else
83
- Loggerx.exception_message "http error: #{response.status_code}"
86
+ Azure::Loggerx.exception_message "http error: #{response.status_code}"
84
87
  end
85
88
  else
86
- Loggerx.exception_message "http error: #{response.status_code}"
89
+ Azure::Loggerx.exception_message "http error: #{response.status_code}"
87
90
  end
88
91
  end
89
92
 
@@ -94,7 +97,7 @@ module Azure
94
97
  #
95
98
  # * +request_id+ - String. x-ms-request-id response header of request
96
99
  #
97
- # See: http://msdn.microsoft.com/en-us/library/windowsazure/ee460783.aspx
100
+ # See: http://msdn.microsoft.com/en-us/library/azure/ee460783.aspx
98
101
  #
99
102
  # Print Error or Success of Operation.
100
103
  def check_completion(request_id)
@@ -122,9 +125,9 @@ module Azure
122
125
  if status.downcase != 'succeeded'
123
126
  error_code = xml_content(ret_val, 'Operation Error Code')
124
127
  error_msg = xml_content(ret_val, 'Operation Error Message')
125
- Loggerx.exception_message "#{error_code}: #{error_msg}"
128
+ Azure::Loggerx.exception_message "#{error_code}: #{error_msg}"
126
129
  else
127
- Loggerx.success "#{status.downcase} (#{status_code})"
130
+ Azure::Loggerx.success "#{status.downcase} (#{status_code})"
128
131
  end
129
132
  return
130
133
  else
@@ -169,4 +172,4 @@ module Azure
169
172
  end
170
173
  end
171
174
  end
172
- end
175
+ end