azure 0.7.0.pre → 0.7.0.pre2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. checksums.yaml +4 -4
  2. data/.env_sample +3 -1
  3. data/.gitignore +15 -0
  4. data/LICENSE.txt +1 -1
  5. data/README.md +322 -248
  6. data/Rakefile +3 -1
  7. data/azure.gemspec +18 -14
  8. data/lib/azure.rb +124 -38
  9. data/lib/azure/base_management/base_management_service.rb +57 -69
  10. data/lib/azure/base_management/location.rb +1 -1
  11. data/lib/azure/base_management/management_http_request.rb +55 -58
  12. data/lib/azure/base_management/serialization.rb +5 -0
  13. data/lib/azure/base_management/sql_management_http_request.rb +10 -20
  14. data/lib/azure/blob/auth/shared_access_signature.rb +82 -76
  15. data/lib/azure/blob/blob_service.rb +196 -171
  16. data/lib/azure/client.rb +31 -0
  17. data/lib/azure/client_services.rb +98 -0
  18. data/lib/azure/cloud_service_management/cloud_service_management_service.rb +8 -10
  19. data/lib/azure/configurable.rb +290 -0
  20. data/lib/azure/core/auth/authorizer.rb +1 -1
  21. data/lib/azure/core/auth/shared_key.rb +48 -40
  22. data/lib/azure/core/auth/shared_key_lite.rb +9 -9
  23. data/lib/azure/core/auth/signer.rb +15 -12
  24. data/lib/azure/core/error.rb +2 -3
  25. data/lib/azure/core/filtered_service.rb +4 -3
  26. data/lib/azure/core/http/http_error.rb +10 -12
  27. data/lib/azure/core/http/http_request.rb +82 -69
  28. data/lib/azure/core/http/http_response.rb +12 -56
  29. data/lib/azure/core/http/signer_filter.rb +3 -4
  30. data/lib/azure/core/service.rb +8 -25
  31. data/lib/azure/core/signed_service.rb +7 -5
  32. data/lib/azure/core/utility.rb +45 -6
  33. data/lib/azure/default.rb +126 -0
  34. data/lib/azure/http_client.rb +85 -0
  35. data/lib/azure/queue/queue.rb +0 -1
  36. data/lib/azure/queue/queue_service.rb +6 -4
  37. data/lib/azure/queue/serialization.rb +0 -1
  38. data/lib/azure/service/storage_service.rb +9 -6
  39. data/lib/azure/service_bus/auth/shared_access_signer.rb +44 -0
  40. data/lib/azure/service_bus/auth/wrap_service.rb +5 -4
  41. data/lib/azure/service_bus/auth/wrap_signer.rb +14 -6
  42. data/lib/azure/service_bus/service_bus_service.rb +34 -30
  43. data/lib/azure/sql_database_management/errors.rb +11 -0
  44. data/lib/azure/sql_database_management/firewall_rule.rb +30 -0
  45. data/lib/azure/sql_database_management/serialization.rb +40 -53
  46. data/lib/azure/sql_database_management/sql_database_management_service.rb +141 -130
  47. data/lib/azure/sql_database_management/{sql_database.rb → sql_server.rb} +4 -3
  48. data/lib/azure/storage_management/storage_management_service.rb +9 -10
  49. data/lib/azure/table/auth/shared_key.rb +17 -50
  50. data/lib/azure/table/auth/shared_key_lite.rb +3 -3
  51. data/lib/azure/table/serialization.rb +24 -24
  52. data/lib/azure/table/table_service.rb +21 -18
  53. data/lib/azure/version.rb +1 -1
  54. data/lib/azure/virtual_machine_image_management/virtual_machine_image_management_service.rb +6 -12
  55. data/lib/azure/virtual_machine_management/serialization.rb +4 -1
  56. data/lib/azure/virtual_machine_management/virtual_machine.rb +1 -0
  57. data/lib/azure/virtual_machine_management/virtual_machine_management_service.rb +29 -37
  58. data/lib/azure/virtual_network_management/virtual_network_management_service.rb +5 -6
  59. data/test/fixtures/list_locations.xml +150 -0
  60. data/test/fixtures/list_sql_database.xml +6 -18
  61. data/test/fixtures/list_sql_server_firewall.xml +18 -18
  62. data/test/fixtures/management_certificate.pfx +0 -0
  63. data/test/fixtures/virtual_machine.xml +1 -0
  64. data/test/integration/affinity_group/Create_Affinity_test.rb +1 -1
  65. data/test/integration/affinity_group/Update_Affinity_test.rb +4 -0
  66. data/test/integration/blob/blob_gb18030_test.rb +29 -29
  67. data/test/integration/blob/blob_pages_test.rb +16 -16
  68. data/test/integration/blob/container/create_container_test.rb +6 -6
  69. data/test/integration/blob/container/root_container_test.rb +2 -1
  70. data/test/integration/database/create_sql_server_firewall_test.rb +26 -31
  71. data/test/integration/database/create_sql_server_test.rb +6 -6
  72. data/test/integration/database/delete_sql_server_firewall_test.rb +18 -24
  73. data/test/integration/database/delete_sql_server_test.rb +9 -22
  74. data/test/integration/database/list_sql_server_firewall_test.rb +7 -8
  75. data/test/integration/database/list_sql_servers_test.rb +4 -4
  76. data/test/integration/database/reset_password_sql_server_test.rb +9 -11
  77. data/test/integration/location/RoleSize_List_test.rb +35 -0
  78. data/test/integration/queue/list_queues_test.rb +0 -1
  79. data/test/integration/service_bus/queues_scenario_test.rb +11 -11
  80. data/test/integration/service_bus/queues_test.rb +2 -2
  81. data/test/integration/service_bus/subscriptions_test.rb +25 -25
  82. data/test/integration/service_bus/topics_scenario_test.rb +6 -6
  83. data/test/integration/service_bus/topics_test.rb +15 -15
  84. data/test/integration/table/query_entities_test.rb +1 -0
  85. data/test/integration/table/table_acl_test.rb +9 -9
  86. data/test/integration/test_helper.rb +11 -9
  87. data/test/integration/vm/VM_Create_test.rb +23 -20
  88. data/test/integration/vnet/Virtual_Network_list_test.rb +1 -1
  89. data/test/test_helper.rb +5 -0
  90. data/test/unit/affinity_group/affinity_group_test.rb +4 -4
  91. data/test/unit/base_management/base_management_service_test.rb +19 -0
  92. data/test/unit/base_management/location_test.rb +6 -6
  93. data/test/unit/base_management/role_size_test.rb +50 -0
  94. data/test/unit/blob/auth/shared_access_signature_test.rb +19 -19
  95. data/test/unit/blob/blob_service_test.rb +583 -582
  96. data/test/unit/cloud_service_management/cloud_service_management_service_test.rb +2 -2
  97. data/test/unit/config/azure_test.rb +112 -0
  98. data/test/unit/config/client_test.rb +37 -0
  99. data/test/unit/core/auth/shared_key_lite_test.rb +15 -15
  100. data/test/unit/core/auth/shared_key_test.rb +26 -26
  101. data/test/unit/core/http/http_error_test.rb +13 -14
  102. data/test/unit/core/http/http_request_test.rb +78 -53
  103. data/test/unit/core/http/http_response_test.rb +2 -27
  104. data/test/unit/core/http/retry_policy_test.rb +3 -3
  105. data/test/unit/core/utility_test.rb +122 -0
  106. data/test/unit/database/serialization_test.rb +17 -20
  107. data/test/unit/database/sql_database_server_service_test.rb +97 -40
  108. data/test/unit/http_client_test.rb +74 -0
  109. data/test/unit/service/storage_service_test.rb +105 -101
  110. data/test/unit/storage_management/storage_management_service_test.rb +28 -28
  111. data/test/unit/virtual_machine_image_management/virtual_machine_image_management_service_test.rb +4 -4
  112. data/test/unit/virtual_machine_management/virtual_machine_management_service_test.rb +37 -20
  113. data/test/unit/vnet/virtual_network_management_service_test.rb +1 -1
  114. metadata +91 -20
  115. data/lib/azure/core.rb +0 -41
  116. data/lib/azure/core/configuration.rb +0 -218
