fog-azure-rm 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (277) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +20 -0
  3. data/README.md +2 -1
  4. data/fog-azure-rm.gemspec +11 -9
  5. data/lib/fog/azurerm.rb +1 -0
  6. data/lib/fog/azurerm/compute.rb +3 -3
  7. data/lib/fog/azurerm/config.rb +33 -0
  8. data/lib/fog/azurerm/credentials.rb +1 -1
  9. data/lib/fog/azurerm/dns.rb +2 -2
  10. data/lib/fog/azurerm/docs/storage.md +120 -66
  11. data/lib/fog/azurerm/models/application_gateway/gateway.rb +30 -31
  12. data/lib/fog/azurerm/models/application_gateway/gateways.rb +4 -4
  13. data/lib/fog/azurerm/models/compute/availability_sets.rb +4 -4
  14. data/lib/fog/azurerm/models/compute/server.rb +14 -14
  15. data/lib/fog/azurerm/models/compute/servers.rb +4 -4
  16. data/lib/fog/azurerm/models/compute/virtual_machine_extension.rb +3 -5
  17. data/lib/fog/azurerm/models/compute/virtual_machine_extensions.rb +5 -5
  18. data/lib/fog/azurerm/models/dns/record_sets.rb +4 -4
  19. data/lib/fog/azurerm/models/dns/zones.rb +4 -4
  20. data/lib/fog/azurerm/models/network/express_route_circuit.rb +2 -5
  21. data/lib/fog/azurerm/models/network/express_route_circuit_authorization.rb +1 -1
  22. data/lib/fog/azurerm/models/network/express_route_circuit_authorizations.rb +4 -4
  23. data/lib/fog/azurerm/models/network/express_route_circuit_peering.rb +3 -5
  24. data/lib/fog/azurerm/models/network/express_route_circuit_peerings.rb +4 -4
  25. data/lib/fog/azurerm/models/network/express_route_circuits.rb +4 -4
  26. data/lib/fog/azurerm/models/network/express_route_service_providers.rb +2 -2
  27. data/lib/fog/azurerm/models/network/load_balancers.rb +5 -5
  28. data/lib/fog/azurerm/models/network/local_network_gateway.rb +1 -1
  29. data/lib/fog/azurerm/models/network/local_network_gateways.rb +4 -4
  30. data/lib/fog/azurerm/models/network/network_interfaces.rb +5 -5
  31. data/lib/fog/azurerm/models/network/network_security_groups.rb +5 -5
  32. data/lib/fog/azurerm/models/network/network_security_rule.rb +3 -4
  33. data/lib/fog/azurerm/models/network/network_security_rules.rb +4 -4
  34. data/lib/fog/azurerm/models/network/public_ips.rb +4 -4
  35. data/lib/fog/azurerm/models/network/subnets.rb +4 -4
  36. data/lib/fog/azurerm/models/network/virtual_network_gateway.rb +6 -7
  37. data/lib/fog/azurerm/models/network/virtual_network_gateway_connection.rb +5 -5
  38. data/lib/fog/azurerm/models/network/virtual_network_gateway_connections.rb +4 -4
  39. data/lib/fog/azurerm/models/network/virtual_network_gateways.rb +4 -4
  40. data/lib/fog/azurerm/models/network/virtual_networks.rb +4 -4
  41. data/lib/fog/azurerm/models/resources/azure_resources.rb +2 -2
  42. data/lib/fog/azurerm/models/resources/deployments.rb +4 -4
  43. data/lib/fog/azurerm/models/resources/resource_groups.rb +4 -4
  44. data/lib/fog/azurerm/models/sql/firewall_rule.rb +1 -1
  45. data/lib/fog/azurerm/models/sql/firewall_rules.rb +4 -4
  46. data/lib/fog/azurerm/models/sql/sql_database.rb +28 -24
  47. data/lib/fog/azurerm/models/sql/sql_databases.rb +5 -6
  48. data/lib/fog/azurerm/models/sql/sql_servers.rb +4 -4
  49. data/lib/fog/azurerm/models/storage/directories.rb +49 -24
  50. data/lib/fog/azurerm/models/storage/directory.rb +126 -40
  51. data/lib/fog/azurerm/models/storage/file.rb +226 -114
  52. data/lib/fog/azurerm/models/storage/files.rb +168 -13
  53. data/lib/fog/azurerm/models/storage/recovery_vault.rb +1 -1
  54. data/lib/fog/azurerm/models/storage/recovery_vaults.rb +4 -4
  55. data/lib/fog/azurerm/models/storage/storage_account.rb +5 -5
  56. data/lib/fog/azurerm/models/storage/storage_accounts.rb +4 -4
  57. data/lib/fog/azurerm/models/traffic_manager/traffic_manager_end_point.rb +1 -1
  58. data/lib/fog/azurerm/models/traffic_manager/traffic_manager_end_points.rb +4 -4
  59. data/lib/fog/azurerm/models/traffic_manager/traffic_manager_profile.rb +4 -4
  60. data/lib/fog/azurerm/models/traffic_manager/traffic_manager_profiles.rb +4 -4
  61. data/lib/fog/azurerm/network.rb +1 -1
  62. data/lib/fog/azurerm/requests/compute/create_virtual_machine.rb +17 -13
  63. data/lib/fog/azurerm/requests/network/list_virtual_networks.rb +1 -1
  64. data/lib/fog/azurerm/requests/resources/create_deployment.rb +1 -1
  65. data/lib/fog/azurerm/requests/resources/create_resource_group.rb +1 -1
  66. data/lib/fog/azurerm/requests/resources/delete_deployment.rb +1 -1
  67. data/lib/fog/azurerm/requests/resources/delete_resource_group.rb +1 -1
  68. data/lib/fog/azurerm/requests/resources/get_deployment.rb +1 -1
  69. data/lib/fog/azurerm/requests/resources/get_resource_group.rb +1 -1
  70. data/lib/fog/azurerm/requests/resources/list_deployments.rb +1 -1
  71. data/lib/fog/azurerm/requests/resources/list_resource_groups.rb +1 -1
  72. data/lib/fog/azurerm/requests/resources/list_tagged_resources.rb +1 -1
  73. data/lib/fog/azurerm/requests/resources/tag_resource.rb +1 -1
  74. data/lib/fog/azurerm/requests/sql/create_or_update_database.rb +3 -3
  75. data/lib/fog/azurerm/requests/sql/create_or_update_firewall_rule.rb +3 -3
  76. data/lib/fog/azurerm/requests/sql/create_or_update_sql_server.rb +3 -3
  77. data/lib/fog/azurerm/requests/sql/delete_database.rb +2 -2
  78. data/lib/fog/azurerm/requests/sql/delete_firewall_rule.rb +4 -4
  79. data/lib/fog/azurerm/requests/sql/delete_sql_server.rb +4 -4
  80. data/lib/fog/azurerm/requests/sql/get_database.rb +3 -3
  81. data/lib/fog/azurerm/requests/sql/get_firewall_rule.rb +3 -3
  82. data/lib/fog/azurerm/requests/sql/get_sql_server.rb +3 -3
  83. data/lib/fog/azurerm/requests/sql/list_databases.rb +3 -3
  84. data/lib/fog/azurerm/requests/sql/list_firewall_rules.rb +3 -3
  85. data/lib/fog/azurerm/requests/sql/list_sql_servers.rb +3 -3
  86. data/lib/fog/azurerm/requests/storage/acquire_blob_lease.rb +5 -2
  87. data/lib/fog/azurerm/requests/storage/acquire_container_lease.rb +5 -2
  88. data/lib/fog/azurerm/requests/storage/commit_blob_blocks.rb +30 -0
  89. data/lib/fog/azurerm/requests/storage/compare_container_blobs.rb +148 -0
  90. data/lib/fog/azurerm/requests/storage/copy_blob.rb +8 -8
  91. data/lib/fog/azurerm/requests/storage/copy_blob_from_uri.rb +8 -8
  92. data/lib/fog/azurerm/requests/storage/create_block_blob.rb +108 -0
  93. data/lib/fog/azurerm/requests/storage/create_container.rb +12 -10
  94. data/lib/fog/azurerm/requests/storage/create_disk.rb +45 -19
  95. data/lib/fog/azurerm/requests/storage/create_or_update_recovery_vault.rb +2 -2
  96. data/lib/fog/azurerm/requests/storage/create_page_blob.rb +31 -0
  97. data/lib/fog/azurerm/requests/storage/create_storage_account.rb +2 -2
  98. data/lib/fog/azurerm/requests/storage/delete_blob.rb +10 -5
  99. data/lib/fog/azurerm/requests/storage/delete_container.rb +6 -2
  100. data/lib/fog/azurerm/requests/storage/delete_disk.rb +19 -16
  101. data/lib/fog/azurerm/requests/storage/get_all_backup_jobs.rb +2 -2
  102. data/lib/fog/azurerm/requests/storage/get_backup_container.rb +2 -2
  103. data/lib/fog/azurerm/requests/storage/get_backup_item.rb +2 -2
  104. data/lib/fog/azurerm/requests/storage/get_backup_job_for_vm.rb +1 -1
  105. data/lib/fog/azurerm/requests/storage/get_backup_protection_policy.rb +2 -2
  106. data/lib/fog/azurerm/requests/storage/get_blob.rb +163 -0
  107. data/lib/fog/azurerm/requests/storage/get_blob_http_url.rb +39 -0
  108. data/lib/fog/azurerm/requests/storage/get_blob_https_url.rb +39 -0
  109. data/lib/fog/azurerm/requests/storage/get_blob_properties.rb +37 -35
  110. data/lib/fog/azurerm/requests/storage/get_blob_url.rb +28 -0
  111. data/lib/fog/azurerm/requests/storage/get_container_acl.rb +30 -0
  112. data/lib/fog/azurerm/requests/storage/get_container_properties.rb +16 -12
  113. data/lib/fog/azurerm/requests/storage/get_container_url.rb +34 -0
  114. data/lib/fog/azurerm/requests/storage/get_recovery_vault.rb +2 -2
  115. data/lib/fog/azurerm/requests/storage/get_storage_access_keys.rb +4 -3
  116. data/lib/fog/azurerm/requests/storage/get_storage_account.rb +2 -2
  117. data/lib/fog/azurerm/requests/storage/list_blobs.rb +110 -24
  118. data/lib/fog/azurerm/requests/storage/list_containers.rb +46 -23
  119. data/lib/fog/azurerm/requests/storage/list_recovery_vaults.rb +2 -2
  120. data/lib/fog/azurerm/requests/storage/list_storage_account_for_rg.rb +2 -2
  121. data/lib/fog/azurerm/requests/storage/list_storage_accounts.rb +2 -2
  122. data/lib/fog/azurerm/requests/storage/multipart_save_block_blob.rb +110 -0
  123. data/lib/fog/azurerm/requests/storage/put_blob_block.rb +30 -0
  124. data/lib/fog/azurerm/requests/storage/{set_blob_metadata.rb → put_blob_metadata.rb} +7 -3
  125. data/lib/fog/azurerm/requests/storage/put_blob_pages.rb +30 -0
  126. data/lib/fog/azurerm/requests/storage/put_blob_properties.rb +31 -0
  127. data/lib/fog/azurerm/requests/storage/put_container_acl.rb +31 -0
  128. data/lib/fog/azurerm/requests/storage/{set_container_metadata.rb → put_container_metadata.rb} +7 -3
  129. data/lib/fog/azurerm/requests/storage/release_blob_lease.rb +4 -1
  130. data/lib/fog/azurerm/requests/storage/release_container_lease.rb +4 -1
  131. data/lib/fog/azurerm/requests/storage/save_page_blob.rb +111 -0
  132. data/lib/fog/azurerm/requests/storage/start_backup.rb +1 -1
  133. data/lib/fog/azurerm/requests/storage/wait_blob_copy_operation_to_finish.rb +56 -0
  134. data/lib/fog/azurerm/resources.rb +2 -2
  135. data/lib/fog/azurerm/storage.rb +33 -19
  136. data/lib/fog/azurerm/traffic_manager.rb +1 -1
  137. data/lib/fog/azurerm/utilities/general.rb +70 -3
  138. data/lib/fog/azurerm/version.rb +1 -1
  139. data/rake-script.sh +5 -2
  140. data/test/api_stub/models/application_gateway/gateway.rb +1 -1
  141. data/test/api_stub/models/compute/server.rb +1 -1
  142. data/test/api_stub/models/dns/record_set.rb +2 -2
  143. data/test/api_stub/models/dns/zone.rb +1 -1
  144. data/test/api_stub/models/network/express_route_circuit.rb +1 -1
  145. data/test/api_stub/models/network/express_route_circuit_authorization.rb +1 -1
  146. data/test/api_stub/models/network/express_route_circuit_peering.rb +1 -1
  147. data/test/api_stub/models/network/express_route_service_provider.rb +1 -1
  148. data/test/api_stub/models/network/load_balancer.rb +1 -1
  149. data/test/api_stub/models/network/network_interface.rb +1 -1
  150. data/test/api_stub/models/network/network_security_group.rb +1 -1
  151. data/test/api_stub/models/network/network_security_rule.rb +1 -1
  152. data/test/api_stub/models/network/public_ip.rb +1 -1
  153. data/test/api_stub/models/network/subnet.rb +1 -1
  154. data/test/api_stub/models/network/virtual_network.rb +1 -1
  155. data/test/api_stub/models/network/virtual_network_gateway.rb +1 -1
  156. data/test/api_stub/models/network/virtual_network_gateway_connection.rb +1 -1
  157. data/test/api_stub/models/resources/resource.rb +2 -2
  158. data/test/api_stub/models/resources/resource_group.rb +1 -1
  159. data/test/api_stub/models/storage/directory.rb +148 -62
  160. data/test/api_stub/models/storage/file.rb +122 -119
  161. data/test/api_stub/models/traffic_manager/traffic_manager_end_point.rb +1 -1
  162. data/test/api_stub/models/traffic_manager/traffic_manager_profile.rb +1 -1
  163. data/test/api_stub/requests/application_gateway/gateway.rb +2 -2
  164. data/test/api_stub/requests/compute/availability_set.rb +3 -3
  165. data/test/api_stub/requests/compute/virtual_machine.rb +9 -9
  166. data/test/api_stub/requests/dns/record_set.rb +3 -3
  167. data/test/api_stub/requests/dns/zone.rb +18 -18
  168. data/test/api_stub/requests/network/express_route_circuit.rb +2 -2
  169. data/test/api_stub/requests/network/express_route_circuit_authorization.rb +1 -1
  170. data/test/api_stub/requests/network/express_route_circuit_peering.rb +2 -2
  171. data/test/api_stub/requests/network/express_route_service_provider.rb +1 -1
  172. data/test/api_stub/requests/network/load_balancer.rb +2 -2
  173. data/test/api_stub/requests/network/network_interface.rb +4 -4
  174. data/test/api_stub/requests/network/network_security_group.rb +3 -3
  175. data/test/api_stub/requests/network/network_security_rule.rb +2 -2
  176. data/test/api_stub/requests/network/public_ip.rb +2 -2
  177. data/test/api_stub/requests/network/subnet.rb +2 -2
  178. data/test/api_stub/requests/network/virtual_network.rb +2 -2
  179. data/test/api_stub/requests/network/virtual_network_gateway.rb +2 -2
  180. data/test/api_stub/requests/network/virtual_network_gateway_connection.rb +3 -3
  181. data/test/api_stub/requests/resources/resource.rb +2 -2
  182. data/test/api_stub/requests/resources/resource_group.rb +2 -2
  183. data/test/api_stub/requests/storage/directory.rb +59 -65
  184. data/test/api_stub/requests/storage/file.rb +183 -113
  185. data/test/api_stub/requests/storage/storageaccount.rb +1 -1
  186. data/test/api_stub/requests/traffic_manager/traffic_manager_endpoint.rb +1 -1
  187. data/test/api_stub/requests/traffic_manager/traffic_manager_profile.rb +2 -2
  188. data/test/integration/Virtual_network_gateway_connection.rb +189 -182
  189. data/test/integration/application_gateway.rb +208 -183
  190. data/test/integration/availability_set.rb +44 -27
  191. data/test/integration/blob.rb +293 -169
  192. data/test/integration/container.rb +93 -42
  193. data/test/integration/data_disk.rb +57 -46
  194. data/test/integration/deployment.rb +40 -32
  195. data/test/integration/express_route_circuit.rb +86 -82
  196. data/test/integration/external_load_balancer.rb +108 -100
  197. data/test/integration/internal_load_balancer.rb +115 -106
  198. data/test/integration/local_network_gateway.rb +46 -39
  199. data/test/integration/network_interface.rb +119 -107
  200. data/test/integration/network_security_group.rb +86 -74
  201. data/test/integration/network_security_rule.rb +65 -57
  202. data/test/integration/public_ip.rb +50 -42
  203. data/test/integration/record_set.rb +90 -78
  204. data/test/integration/resource_group.rb +26 -14
  205. data/test/integration/resource_tag.rb +56 -45
  206. data/test/integration/server.rb +152 -135
  207. data/test/integration/server_custom_image.rb +85 -76
  208. data/test/integration/sql_server.rb +130 -117
  209. data/test/integration/storage_account.rb +82 -70
  210. data/test/integration/subnet.rb +87 -74
  211. data/test/integration/traffic_manager.rb +86 -74
  212. data/test/integration/virtual_machine_extension.rb +115 -106
  213. data/test/integration/virtual_network.rb +121 -100
  214. data/test/integration/virtual_network_gateway.rb +86 -79
  215. data/test/integration/virtual_network_gateway_connection_to_express_route.rb +94 -87
  216. data/test/integration/zone.rb +36 -28
  217. data/test/models/storage/test_directories.rb +26 -71
  218. data/test/models/storage/test_directory.rb +111 -58
  219. data/test/models/storage/test_file.rb +179 -143
  220. data/test/models/storage/test_files.rb +197 -30
  221. data/test/models/storage/test_storage_account.rb +1 -1
  222. data/test/requests/compute/test_attach_data_disk_to_vm.rb +15 -17
  223. data/test/requests/storage/test_acquire_blob_lease.rb +23 -4
  224. data/test/requests/storage/test_acquire_container_lease.rb +24 -5
  225. data/test/requests/storage/test_commit_blob_blocks.rb +34 -0
  226. data/test/requests/storage/test_compare_container_blobs.rb +36 -0
  227. data/test/requests/storage/test_copy_blob.rb +22 -3
  228. data/test/requests/storage/test_copy_blob_from_uri.rb +23 -4
  229. data/test/requests/storage/test_create_block_blob.rb +80 -0
  230. data/test/requests/storage/test_create_container.rb +18 -13
  231. data/test/requests/storage/test_create_disk.rb +57 -4
  232. data/test/requests/storage/test_create_page_blob.rb +34 -0
  233. data/test/requests/storage/test_delete_blob.rb +25 -5
  234. data/test/requests/storage/test_delete_container.rb +21 -9
  235. data/test/requests/storage/test_delete_disk.rb +14 -7
  236. data/test/requests/storage/test_get_blob.rb +141 -0
  237. data/test/requests/storage/test_get_blob_http_url.rb +30 -0
  238. data/test/requests/storage/test_get_blob_https_url.rb +30 -0
  239. data/test/requests/storage/test_get_blob_properties.rb +29 -7
  240. data/test/requests/storage/test_get_blob_url.rb +33 -0
  241. data/test/requests/storage/test_get_container_acl.rb +37 -0
  242. data/test/requests/storage/test_get_container_properties.rb +25 -11
  243. data/test/requests/storage/test_get_container_url.rb +33 -0
  244. data/test/requests/storage/test_list_blobs.rb +77 -0
  245. data/test/requests/storage/test_list_containers.rb +38 -7
  246. data/test/requests/storage/test_multipart_save_block_blob.rb +105 -0
  247. data/test/requests/storage/test_put_blob_block.rb +34 -0
  248. data/test/requests/storage/test_put_blob_metadata.rb +36 -0
  249. data/test/requests/storage/test_put_blob_pages.rb +34 -0
  250. data/test/requests/storage/test_put_blob_properties.rb +39 -0
  251. data/test/requests/storage/test_put_container_acl.rb +34 -0
  252. data/test/requests/storage/test_put_container_metadata.rb +36 -0
  253. data/test/requests/storage/test_release_blob_lease.rb +20 -2
  254. data/test/requests/storage/test_release_container_lease.rb +21 -3
  255. data/test/requests/storage/test_save_page_blob.rb +115 -0
  256. data/test/requests/storage/test_wait_blob_copy_operation_to_finish.rb +148 -0
  257. data/test/test_helper.rb +34 -21
  258. metadata +92 -46
  259. data/lib/fog/azurerm/requests/storage/check_blob_exist.rb +0 -25
  260. data/lib/fog/azurerm/requests/storage/compare_blob.rb +0 -73
  261. data/lib/fog/azurerm/requests/storage/download_blob_to_file.rb +0 -56
  262. data/lib/fog/azurerm/requests/storage/get_blob_metadata.rb +0 -59
  263. data/lib/fog/azurerm/requests/storage/get_container_access_control_list.rb +0 -30
  264. data/lib/fog/azurerm/requests/storage/get_container_metadata.rb +0 -32
  265. data/lib/fog/azurerm/requests/storage/set_blob_properties.rb +0 -26
  266. data/lib/fog/azurerm/requests/storage/upload_block_blob_from_file.rb +0 -60
  267. data/test/requests/storage/test_check_blob_exist.rb +0 -17
  268. data/test/requests/storage/test_compare_blob.rb +0 -17
  269. data/test/requests/storage/test_download_blob_to_file.rb +0 -25
  270. data/test/requests/storage/test_get_blob_metadata.rb +0 -18
  271. data/test/requests/storage/test_get_container_access_control_list.rb +0 -31
  272. data/test/requests/storage/test_get_container_metadata.rb +0 -18
  273. data/test/requests/storage/test_list_blobs_in_container.rb +0 -23
  274. data/test/requests/storage/test_set_blob_metadata.rb +0 -17
  275. data/test/requests/storage/test_set_blob_properties.rb +0 -16
  276. data/test/requests/storage/test_set_container_metadata.rb +0 -17
  277. data/test/requests/storage/test_upload_block_blob_from_file.rb +0 -23