@@ -12,7 +12,7 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
  #--------------------------------------------------------------------------
15
- require "azure/table/auth/shared_key"
15
+ require 'azure/table/auth/shared_key'
16
16
 
17
17
  module Azure
18
18
  module Table
@@ -22,7 +22,7 @@ module Azure
22
22
  #
23
23
  # Returns a String.
24
24
  def name
25
- "SharedKeyLite"
25
+ 'SharedKeyLite'
26
26
  end
27
27
 
28
28
  # Generate the string to sign.
@@ -34,7 +34,7 @@ module Azure
34
34
  # Returns a plain text string.
35
35
  def signable_string(method, uri, headers)
36
36
  [
37
- headers.fetch("Date") { headers.fetch("x-ms-date") },
37
+ headers.fetch('Date') { headers.fetch('x-ms-date') },
38
38
  canonicalized_resource(uri)
39
39
  ].join("\n")
40
40
  end
@@ -17,19 +17,19 @@ require 'azure/service/serialization'
17
17
  require 'azure/table/guid'
18
18
  require 'azure/table/edmtype'
19
19
 
20
- require "time"
21
- require "date"
20
+ require 'time'
21
+ require 'date'
22
22
 
23
23
  module Azure
24
24
  module Table
25
25
  module Serialization
26
26
  include Azure::Service::Serialization
27
27
 
28
- def self.hash_to_entry_xml(hash, id=nil, xml=Nokogiri::XML::Builder.new(:encoding => "UTF-8"))
28
+ def self.hash_to_entry_xml(hash, id=nil, xml=Nokogiri::XML::Builder.new(:encoding => 'UTF-8'))
29
29
  entry_namespaces = {
30
- "xmlns" => "http://www.w3.org/2005/Atom",
31
- "xmlns:m" => "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata",
32
- "xmlns:d" => "http://schemas.microsoft.com/ado/2007/08/dataservices"
30
+ 'xmlns' => 'http://www.w3.org/2005/Atom',
31
+ 'xmlns:m' => 'http://schemas.microsoft.com/ado/2007/08/dataservices/metadata',
32
+ 'xmlns:d' => 'http://schemas.microsoft.com/ado/2007/08/dataservices'
33
33
  }
34
34
 
35
35
  xml.entry entry_namespaces do |entry|
@@ -45,19 +45,19 @@ module Azure
45
45
  xml
46
46
  end
47
47
 
48
- def self.hash_to_content_xml(hash, xml=Nokogiri::XML::Builder.new(:encoding => "UTF-8"))
49
- xml.send("content", :type => "application/xml") do |content|
50
- content.send("m:properties") do |properties|
48
+ def self.hash_to_content_xml(hash, xml=Nokogiri::XML::Builder.new(:encoding => 'UTF-8'))
49
+ xml.send('content', :type => 'application/xml') do |content|
50
+ content.send('m:properties') do |properties|
51
51
  hash.each do |key, val|
52
- key = key.encode("UTF-8") if key.is_a? String and !key.encoding.names.include?("BINARY")
53
- val = val.encode("UTF-8") if val.is_a? String and !val.encoding.names.include?("BINARY")
52
+ key = key.encode('UTF-8') if key.is_a? String and !key.encoding.names.include?('BINARY')
53
+ val = val.encode('UTF-8') if val.is_a? String and !val.encoding.names.include?('BINARY')
54
54
 
55
55
  type = Azure::Table::EdmType.property_type(val)
56
56
  attributes = {}
57
- attributes["m:type"] = type unless type.nil? || type.empty?
57
+ attributes['m:type'] = type unless type.nil? || type.empty?
58
58
 
59
59
  if val.nil?
60
- attributes["m:null"] = "true"
60
+ attributes['m:null'] = 'true'
61
61
  properties.send("d:#{key}", attributes)
62
62
  else
63
63
  properties.send("d:#{key}", Azure::Table::EdmType.serialize_value(type, val), attributes)
@@ -71,16 +71,16 @@ module Azure
71
71
 
72
72
  def self.entries_from_feed_xml(xml)
73
73
  xml = slopify(xml)
74
- expect_node("feed", xml)
74
+ expect_node('feed', xml)
75
75
 
76
- return nil unless (xml > "entry").any?
76
+ return nil unless (xml > 'entry').any?
77
77
 
78
78
  results = []
79
79
 
80
- if (xml > "entry").count == 0
81
- results.push hash_from_entry_xml((xml > "entry"))
80
+ if (xml > 'entry').count == 0
81
+ results.push hash_from_entry_xml((xml > 'entry'))
82
82
  else
83
- (xml > "entry").each do |entry|
83
+ (xml > 'entry').each do |entry|
84
84
  results.push hash_from_entry_xml(entry)
85
85
  end
86
86
  end
@@ -90,14 +90,14 @@ module Azure
90
90
 
91
91
  def self.hash_from_entry_xml(xml)
92
92
  xml = slopify(xml)
93
- expect_node("entry", xml)
93
+ expect_node('entry', xml)
94
94
  result = {}
95
- result[:etag] = xml["etag"]
96
- result[:updated] = Time.parse((xml > "updated").text) if (xml > "updated").any?
95
+ result[:etag] = xml['etag']
96
+ result[:updated] = Time.parse((xml > 'updated').text) if (xml > 'updated').any?
97
97
  properties = {}
98
- if (xml > "content").any?
99
- (xml > "content").first.first_element_child.element_children.each do |prop|
100
- properties[prop.name] = prop.text != "" ? Azure::Table::EdmType.unserialize_query_value(prop.text, prop["m:type"]) : prop["null"] ? nil : ""
98
+ if (xml > 'content').any?
99
+ (xml > 'content').first.first_element_child.element_children.each do |prop|
100
+ properties[prop.name] = prop.text != '' ? Azure::Table::EdmType.unserialize_query_value(prop.text, prop['m:type']) : prop['null'] ? nil : ''
101
101
  end
102
102
  end
103
103
  result[:properties] = properties
@@ -15,7 +15,6 @@
15
15
  require 'azure/service/storage_service'
16
16
 
17
17
  require 'azure/table/auth/shared_key'
18
-
19
18
  require 'azure/table/serialization'
20
19
  require 'azure/table/entity'
21
20
 
@@ -23,9 +22,11 @@ module Azure
23
22
  module Table
24
23
  class TableService < Azure::Service::StorageService