@@ -0,0 +1,34 @@
1
+ module Fog
2
+ module Storage
3
+ class AzureRM
4
+ # This class provides the actual implemention for service calls.
5
+ class Real
6
+ # Get a public container url from Azure storage container
7
+ #
8
+ # @param container_name [String] Name of container
9
+ #
10
+ # @return [String] - url for container
11
+ #
12
+ def get_container_url(container_name, options = {})
13
+ query = { 'comp' => 'list', 'restype' => 'container' }
14
+ uri = @blob_client.generate_uri(container_name, query)
15
+
16
+ if options[:scheme] == 'http'
17
+ uri.to_s.gsub('https:', 'http:')
18
+ else
19
+ uri.to_s
20
+ end
21
+ end
22
+ end
23
+
24
+ # This class provides the mock implementation for unit tests.
25
+ class Mock
26
+ def get_container_url(_container_name, options = {})
27
+ url = 'https://sa.blob.core.windows.net/test_container?comp=list&restype=container'
28
+ url.gsub!('https:', 'http:') if options[:scheme] == 'http'
29
+ url
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -19,7 +19,7 @@ module Fog
19
19
  raise_azure_exception(e, msg)
20
20
  end
21
21
  Fog::Logger.debug "Recovery Vault #{name} from Resource Group #{resource_group} retrieved successfully"