25
24
 
26
- def initialize
27
- super(Azure::Table::Auth::SharedKey.new)
28
- @host = Azure.config.storage_table_host
25
+ def initialize(options = {})
26
+ client_config = options[:client] || Azure
27
+ signer = options[:signer] || Auth::SharedKey.new(client_config.storage_account_name, client_config.storage_access_key)
28
+ super(signer, client_config.storage_account_name, options)
29
+ @host = client.storage_table_host
29
30
  end
30
31
 
31
32
  # Public: Creates new table in the storage account
@@ -43,10 +44,10 @@ module Azure
43
44
  #
44
45
  # See http://msdn.microsoft.com/en-us/library/azure/dd135729
45
46
  #
46
- # Returns nil on success
47
+ # @return [nil] on success
47
48
  def create_table(table_name, options={})
48
49
  query = { }
49
- query["timeout"] = options[:timeout].to_s if options[:timeout]
50
+ query['timeout'] = options[:timeout].to_s if options[:timeout]
50
51
 
51
52
  body = Azure::Table::Serialization.hash_to_entry_xml({"TableName" => table_name}).to_xml
52
53
  call(:post, collection_uri(query), body)
@@ -145,10 +146,10 @@ module Azure
145
146
  #
146
147
  # Returns a list of Azure::Entity::SignedIdentifier instances
147
148
  def get_table_acl(table_name, options={})
148
- query = { "comp" => "acl" }
149
- query["timeout"] = options[:timeout].to_s if options[:timeout]
149
+ query = { 'comp' => 'acl'}
150
+ query['timeout'] = options[:timeout].to_s if options[:timeout]
150
151
 
151
- response = call(:get, generate_uri(table_name, query))
152
+ response = call(:get, generate_uri(table_name, query), nil, {'x-ms-version' => '2012-02-12'})
152
153
 
153
154
  signed_identifiers = []
154
155
  signed_identifiers = Azure::Table::Serialization.signed_identifiers_from_xml response.body unless response.body == nil or response.body.length < 1
@@ -172,14 +173,14 @@ module Azure
172
173
  #
173
174
  # Returns nil on success
174
175
  def set_table_acl(table_name, options={})
175
- query = { "comp" => "acl" }
176
- query["timeout"] = options[:timeout].to_s if options[:timeout]
176
+ query = { 'comp' => 'acl'}
177
+ query['timeout'] = options[:timeout].to_s if options[:timeout]
177
178
 
178
179
  uri = generate_uri(table_name, query)
179
180
  body = nil
180
181
  body = Azure::Table::Serialization.signed_identifiers_to_xml options[:signed_identifiers] if options[:signed_identifiers] && options[:signed_identifiers].length > 0
181
182
 
182
- call(:put, uri, body, {})
183
+ call(:put, uri, body, {'x-ms-version' => '2012-02-12'})
183
184
  nil
184
185
  end
185
186
 
@@ -204,7 +205,7 @@ module Azure
204
205
  body = Azure::Table::Serialization.hash_to_entry_xml(entity_values).to_xml
205
206
 
206
207
  query = { }
207
- query["timeout"] = options[:timeout].to_s if options[:timeout]
208
+ query['timeout'] = options[:timeout].to_s if options[:timeout]
208
209
 
209
210
  response = call(:post, entities_uri(table_name, nil, nil, query), body)
210
211
 
@@ -213,7 +214,7 @@ module Azure
213
214
  Entity.new do |entity|
214
215
  entity.table = table_name
215
216
  entity.updated = result[:updated]
216
- entity.etag = response.headers["etag"] || result[:etag]
217
+ entity.etag = response.headers['etag'] || result[:etag]
217
218
  entity.properties = result[:properties]
218
219
  end
219
220
  end
@@ -438,8 +439,8 @@ module Azure
438
439
  # Returns an array of results, one for each operation in the batch
439
440
  def execute_batch(batch, options={})
440
441
  headers = {
441
- "Content-Type"=> "multipart/mixed; boundary=#{batch.batch_id}",
442
- "Accept"=> 'application/atom+xml,application/xml',
442
+ 'Content-Type' => "multipart/mixed; boundary=#{batch.batch_id}",
443
+ 'Accept' => 'application/atom+xml,application/xml',
443
444
  'Accept-Charset'=> 'UTF-8'
444
445
  }
445
446
 
@@ -447,7 +448,7 @@ module Azure
447
448
  query["timeout"] = options[:timeout].to_s if options[:timeout]
448
449
 
449
450
  body = batch.to_body
450
- response = call(:post, generate_uri("/$batch", query), body, headers)
451
+ response = call(:post, generate_uri('/$batch', query), body, headers)
451
452
  batch.parse_response(response)
452
453
  end
453
454
 
@@ -557,4 +558,6 @@ module Azure
557
558
  end
558
559
  end
559
560
  end
560
- end
561
+ end
562
+
563
+ Azure::TableService = Azure::Table::TableService
@@ -18,7 +18,7 @@ module Azure
18
18
  MAJOR = 0 unless defined? MAJOR
19
19
  MINOR = 7 unless defined? MINOR
20
20
  UPDATE = 0 unless defined? UPDATE
21
- PRE = 'pre' unless defined? PRE
21
+ PRE = 'pre2' unless defined? PRE
22
22
 
23
23
  class << self
24
24
 
@@ -18,10 +18,6 @@ module Azure
18
18
  module VirtualMachineImageManagement
19
19
  class VirtualMachineImageManagementService < BaseManagement::BaseManagementService
20
20
 
21
- def initialize
22
- super()
23
- end
24
-
25
21
  # Public: Gets a list of virtual machine images from the server
26
22
  #
27
23
  # Returns an array of Azure::VirtualMachineImageManagement::VirtualMachineImage objects
@@ -36,7 +32,7 @@ module Azure
36
32
  # Returns an array of Azure::VirtualMachineImageManagement::VirtualMachineImage objects
37
33
  def list_os_images
38
34
  request_path = '/services/images'
39
- request = BaseManagement::ManagementHttpRequest.new(:get, request_path, nil)
35
+ request = client.management_request(:get, request_path, nil)
40
36
  response = request.call
41
37
  Serialization.virtual_machine_images_from_xml(response)
42
38
  end
@@ -48,7 +44,7 @@ module Azure
48
44
  # Returns an array of Azure::VirtualMachineImageManagement::VirtualMachineImage objects
49
45
  def list_vm_images
50
46
  request_path = '/services/vmimages'
51
- request = Azure::BaseManagement::ManagementHttpRequest.new(:get, request_path, nil)
47
+ request = client.management_request(:get, request_path)
52
48
  response = request.call
53
49
  Serialization.virtual_machine_vm_images_from_xml(response)
54
50
  end
@@ -56,16 +52,12 @@ module Azure
56
52
 
57
53
  class VirtualMachineDiskManagementService < BaseManagement::BaseManagementService
58
54
 
59
- def initialize
60
- super()
61
- end
62
-
63
55
  # Public: Gets a list of Disks from the server.
64
56
  #
65
57
  # Returns an array of Azure::VirtualMachineDiskManagementService objects
66
58
  def list_virtual_machine_disks
67
59
  request_path = '/services/disks'
68
- request = Azure::BaseManagement::ManagementHttpRequest.new(:get, request_path, nil)
60
+ request = client.management_request(:get, request_path)
69
61
  response = request.call
70
62
  Serialization.disks_from_xml(response)
71
63
  end
@@ -81,9 +73,11 @@ module Azure
81
73
  def delete_virtual_machine_disk(disk_name)
82
74
  Azure::Loggerx.info "Deleting Disk \"#{disk_name}\". "
83
75
  path = "/services/disks/#{disk_name}"
84
- request = BaseManagement::ManagementHttpRequest.new(:delete, path)
76
+ request = client.management_request(:delete, path)
85
77
  request.call
86
78
  end
87
79
  end
88
80
  end
89
81
  end
82
+
83
+ Azure::VirtualMachineImageManagementService = Azure::VirtualMachineImageManagement::VirtualMachineImageManagementService
@@ -89,7 +89,7 @@ module Azure
89
89
  xml.OsVersion('i:nil' => 'true')
90
90
  xml.RoleType 'PersistentVMRole'
91
91
  xml.ConfigurationSets do
92
- provisioning_configuration_to_xml(xml, params, options) if image.image_type == 'OS'
92
+ provisioning_configuration_to_xml(xml, params, options) if image.image_type == 'OS' || image.image_type == 'VM'
93
93
  xml.ConfigurationSet('i:type' => 'NetworkConfigurationSet') do
94
94
  xml.ConfigurationSetType 'NetworkConfiguration'
95
95
  xml.InputEndpoints do
@@ -281,6 +281,8 @@ module Azure
281
281
  'ConfigurationSets ConfigurationSet SubnetNames SubnetName'
282
282
  )
283
283
  vm.subnet = subnet unless subnet.empty?
284
+ static_virtual_network_ipaddress = xml_content(role,'ConfigurationSets ConfigurationSet StaticVirtualNetworkIPAddress')
285
+ vm.static_virtual_network_ipaddress = static_virtual_network_ipaddress unless static_virtual_network_ipaddress.empty?
284
286
  vm.os_type = xml_content(role, 'OSVirtualHardDisk OS')
285
287
  vm.disk_name = xml_content(role, 'OSVirtualHardDisk DiskName')
286
288
  vm.media_link = xml_content(role, 'OSVirtualHardDisk MediaLink')
@@ -367,6 +369,7 @@ module Azure
367
369
  xml.SubnetNames do
368
370
  xml.SubnetName vm.subnet if vm.subnet
369
371
  end