22
- recovery_vault = JSON.parse(recovery_vault_response)['value']
22
+ recovery_vault = Fog::JSON.decode(recovery_vault_response)['value']
23
23
  recovery_vault.select { |vault| vault['name'].eql? name }[0]
24
24
  end
25
25
  end
@@ -41,7 +41,7 @@ module Fog
41
41
  }
42
42
  }]
43
43
  }'
44
- JSON.parse(body)['value'][0]
44
+ Fog::JSON.decode(body)['value'][0]
45
45
  end
46
46
  end
47
47
  end
@@ -4,12 +4,13 @@ module Fog
4
4
  # This class provides the actual implementation for service calls.
5
5
  class Real
6
6
  def get_storage_access_keys(resource_group, storage_account_name, options = {})
7
- msg = "Getting storage access keys for storage account: #{storage_account_name}."
7
+ options[:request_id] = SecureRandom.uuid
8
+ msg = "Getting storage access keys for storage account: #{storage_account_name}, #{options}."
8
9
  Fog::Logger.debug msg
9
10
  begin
10
11
  storage_account_keys = @storage_mgmt_client.storage_accounts.list_keys(resource_group, storage_account_name, options)
11
- rescue MsRestAzure::AzureOperationError => e
12
- raise_azure_exception(e, msg)
12
+ rescue MsRestAzure::AzureOperationError => ex
13
+ raise_azure_exception(ex, msg)
13
14
  end