372
+ xml.StaticVirtualNetworkIPAddress vm.static_virtual_network_ipaddress if vm.static_virtual_network_ipaddress
370
373
  end
371
374
  end
372
375
  xml.OSVirtualHardDisk do
@@ -38,6 +38,7 @@ module Azure
38
38
  attr_accessor :media_link
39
39
  attr_accessor :data_disks
40
40
  attr_accessor :subnet
41
+ attr_accessor :static_virtual_network_ipaddress
41
42
  end
42
43
  end
43
44
  end
@@ -20,10 +20,6 @@ module Azure
20
20
  class VirtualMachineManagementService < BaseManagement::BaseManagementService
21
21
  include Azure::Core::Utility
22
22
 
23
- def initialize
24
- super()
25
- end
26
-
27
23
  # Public: Get a lists of virtual machines available under the current subscription.
28
24
  #
29
25
  # Returns an list of Azure::VirtualMachineManagement::VirtualMachine instances.
@@ -31,12 +27,12 @@ module Azure
31
27
  roles = []
32
28
  cloud_service_names.flatten!
33
29
  if cloud_service_names.empty?
34
- cloud_service = Azure::CloudServiceManagementService.new
30
+ cloud_service = client.cloud_service_management
35
31
  cloud_service_names = cloud_service.list_cloud_services.map(&:name)
36
32
  end
37
33
  cloud_service_names.each do |cloud_service_name|
38
34
  request_path = "/services/hostedservices/#{cloud_service_name}/deploymentslots/production"
39
- request = BaseManagement::ManagementHttpRequest.new(:get, request_path)
35
+ request = client.management_request(:get, request_path)
40
36
  request.warn = true
41
37
  response = request.call
42
38
  roles << Serialization.virtual_machines_from_xml(response, cloud_service_name)
@@ -85,17 +81,17 @@ module Azure
85
81
  # You can map multiple internal and external ports by separating them with a comma.
86
82
  # * +:ssh_private_key_file+ - String. Path of private key file.
87
83
  # * +:ssh_port+ - Integer. Specifies the SSH port number.
88
- # * +:winrm_http_port - Integer. Specifies the WinRM HTTP port number.
89
- # * +:winrm_https_port - Integer. Specifies the WinRM HTTPS port number.
84
+ # * +:winrm_http_port+ - Integer. Specifies the WinRM HTTP port number.
85
+ # * +:winrm_https_port+ - Integer. Specifies the WinRM HTTPS port number.
90
86
  # * +:vm_size+ - String. Specifies the size of the virtual machine instance.
91
87
  # * +:winrm_transport+ - Array. Specifies WINRM transport protocol.
92
88
  # * +:availability_set_name+ - String. Specifies the availability set name.
93
89
  # * +:reserved_ip_name+ - String. Specifies the reserved IP name.
94
90
  #
95
- # Returns Azure::VirtualMachineManagement::VirtualMachine objects of newly created instance.
91
+ # @return [Azure::VirtualMachineManagement::VirtualMachine] objects of newly created instance.
96
92
  #
97
- # See:
98
- # http://msdn.microsoft.com/en-us/library/azure/jj157194.aspx
93
+ #
94
+ # @see http://msdn.microsoft.com/en-us/library/azure/jj157194.aspx
99
95
  def create_virtual_machine(params, options = {})
100
96
  image = get_image(params[:image])
101
97
  options[:os_type] = image.os_type
@@ -107,7 +103,7 @@ module Azure
107
103
  options[:storage_account_name] ||= generate_storage_account_name(params[:vm_name])
108
104
  optionals = {}
109
105
  if options[:virtual_network_name]
110
- virtual_network_service = Azure::VirtualNetworkManagementService.new
106
+ virtual_network_service = client.network_management
111
107
  virtual_networks = virtual_network_service.list_virtual_networks.select { |x| x.name == options[:virtual_network_name] }
112
108
  if virtual_networks.empty?
113
109
  Azure::Loggerx.error_with_exit "Virtual network #{options[:virtual_network_name]} doesn't exists"
@@ -124,21 +120,21 @@ module Azure
124
120
  else
125
121
  optionals[:location] = params[:location]
126
122
  end
127
- cloud_service = Azure::CloudServiceManagementService.new
123
+ cloud_service = client.cloud_service_management
128
124
  cloud_service.create_cloud_service(options[:cloud_service_name], optionals)
129
125
  cloud_service.upload_certificate(options[:cloud_service_name], params[:certificate]) unless params[:certificate].empty?
130
126
  unless image.category == 'User'
131
127
  options[:storage_account_name] ||= generate_storage_account_name(params[:vm_name])
132
- Azure::StorageManagementService.new.create_storage_account(options[:storage_account_name], optionals)
128
+ client.storage_management.create_storage_account(options[:storage_account_name], optionals)
133
129
  end
134
130
  body = Serialization.deployment_to_xml(params, image, options)
135
131
  path = "/services/hostedservices/#{options[:cloud_service_name]}/deployments"
136
132
  Azure::Loggerx.info 'Deployment in progress...'
137
- request = BaseManagement::ManagementHttpRequest.new(:post, path, body)
133
+ request = client.management_request(:post, path, body)
138
134
  request.call
139
135
  get_virtual_machine(params[:vm_name], options[:cloud_service_name])
140
136
  rescue Exception => e
141
- e.message
137
+ Azure::Loggerx.error_with_exit "Failed to create virtual machine : "+e.message
142
138
  end
143
139
 
144
140
  # Public: Add a new role to a cloud service. Atleast one deployment should exist before you can add a role.
@@ -178,7 +174,7 @@ module Azure
178
174
  image = get_image(params[:image])
179
175
  options[:os_type] = image.os_type
180
176
  validate_deployment_params(params, options, true)
181
- cloud_service = Azure::CloudServiceManagementService.new
177
+ cloud_service = client.cloud_service_management
182
178
  cloud_service = cloud_service.get_cloud_service_properties(params[:cloud_service_name])
183
179
  deployment_name = cloud_service.deployment_name
184
180
  Azure::Loggerx.error_with_exit "Deployment doesn't exists." if cloud_service && deployment_name.empty?
@@ -190,7 +186,7 @@ module Azure
190
186
  end
191
187
  unless image.category == 'User'
192
188
  options[:storage_account_name] ||= generate_storage_account_name(params[:vm_name])
193
- Azure::StorageManagementService.new.create_storage_account(options[:storage_account_name], others)
189
+ client.storage_management.create_storage_account(options[:storage_account_name], others)
194
190
  end
195
191
  Azure::Loggerx.info 'Deployment exists, adding role...'
196
192
  existing_ports = []
@@ -203,7 +199,7 @@ module Azure
203
199
  body = Serialization.role_to_xml(params, image, options).to_xml
204
200
  path = "/services/hostedservices/#{cloud_service.name}/deployments/#{deployment_name}/roles"
205
201
  Azure::Loggerx.info 'Deployment in progress...'
206
- request = BaseManagement::ManagementHttpRequest.new(:post, path, body)
202
+ request = client.management_request(:post, path, body)
207
203
  request.call
208
204
  get_virtual_machine(params[:vm_name], cloud_service.name)
209
205
  end
@@ -224,18 +220,18 @@ module Azure
224
220
  vm = virtual_machines.select { |x| x.vm_name == vm_name }.first
225
221
  if vm
226
222
  if virtual_machines.size == 1
227
- cloud_service = Azure::CloudServiceManagementService.new
223
+ cloud_service = client.cloud_service_management
228
224
  cloud_service.delete_cloud_service_deployment(cloud_service_name)
229
225
  cloud_service.delete_cloud_service(cloud_service_name)
230
226
  else
231
227
  path = "/services/hostedservices/#{vm.cloud_service_name}/deployments/#{vm.deployment_name}/roles/#{vm.vm_name}"
232
228
  Azure::Loggerx.info "Deleting virtual machine #{vm_name}. \n"
233
- request = BaseManagement::ManagementHttpRequest.new(:delete, path)
229
+ request = client.management_request(:delete, path)
234
230
  request.call
235
231
  end
236
232
  Azure::Loggerx.info "Waiting for disk to be released.\n"
237
233
  disk_name = vm.disk_name
238
- disk_management_service = VirtualMachineDiskManagementService.new
234
+ disk_management_service = client.vm_disk_management
239
235
  # Wait for 180s for disk to be released.
240
236
  disk = nil
241
237
  18.times do
@@ -277,7 +273,7 @@ module Azure
277
273
  path = "/services/hostedservices/#{vm.cloud_service_name}/deployments/#{vm.deployment_name}/roleinstances/#{vm.vm_name}/Operations"
278
274
  body = Serialization.shutdown_virtual_machine_to_xml
279
275
  Azure::Loggerx.info "Shutting down virtual machine \"#{vm.vm_name}\" ..."
280
- request = BaseManagement::ManagementHttpRequest.new(:post, path, body)
276
+ request = client.management_request(:post, path, body)
281
277
  request.call
282
278
  else
283
279
  Azure::Loggerx.error 'Cannot perform the shutdown operation on a stopped deployment.'
@@ -306,7 +302,7 @@ module Azure
306
302
  path = "/services/hostedservices/#{vm.cloud_service_name}/deployments/#{vm.deployment_name}/roleinstances/#{vm.vm_name}/Operations"
307
303
  body = Serialization.start_virtual_machine_to_xml
308
304
  Azure::Loggerx.info "Starting virtual machine \"#{vm.vm_name}\" ..."
309
- request = BaseManagement::ManagementHttpRequest.new(:post, path, body)
305
+ request = client.management_request(:post, path, body: body)
310
306
  request.call
311
307
  end
312
308
  else