14
15
  Fog::Logger.debug "Storage access keys for storage account: #{storage_account_name} listed successfully."
15
16
  storage_account_keys.keys
@@ -8,8 +8,8 @@ module Fog
8
8
  Fog::Logger.debug msg
9
9
  begin
10
10
  storage_account = @storage_mgmt_client.storage_accounts.get_properties(resource_group_name, storage_account_name)
11
- rescue MsRestAzure::AzureOperationError => e
12
- raise_azure_exception(e, msg)
11
+ rescue MsRestAzure::AzureOperationError => ex
12
+ raise_azure_exception(ex, msg)
13
13
  end
14
14
  Fog::Logger.debug "Getting storage account: #{storage_account_name} successfully."
15
15
  storage_account
@@ -1,17 +1,50 @@
1
1
  module Fog
2
2
  module Storage
3
3
  class AzureRM
4
- # This class provides the actual implemention for service calls.
4
+ # This class provides the actual implementation for service calls.
5
+ # https://msdn.microsoft.com/en-us/library/azure/dd135734.aspx
5
6
  class Real
6
7
  def list_blobs(container_name, options = {})
7
- Fog::Logger.debug "Listing blobs in container: #{container_name}"
8
+ options = options.dup
9
+ options[:metadata] = true
10
+ next_marker = nil
11
+ blobs = []
12
+
13
+ msg = nil
14
+
15
+ max_results = -1
16
+ max_results = options[:max_results].to_i if options[:max_results]
8
17
  begin
9
- blobs = @blob_client.list_blobs(container_name, options)
10
- Fog::Logger.debug "Listing blobs in container: #{container_name} successfully."
11
- blobs
18
+ loop do
19
+ options[:request_id] = SecureRandom.uuid
20
+ msg = "Listing blobs in container: #{container_name}, options: #{options}"
21
+ Fog::Logger.debug msg
22
+ temp = @blob_client.list_blobs(container_name, options)
23
+ # Workaround for the issue https://github.com/Azure/azure-storage-ruby/issues/37
24
+ raise temp unless temp.instance_of?(Azure::Service::EnumerationResults)
25
+
26
+ blobs += temp unless temp.empty?
27
+ break if temp.continuation_token.nil? || temp.continuation_token.empty?
28
+ options[:marker] = temp.continuation_token
29
+
30
+ next if max_results == -1
31
+
32
+ options[:max_results] = max_results - blobs.size
33
+ if options[:max_results].zero?
34
+ next_marker = temp.continuation_token
35
+ break
36
+ end
37
+ end
12
38
  rescue Azure::Core::Http::HTTPError => ex
13
- raise "Exception in listing blobs: #{ex.inspect}"
39
+ raise 'NotFound' if ex.message.include?('(404)')
40
+ raise_azure_exception(ex, msg)
14
41
  end