@@ -330,7 +326,7 @@ module Azure
330
326
  path = "/services/hostedservices/#{vm.cloud_service_name}/deployments/#{vm.deployment_name}/roleinstances/#{vm.vm_name}/Operations"
331
327
  body = Serialization.restart_virtual_machine_to_xml
332
328
  Azure::Loggerx.info "Restarting virtual machine \"#{vm.vm_name}\" ..."
333
- request = BaseManagement::ManagementHttpRequest.new(:post, path, body)
329
+ request = client.management_request(:post, path, body: body)
334
330
  request.call
335
331
  else
336
332
  Azure::Loggerx.error "Cannot find virtual machine \"#{vm_name}\" under cloud service \"#{cloud_service_name}\"."
@@ -391,7 +387,7 @@ module Azure
391
387
  end
392
388
  endpoints += input_endpoints
393
389
  body = Serialization.update_role_to_xml(endpoints, vm)
394
- request = BaseManagement::ManagementHttpRequest.new(:put, path, body)
390
+ request = client.management_request(:put, path, body: body)
395
391
  Azure::Loggerx.info "Updating endpoints of virtual machine #{vm.vm_name} ..."
396
392
  request.call
397
393
  else
@@ -417,7 +413,7 @@ module Azure
417
413
  endpoints = vm.tcp_endpoints + vm.udp_endpoints
418
414
  endpoints.delete_if { |ep| endpoint_name.downcase == ep[:name].downcase }
419
415
  body = Serialization.update_role_to_xml(endpoints, vm)
420
- request = BaseManagement::ManagementHttpRequest.new(:put, path, body)
416
+ request = client.management_request(:put, path, body: body)
421
417
  Azure::Loggerx.info "Deleting virtual machine endpoint #{endpoint_name} ..."
422
418
  request.call
423
419
  else
@@ -455,7 +451,7 @@ module Azure
455
451
  path = "/services/hostedservices/#{cloud_service_name}/deployments/#{vm.deployment_name}/roles/#{vm_name}/DataDisks"
456
452
  body = Serialization.add_data_disk_to_xml(vm, options)
457
453
  Azure::Loggerx.info "Adding data disk to virtual machine #{vm_name} ..."
458
- request = BaseManagement::ManagementHttpRequest.new(:post, path, body)
454
+ request = client.management_request(:post, path, body: body)
459
455
  request.call
460
456
  else
461
457
  Azure::Loggerx.error "Cannot find virtual machine \"#{vm_name}\" under cloud service \"#{cloud_service_name}\"."
@@ -468,7 +464,7 @@ module Azure
468
464
  #
469
465
  # Returns Linux or Windows
470
466
  def get_image(image_name)
471
- image_service = Azure::VirtualMachineImageManagementService.new
467
+ image_service = client.vm_image_management
472
468
  image = image_service.list_virtual_machine_images.select { |x| x.name.casecmp(image_name.to_s) == 0 }.first
473
469
  Azure::Loggerx.error_with_exit 'The virtual machine image source is not valid.' unless image
474
470
  image
@@ -534,20 +530,14 @@ module Azure
534
530
  end
535
531
 
536
532
  def validate_role_size(vm_size)
537
- suggested_role_sizes = %w(
538
- Basic_A0 Basic_A1 Basic_A2 Basic_A3 Basic_A4
539
- ExtraSmall Small Medium Large ExtraLarge A5 A6 A7 A8 A9 A10 A11
540
- Standard_D1 Standard_D2 Standard_D3 Standard_D4 Standard_D11 Standard_D12 Standard_D13 Standard_D14
541
- Standard_DS1 Standard_DS2 Standard_DS3 Standard_DS4 Standard_DS11 Standard_DS12 Standard_DS13 Standard_DS14
542
- Standard_G1 Standard_G2 Standard_G3 Standard_G4 Standard_G5
543
- )
533
+ suggested_role_sizes = client.base_management.list_role_sizes
544
534
  if vm_size && !suggested_role_sizes.include?(vm_size)
545
535
  Azure::Loggerx.warn "Value '#{vm_size}' specified for parameter 'vm_size' is not in the list of valid VM role sizes. Suggested values are '#{suggested_role_sizes.join(',')}'"
546
536
  end
547
537
  end
548
538
 
549
539
  def validate_location(location_name)
550
- locations = Azure::BaseManagementService.new.list_locations
540
+ locations = client.base_management.list_locations
551
541
  location = locations.select { |loc| loc.name.downcase == location_name.downcase }.first
552
542
  if location.nil?
553
543
  Azure::Loggerx.error_with_exit "Value '#{location_name}' specified for parameter 'location' is invalid. Allowed values are #{locations.map(&:name).join(',')}"
@@ -558,3 +548,5 @@ module Azure
558
548
  end
559
549
  end
560
550
  end
551
+
552
+ Azure::VirtualMachineManagementService = Azure::VirtualMachineManagement::VirtualMachineManagementService