42
+
43
+ Fog::Logger.debug "Listing blobs in container: #{container_name} successfully."
44
+ {
45
+ next_marker: next_marker,
46
+ blobs: blobs
47
+ }
15
48
  end
16
49
  end
17
50
 
@@ -19,11 +52,13 @@ module Fog
19
52
  class Mock
20
53
  def list_blobs(*)
21
54
  Fog::Logger.debug 'Listing blobs in container successfully.'
22
- [
23
- {
24
- 'name' => 'testblob1',
25
- 'properties' =>
26
- {
55
+ {
56
+ next_marker: 'marker',
57
+ blobs: [
58
+ {
59
+ 'name' => 'test_blob1',
60
+ 'metadata' => {},
61
+ 'properties' => {
27
62
  'last_modified' => 'Mon, 04 Jul 2016 02:50:20 GMT',
28
63
  'etag' => '0x8D3A3B5F017F52D',
29
64
  'lease_status' => 'unlocked',
@@ -39,18 +74,69 @@ module Fog
39
74
  'blob_type' => 'PageBlob',
40
75
  'copy_id' => '095adc3b-e277-4c3d-97e0-0abca881f60c',
41
76
  'copy_status' => 'success',
42
- 'copy_source' => 'https://testaccount.blob.core.windows.net/testblob/testblob1?snapshot=2016-02-04T08%3A35%3A50.3256874Z',
77
+ 'copy_source' => 'https://testaccount.blob.core.windows.net/test_container/test_blob?snapshot=2016-02-04T08%3A35%3A50.3256874Z',
43
78
  'copy_progress' => '4194304/4194304',
44
79
  'copy_completion_time' => 'Thu, 04 Feb 2016 08:35:52 GMT',
45
80
  'copy_status_description' => nil,
46
81
  'accept_ranges' => 0
47
- },
48
- 'metadata' => {}
49
- },
50
- {
51
- 'name' => 'testblob2',
52
- 'properties' =>
53
- {
82
+ }
83
+ },
84
+ {
85
+ 'name' => 'test_blob2',
86
+ 'metadata' => {},
87
+ 'properties' => {
88
+ 'last_modified' => 'Tue, 04 Aug 2015 06:02:08 GMT',
89
+ 'etag' => '0x8D29C92173526C8',
90
+ 'lease_status' => 'unlocked',
91
+ 'lease_state' => 'available',
92
+ 'content_length' => 4_194_304,
93
+ 'content_type' => 'application/octet-stream',
94
+ 'content_encoding' => nil,
95
+ 'content_language' => nil,
96
+ 'content_disposition' => nil,
97
+ 'content_md5' => 'tXAohIyxuu/t94Lp/ujeRw==',
98
+ 'cache_control' => nil,
99
+ 'sequence_number' => 0,
100
+ 'blob_type' => 'PageBlob',
101
+ 'copy_id' => '0abcdc3b-4c3d-e277-97e0-0abca881f60c',
102
+ 'copy_status' => 'success',
103
+ 'copy_source' => 'https://testaccount.blob.core.windows.net/test_container/test_blob?snapshot=2016-02-04T08%3A35%3A55.3157696Z',
104
+ 'copy_progress' => '4194304/4194304',
105
+ 'copy_completion_time' => 'Thu, 04 Feb 2016 08:40:52 GMT',
106
+ 'copy_status_description' => nil,
107
+ 'accept_ranges' => 0
108
+ }
109
+ },
110
+ {
111
+ 'name' => 'test_blob3',
112
+ 'metadata' => {},
113
+ 'properties' => {
114
+ 'last_modified' => 'Tue, 04 Aug 2015 06:02:08 GMT',
115
+ 'etag' => '0x8D29C92173526C8',
116
+ 'lease_status' => 'unlocked',
117
+ 'lease_state' => 'available',
118
+ 'content_length' => 4_194_304,
119
+ 'content_type' => 'application/octet-stream',
120
+ 'content_encoding' => nil,
121
+ 'content_language' => nil,
122
+ 'content_disposition' => nil,
123
+ 'content_md5' => 'tXAohIyxuu/t94Lp/ujeRw==',
124
+ 'cache_control' => nil,
125
+ 'sequence_number' => 0,
126
+ 'blob_type' => 'PageBlob',
127
+ 'copy_id' => '0abcdc3b-4c3d-e277-97e0-0abca881f60c',
128
+ 'copy_status' => 'success',
129
+ 'copy_source' => 'https://testaccount.blob.core.windows.net/test_container/test_blob?snapshot=2016-02-04T08%3A35%3A55.3157696Z',
130
+ 'copy_progress' => '4194304/4194304',
131
+ 'copy_completion_time' => 'Thu, 04 Feb 2016 08:40:52 GMT',
132
+ 'copy_status_description' => nil,
133
+ 'accept_ranges' => 0
134
+ }
135
+ },
136
+ {
137
+ 'name' => 'test_blob4',
138
+ 'metadata' => {},
139
+ 'properties' => {
54
140
  'last_modified' => 'Tue, 04 Aug 2015 06:02:08 GMT',
55
141
  'etag' => '0x8D29C92173526C8',
56
142
  'lease_status' => 'unlocked',
@@ -66,15 +152,15 @@ module Fog
66
152
  'blob_type' => 'PageBlob',
67
153
  'copy_id' => '0abcdc3b-4c3d-e277-97e0-0abca881f60c',
68
154
  'copy_status' => 'success',
69
- 'copy_source' => 'https://testaccount.blob.core.windows.net/testblob/testblob2?snapshot=2016-02-04T08%3A35%3A55.3157696Z',
155
+ 'copy_source' => 'https://testaccount.blob.core.windows.net/test_container/test_blob?snapshot=2016-02-04T08%3A35%3A55.3157696Z',
70
156
  'copy_progress' => '4194304/4194304',
71
157
  'copy_completion_time' => 'Thu, 04 Feb 2016 08:40:52 GMT',
72
158
  'copy_status_description' => nil,
73
159
  'accept_ranges' => 0
74
- },
75
- 'metadata' => {}
76
- }
77
- ]
160
+ }
161
+ }
162
+ ]
163
+ }
78
164
  end
79
165
  end
80
166
  end
@@ -2,15 +2,30 @@ module Fog
2
2
  module Storage
3
3
  class AzureRM
4
4
  # This class provides the actual implementation for service calls.
5
+ # https://msdn.microsoft.com/en-us/library/azure/dd179352.aspx
5
6
  class Real
6
- def list_containers(options = {})
7
- msg = 'Listing containers.'
8
- Fog::Logger.debug msg
7
+ def list_containers
8
+ options = { metadata: true }
9
+ containers = []
10
+ msg = nil
11
+
9
12
  begin
10
- containers = @blob_client.list_containers(options)
13
+ loop do
14
+ options[:request_id] = SecureRandom.uuid
15
+ msg = "Listing containers. options: #{options}"
16
+ Fog::Logger.debug msg
17
+ temp = @blob_client.list_containers(options)
18
+ # Workaround for the issue https://github.com/Azure/azure-storage-ruby/issues/37
19
+ raise temp unless temp.instance_of?(Azure::Service::EnumerationResults)
20
+
21
+ containers += temp unless temp.empty?
22
+ break if temp.continuation_token.nil? || temp.continuation_token.empty?
23
+ options[:marker] = temp.continuation_token
24
+ end
11
25
  rescue Azure::Core::Http::HTTPError => ex
12
26
  raise_azure_exception(ex, msg)
13
27
  end
28
+
14
29
  Fog::Logger.debug 'Listing containers successfully.'
15
30
  containers
16
31
  end
@@ -18,29 +33,37 @@ module Fog
18
33
 
19
34
  # This class provides the mock implementation for unit tests.
20
35
  class Mock
21
- def list_containers(*)
36
+ def list_containers
22
37
  [
23
38
  {
24
- 'name' => 'testcontainer1',
25
- 'properties' =>
26
- {
27
- 'last_modified' => 'Mon, 04 Jul 2016 02:50:20 GMT',
28
- 'etag' => '0x8D3A3B5F017F52D',
29
- 'lease_status' => 'unlocked',
30
- 'lease_state' => 'available'
31
- },
32
- 'metadata' => {}
39
+ 'name' => 'test_container1',
40
+ 'metadata' => {},
41
+ 'properties' => {
42
+ 'last_modified' => 'Mon, 04 Jul 2016 02:50:20 GMT',
43
+ 'etag' => '0x8D3A3B5F017F52D',
44
+ 'lease_status' => 'unlocked',
45
+ 'lease_state' => 'available'
46
+ }
47
+ },
48
+ {
49
+ 'name' => 'test_container2',
50
+ 'metadata' => {},
51
+ 'properties' => {
52
+ 'last_modified' => 'Tue, 04 Aug 2015 06:01:08 GMT',
53
+ 'etag' => '0x8D29C92176C8352',
54
+ 'lease_status' => 'unlocked',
55
+ 'lease_state' => 'available'
56
+ }
33
57
  },
34
58
  {
35
- 'name' => 'testcontainer2',
36
- 'properties' =>
37
- {
38
- 'last_modified' => 'Tue, 04 Aug 2015 06:01:08 GMT',
39
- 'etag' => '0x8D29C92176C8352',
40
- 'lease_status' => 'unlocked',
41
- 'lease_state' => 'available'
42
- },
43
- 'metadata' => {}
59
+ 'name' => 'test_container3',
60
+ 'metadata' => {},
61
+ 'properties' => {
62
+ 'last_modified' => 'Tue, 01 Sep 2015 05:15:36 GMT',
63
+ 'etag' => '0x8D2B28C5EB36458',
64
+ 'lease_status' => 'unlocked',
65
+ 'lease_state' => 'available'
66
+ }
44
67
  }
45
68
  ]
46
69
  end
@@ -19,7 +19,7 @@ module Fog
19
19
  raise_azure_exception(e, msg)
20
20
  end
21
21
  Fog::Logger.debug "Recovery Vaults in Resource Group #{resource_group} listed successfully"
22
- JSON.parse(recovery_vaults_response)['value']
22
+ Fog::JSON.decode(recovery_vaults_response)['value']
23
23
  end
24
24
  end
25
25
 
@@ -40,7 +40,7 @@ module Fog
40
40
  }
41
41
  }]
42
42
  }'
43
- JSON.parse(body)['value']
43
+ Fog::JSON.decode(body)['value']
44
44
  end
45
45
  end
46
46
  end
@@ -8,8 +8,8 @@ module Fog
8
8
  Fog::Logger.debug msg
9
9
  begin
10
10
  result = @storage_mgmt_client.storage_accounts.list_by_resource_group(resource_group)
11
- rescue MsRestAzure::AzureOperationError => e
12
- raise_azure_exception(e, msg)
11
+ rescue MsRestAzure::AzureOperationError => ex
12
+ raise_azure_exception(ex, msg)
13
13
  end
14
14
  result.value
15
15
  end
@@ -8,8 +8,8 @@ module Fog
8
8
  Fog::Logger.debug msg
9
9
  begin
10
10
  result = @storage_mgmt_client.storage_accounts.list
11
- rescue MsRestAzure::AzureOperationError => e
12
- raise_azure_exception(e, msg)
11
+ rescue MsRestAzure::AzureOperationError => ex
12
+ raise_azure_exception(ex, msg)
13
13
  end
14
14
  result.value
15
15
  end
@@ -0,0 +1,110 @@
1
+ module Fog
2
+ module Storage
3
+ class AzureRM
4
+ # This class provides the actual implementation for service calls.
5
+ class Real
6
+ # This class is used to store chunk data for block blob before uploading.
7
+ class BlockChunk
8
+ attr_reader :id # For debug
9
+ attr_reader :block_id
10
+ attr_reader :data
11
+
12
+ def initialize(id, block_id, data)
13
+ @id = id
14
+ @block_id = block_id
15
+ @data = data
16
+ end
17
+ end
18
+
19
+ # This class is a stream to read chunk data.
20
+ class BlockFileStream
21
+ attr_reader :blocks
22
+
23
+ def initialize(body)
24
+ if body.respond_to?(:read)
25
+ if body.respond_to?(:rewind)
26
+ begin
27
+ body.rewind
28
+ rescue => ex
29
+ Fog::Logger.debug "multipart_save_block_blob - body responds to :rewind but throws an exception when calling :rewind: #{ex.inspect}"
30
+ end
31
+ end
32
+ @stream = body
33
+ else
34
+ @stream = StringIO.new(body)
35
+ end
36
+ @mutex = Mutex.new
37
+ @blocks = []
38
+ end
39
+
40
+ def read(size)
41
+ block_id = Base64.strict_encode64(random_string(32))
42
+ data = nil
43
+ id = 0
44
+ @mutex.synchronize do
45
+ data = @stream.read(size)
46
+ return nil if data.nil?
47
+ @blocks << [block_id]
48
+ id = @blocks.size
49
+ end
50
+ BlockChunk.new(id, block_id, data)
51
+ end
52
+ end
53
+
54
+ def multipart_save_block_blob(container_name, blob_name, body, options)
55
+ threads_num = options.delete(:worker_thread_num)
56
+ threads_num = UPLOAD_BLOB_WORKER_THREAD_COUNT if threads_num.nil? || !threads_num.is_a?(Integer) || threads_num < 1
57
+
58
+ begin
59
+ # Initiate the upload
60
+ Fog::Logger.debug "Creating the block blob #{container_name}/#{blob_name}. options: #{options}"
61
+ content_md5 = options.delete(:content_md5)
62
+ create_block_blob(container_name, blob_name, nil, options)
63
+
64
+ # Uploading parts
65
+ Fog::Logger.debug "Starting to upload parts for the block blob #{container_name}/#{blob_name}."
66
+ iostream = BlockFileStream.new(body)
67
+
68
+ threads = []
69
+ threads_num.times do |id|
70
+ thread = Thread.new do
71
+ Fog::Logger.debug "Created upload thread #{id}."
72
+ while (chunk = iostream.read(MAXIMUM_CHUNK_SIZE))
73
+ Fog::Logger.debug "Upload thread #{id} is uploading #{chunk.id}, size: #{chunk.data.size}, options: #{options}."
74
+ put_blob_block(container_name, blob_name, chunk.block_id, chunk.data, options)
75
+ end
76
+ Fog::Logger.debug "Upload thread #{id} finished."
77
+ end
78
+ thread.abort_on_exception = true
79
+ threads << thread
80
+ end
81
+
82
+ threads.each(&:join)
83
+ # Complete the upload
84
+ options[:content_md5] = content_md5 unless content_md5.nil?
85
+ Fog::Logger.debug "Commiting the block blob #{container_name}/#{blob_name}. options: #{options}"
86
+ commit_blob_blocks(container_name, blob_name, iostream.blocks, options)
87
+ rescue
88
+ # Abort the upload & reraise
89
+ begin
90
+ delete_blob(container_name, blob_name)
91
+ rescue => ex
92
+ Fog::Logger.debug "Cannot delete the blob: #{container_name}/#{blob_name} after multipart_save_block_blob failed. #{ex.inspect}"
93
+ end
94
+ raise
95
+ end
96
+
97
+ Fog::Logger.debug "Successfully save the block blob: #{container_name}/#{blob_name}."
98
+ true
99
+ end
100
+ end
101
+
102
+ # This class provides the mock implementation for unit tests.
103
+ class Mock
104
+ def multipart_save_block_blob(*)
105
+ true
106
+ end
107
+ end
108
+ end
109
+ end
110
+ end