fog-azure-rm 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (288) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +17 -0
  3. data/.gitignore +6 -0
  4. data/.hound.yml +2 -0
  5. data/.rubocop.yml +36 -0
  6. data/.travis.yml +14 -0
  7. data/CHANGELOG.md +28 -0
  8. data/CONTRIBUTING.md +2 -0
  9. data/CONTRIBUTORS.md +2 -0
  10. data/Gemfile +3 -0
  11. data/fog-azure-rm.gemspec +34 -0
  12. data/lib/fog/azurerm.rb +1 -0
  13. data/lib/fog/azurerm/compute.rb +0 -1
  14. data/lib/fog/azurerm/config.rb +4 -0
  15. data/lib/fog/azurerm/credentials.rb +10 -3
  16. data/lib/fog/azurerm/docs/compute.md +172 -0
  17. data/lib/fog/azurerm/docs/dns.md +112 -0
  18. data/lib/fog/azurerm/docs/network.md +794 -0
  19. data/lib/fog/azurerm/docs/resources.md +155 -0
  20. data/lib/fog/azurerm/docs/storage.md +222 -0
  21. data/lib/fog/azurerm/docs/structure.md +53 -0
  22. data/lib/fog/azurerm/models/compute/server.rb +3 -2
  23. data/lib/fog/azurerm/models/network/frontend_ip_configuration.rb +5 -1
  24. data/lib/fog/azurerm/models/network/network_interface.rb +49 -4
  25. data/lib/fog/azurerm/models/network/network_interfaces.rb +4 -2
  26. data/lib/fog/azurerm/models/network/network_security_group.rb +27 -4
  27. data/lib/fog/azurerm/models/network/network_security_groups.rb +4 -2
  28. data/lib/fog/azurerm/models/network/network_security_rule.rb +1 -1
  29. data/lib/fog/azurerm/models/network/subnet.rb +26 -6
  30. data/lib/fog/azurerm/models/network/subnets.rb +4 -2
  31. data/lib/fog/azurerm/models/network/virtual_network.rb +72 -10
  32. data/lib/fog/azurerm/models/network/virtual_networks.rb +4 -2
  33. data/lib/fog/azurerm/models/resources/azure_resource.rb +25 -0
  34. data/lib/fog/azurerm/models/resources/azure_resources.rb +31 -0
  35. data/lib/fog/azurerm/models/resources/dependency.rb +27 -0
  36. data/lib/fog/azurerm/models/resources/deployment.rb +65 -0
  37. data/lib/fog/azurerm/models/resources/deployments.rb +27 -0
  38. data/lib/fog/azurerm/models/resources/provider.rb +27 -0
  39. data/lib/fog/azurerm/models/resources/provider_resource_type.rb +22 -0
  40. data/lib/fog/azurerm/models/storage/blob.rb +13 -0
  41. data/lib/fog/azurerm/models/storage/blobs.rb +22 -0
  42. data/lib/fog/azurerm/models/storage/container.rb +65 -0
  43. data/lib/fog/azurerm/models/storage/containers.rb +44 -0
  44. data/lib/fog/azurerm/models/storage/data_disk.rb +26 -0
  45. data/lib/fog/azurerm/models/storage/storage_account.rb +4 -0
  46. data/lib/fog/azurerm/network.rb +21 -3
  47. data/lib/fog/azurerm/requests/network/add_address_prefixes_in_virtual_network.rb +68 -0
  48. data/lib/fog/azurerm/requests/network/add_dns_servers_in_virtual_network.rb +74 -0
  49. data/lib/fog/azurerm/requests/network/add_security_rules.rb +152 -0
  50. data/lib/fog/azurerm/requests/network/add_subnets_in_virtual_network.rb +69 -0
  51. data/lib/fog/azurerm/requests/network/attach_network_security_group_to_subnet.rb +59 -0
  52. data/lib/fog/azurerm/requests/network/attach_resource_to_nic.rb +88 -0
  53. data/lib/fog/azurerm/requests/network/attach_route_table_to_subnet.rb +59 -0
  54. data/lib/fog/azurerm/requests/network/create_load_balancer.rb +4 -4
  55. data/lib/fog/azurerm/requests/network/{create_network_interface.rb → create_or_update_network_interface.rb} +14 -13
  56. data/lib/fog/azurerm/requests/network/{create_network_security_group.rb → create_or_update_network_security_group.rb} +17 -35
  57. data/lib/fog/azurerm/requests/network/create_or_update_virtual_network.rb +116 -0
  58. data/lib/fog/azurerm/requests/network/create_subnet.rb +28 -14
  59. data/lib/fog/azurerm/requests/network/detach_network_security_group_from_subnet.rb +53 -0
  60. data/lib/fog/azurerm/requests/network/detach_resource_from_nic.rb +80 -0
  61. data/lib/fog/azurerm/requests/network/detach_route_table_from_subnet.rb +53 -0
  62. data/lib/fog/azurerm/requests/network/get_network_interface.rb +60 -0
  63. data/lib/fog/azurerm/requests/network/get_network_security_group.rb +161 -0
  64. data/lib/fog/azurerm/requests/network/get_subnet.rb +36 -0
  65. data/lib/fog/azurerm/requests/network/get_virtual_network.rb +64 -0
  66. data/lib/fog/azurerm/requests/network/remove_address_prefixes_from_virtual_network.rb +67 -0
  67. data/lib/fog/azurerm/requests/network/remove_dns_servers_from_virtual_network.rb +67 -0
  68. data/lib/fog/azurerm/requests/network/remove_security_rule.rb +155 -0
  69. data/lib/fog/azurerm/requests/network/remove_subnets_from_virtual_network.rb +57 -0
  70. data/lib/fog/azurerm/requests/resources/create_deployment.rb +90 -0
  71. data/lib/fog/azurerm/requests/resources/delete_deployment.rb +28 -0
  72. data/lib/fog/azurerm/requests/resources/delete_resource_tag.rb +48 -0
  73. data/lib/fog/azurerm/requests/resources/list_deployments.rb +75 -0
  74. data/lib/fog/azurerm/requests/resources/list_tagged_resources.rb +46 -0
  75. data/lib/fog/azurerm/requests/resources/tag_resource.rb +46 -0
  76. data/lib/fog/azurerm/requests/storage/create_container.rb +37 -0
  77. data/lib/fog/azurerm/requests/storage/delete_container.rb +26 -0
  78. data/lib/fog/azurerm/requests/storage/delete_disk.rb +36 -0
  79. data/lib/fog/azurerm/requests/storage/get_blob_metadata.rb +30 -0
  80. data/lib/fog/azurerm/requests/storage/get_container_access_control_list.rb +29 -0
  81. data/lib/fog/azurerm/requests/storage/get_container_metadata.rb +31 -0
  82. data/lib/fog/azurerm/requests/storage/get_container_properties.rb +36 -0
  83. data/lib/fog/azurerm/requests/storage/get_storage_access_keys.rb +31 -0
  84. data/lib/fog/azurerm/requests/storage/list_containers.rb +49 -0
  85. data/lib/fog/azurerm/requests/storage/list_storage_account_for_rg.rb +0 -1
  86. data/lib/fog/azurerm/requests/storage/set_blob_metadata.rb +26 -0
  87. data/lib/fog/azurerm/requests/storage/set_container_metadata.rb +26 -0
  88. data/lib/fog/azurerm/resources.rb +13 -0
  89. data/lib/fog/azurerm/storage.rb +46 -6
  90. data/lib/fog/azurerm/utilities/general.rb +18 -0
  91. data/lib/fog/azurerm/version.rb +1 -1
  92. data/rakefile +21 -0
  93. data/test/api_stub.rb +44 -0
  94. data/test/api_stub/models/compute/availability_set.rb +21 -0
  95. data/test/api_stub/models/compute/server.rb +191 -0
  96. data/test/api_stub/models/dns/record_set.rb +59 -0
  97. data/test/api_stub/models/dns/zone.rb +47 -0
  98. data/test/api_stub/models/network/application_gateway.rb +135 -0
  99. data/test/api_stub/models/network/load_balancer.rb +132 -0
  100. data/test/api_stub/models/network/network_interface.rb +71 -0
  101. data/test/api_stub/models/network/network_security_group.rb +94 -0
  102. data/test/api_stub/models/network/public_ip.rb +35 -0
  103. data/test/api_stub/models/network/subnet.rb +35 -0
  104. data/test/api_stub/models/network/traffic_manager_end_point.rb +26 -0
  105. data/test/api_stub/models/network/traffic_manager_profile.rb +74 -0
  106. data/test/api_stub/models/network/virtual_network.rb +61 -0
  107. data/test/api_stub/models/resources/deployment.rb +110 -0
  108. data/test/api_stub/models/resources/resource.rb +40 -0
  109. data/test/api_stub/models/resources/resource_group.rb +38 -0
  110. data/test/api_stub/models/storage/blob.rb +17 -0
  111. data/test/api_stub/models/storage/container.rb +92 -0
  112. data/test/api_stub/models/storage/data_disk.rb +30 -0
  113. data/test/api_stub/models/storage/storageaccount.rb +29 -0
  114. data/test/api_stub/requests/compute/availability_set.rb +46 -0
  115. data/test/api_stub/requests/compute/virtual_machine.rb +654 -0
  116. data/test/api_stub/requests/dns/record_set.rb +105 -0
  117. data/test/api_stub/requests/dns/zone.rb +67 -0
  118. data/test/api_stub/requests/network/application_gateway.rb +433 -0
  119. data/test/api_stub/requests/network/load_balancer.rb +366 -0
  120. data/test/api_stub/requests/network/network_interface.rb +268 -0
  121. data/test/api_stub/requests/network/network_security_group.rb +240 -0
  122. data/test/api_stub/requests/network/public_ip.rb +73 -0
  123. data/test/api_stub/requests/network/subnet.rb +73 -0
  124. data/test/api_stub/requests/network/traffic_manager_endpoint.rb +25 -0
  125. data/test/api_stub/requests/network/traffic_manager_profile.rb +140 -0
  126. data/test/api_stub/requests/network/virtual_network.rb +127 -0
  127. data/test/api_stub/requests/resources/deployment.rb +23 -0
  128. data/test/api_stub/requests/resources/resource.rb +47 -0
  129. data/test/api_stub/requests/resources/resource_group.rb +53 -0
  130. data/test/api_stub/requests/storage/blob.rb +24 -0
  131. data/test/api_stub/requests/storage/container.rb +95 -0
  132. data/test/api_stub/requests/storage/storageaccount.rb +112 -0
  133. data/test/integration/README.md +14 -0
  134. data/test/integration/application_gateway.rb +129 -0
  135. data/test/integration/availability_set.rb +56 -0
  136. data/test/integration/container.rb +81 -0
  137. data/test/integration/credentials/azure.yml +4 -0
  138. data/test/integration/external_load_balancer.rb +119 -0
  139. data/test/integration/internal_load_balancer.rb +126 -0
  140. data/test/integration/network_interface.rb +135 -0
  141. data/test/integration/network_security_group.rb +104 -0
  142. data/test/integration/public_ip.rb +63 -0
  143. data/test/integration/record_set.rb +88 -0
  144. data/test/integration/server.rb +139 -0
  145. data/test/integration/storage_account.rb +62 -0
  146. data/test/integration/subnet.rb +91 -0
  147. data/test/integration/traffic_manager.rb +81 -0
  148. data/test/integration/virtual_network.rb +124 -0
  149. data/test/integration/zone.rb +64 -0
  150. data/test/models/compute/test_availability_set.rb +53 -0
  151. data/test/models/compute/test_availability_sets.rb +41 -0
  152. data/test/models/compute/test_server.rb +143 -0
  153. data/test/models/compute/test_servers.rb +49 -0
  154. data/test/models/dns/test_record_set.rb +59 -0
  155. data/test/models/dns/test_record_sets.rb +51 -0
  156. data/test/models/dns/test_zone.rb +49 -0
  157. data/test/models/dns/test_zones.rb +49 -0
  158. data/test/models/network/test_application_gateway.rb +62 -0
  159. data/test/models/network/test_application_gateways.rb +42 -0
  160. data/test/models/network/test_load_balancer.rb +56 -0
  161. data/test/models/network/test_load_balancers.rb +42 -0
  162. data/test/models/network/test_network_interface.rb +106 -0
  163. data/test/models/network/test_network_interfaces.rb +41 -0
  164. data/test/models/network/test_network_security_group.rb +88 -0
  165. data/test/models/network/test_network_security_groups.rb +40 -0
  166. data/test/models/network/test_network_security_rule.rb +30 -0
  167. data/test/models/network/test_public_ip.rb +58 -0
  168. data/test/models/network/test_public_ips.rb +55 -0
  169. data/test/models/network/test_subnet.rb +84 -0
  170. data/test/models/network/test_subnets.rb +42 -0
  171. data/test/models/network/test_traffic_manager_end_point.rb +53 -0
  172. data/test/models/network/test_traffic_manager_end_points.rb +42 -0
  173. data/test/models/network/test_traffic_manager_profile.rb +54 -0
  174. data/test/models/network/test_traffic_manager_profiles.rb +41 -0
  175. data/test/models/network/test_virtual_network.rb +112 -0
  176. data/test/models/network/test_virtual_networks.rb +54 -0
  177. data/test/models/resources/test_deployment.rb +54 -0
  178. data/test/models/resources/test_deployments.rb +37 -0
  179. data/test/models/resources/test_resource.rb +22 -0
  180. data/test/models/resources/test_resource_group.rb +43 -0
  181. data/test/models/resources/test_resource_groups.rb +37 -0
  182. data/test/models/resources/test_resources.rb +38 -0
  183. data/test/models/storage/test_blobs.rb +32 -0
  184. data/test/models/storage/test_container.rb +67 -0
  185. data/test/models/storage/test_containers.rb +56 -0
  186. data/test/models/storage/test_data_disk.rb +29 -0
  187. data/test/models/storage/test_storage_account.rb +62 -0
  188. data/test/models/storage/test_storage_accounts.rb +65 -0
  189. data/test/requests/compute/test_attach_data_disk_to_vm.rb +175 -0
  190. data/test/requests/compute/test_create_availability_set.rb +30 -0
  191. data/test/requests/compute/test_create_virtual_machine.rb +50 -0
  192. data/test/requests/compute/test_deallocate_virtual_machine.rb +29 -0
  193. data/test/requests/compute/test_delete_availability_set.rb +29 -0
  194. data/test/requests/compute/test_delete_virtual_machine.rb +29 -0
  195. data/test/requests/compute/test_detach_data_disk_from_vm.rb +53 -0
  196. data/test/requests/compute/test_generalize_virtual_machine.rb +29 -0
  197. data/test/requests/compute/test_get_virtual_machine.rb +31 -0
  198. data/test/requests/compute/test_get_vm_status.rb +31 -0
  199. data/test/requests/compute/test_list_availability_sets.rb +30 -0
  200. data/test/requests/compute/test_list_available_sizes_for_virtual_machine.rb +31 -0
  201. data/test/requests/compute/test_list_virtual_machines.rb +30 -0
  202. data/test/requests/compute/test_power_off_virtual_machine.rb +29 -0
  203. data/test/requests/compute/test_redeploy_virtual_machine.rb +29 -0
  204. data/test/requests/compute/test_restart_virtual_machine.rb +29 -0
  205. data/test/requests/compute/test_start_virtual_machine.rb +29 -0
  206. data/test/requests/dns/test_check_for_zone.rb +52 -0
  207. data/test/requests/dns/test_create_record_set.rb +45 -0
  208. data/test/requests/dns/test_create_zone.rb +36 -0
  209. data/test/requests/dns/test_delete_record_set.rb +35 -0
  210. data/test/requests/dns/test_delete_zone.rb +35 -0
  211. data/test/requests/dns/test_get_records_from_record_set.rb +55 -0
  212. data/test/requests/dns/test_list_record_sets.rb +36 -0
  213. data/test/requests/dns/test_list_zones.rb +40 -0
  214. data/test/requests/network/test_add_address_prefixes_in_virtual_network.rb +45 -0
  215. data/test/requests/network/test_add_dns_servers_in_virtual_network.rb +45 -0
  216. data/test/requests/network/test_add_security_rules.rb +63 -0
  217. data/test/requests/network/test_add_subnets_in_virtual_network.rb +45 -0
  218. data/test/requests/network/test_attach_network_security_group_to_subnet.rb +33 -0
  219. data/test/requests/network/test_attach_resource_to_nic.rb +65 -0
  220. data/test/requests/network/test_attach_route_table_to_subnet.rb +33 -0
  221. data/test/requests/network/test_check_for_public_ip.rb +38 -0
  222. data/test/requests/network/test_check_for_virtual_network.rb +38 -0
  223. data/test/requests/network/test_create_application_gateway.rb +61 -0
  224. data/test/requests/network/test_create_load_balancer.rb +56 -0
  225. data/test/requests/network/test_create_network_interface.rb +54 -0
  226. data/test/requests/network/test_create_network_security_group.rb +45 -0
  227. data/test/requests/network/test_create_or_update_virtual_network.rb +63 -0
  228. data/test/requests/network/test_create_public_ip.rb +44 -0
  229. data/test/requests/network/test_create_subnet.rb +44 -0
  230. data/test/requests/network/test_create_traffic_manager_endpoint.rb +32 -0
  231. data/test/requests/network/test_create_traffic_manager_profile.rb +32 -0
  232. data/test/requests/network/test_delete_application_gateway.rb +30 -0
  233. data/test/requests/network/test_delete_load_balancer.rb +30 -0
  234. data/test/requests/network/test_delete_network_interface.rb +30 -0
  235. data/test/requests/network/test_delete_network_security_group.rb +32 -0
  236. data/test/requests/network/test_delete_public_ip.rb +30 -0
  237. data/test/requests/network/test_delete_subnet.rb +30 -0
  238. data/test/requests/network/test_delete_traffic_manager_endpoint.rb +28 -0
  239. data/test/requests/network/test_delete_traffic_manager_profile.rb +28 -0
  240. data/test/requests/network/test_delete_virtual_network.rb +30 -0
  241. data/test/requests/network/test_detach_network_security_group_from_subnet.rb +33 -0
  242. data/test/requests/network/test_detach_resource_from_nic.rb +60 -0
  243. data/test/requests/network/test_detach_route_table_from_subnet.rb +33 -0
  244. data/test/requests/network/test_get_network_interface.rb +31 -0
  245. data/test/requests/network/test_get_network_security_group.rb +33 -0
  246. data/test/requests/network/test_get_subnet.rb +33 -0
  247. data/test/requests/network/test_get_traffic_manager_profile.rb +29 -0
  248. data/test/requests/network/test_list_application_gateways.rb +31 -0
  249. data/test/requests/network/test_list_load_balancers.rb +31 -0
  250. data/test/requests/network/test_list_network_interfaces.rb +31 -0
  251. data/test/requests/network/test_list_network_security_groups.rb +33 -0
  252. data/test/requests/network/test_list_public_ips.rb +31 -0
  253. data/test/requests/network/test_list_subnets.rb +31 -0
  254. data/test/requests/network/test_list_traffic_manager_profiles.rb +29 -0
  255. data/test/requests/network/test_list_virtual_networks.rb +31 -0
  256. data/test/requests/network/test_remove_address_prefixes_from_virtual_network.rb +45 -0
  257. data/test/requests/network/test_remove_dns_servers_from_virtual_network.rb +45 -0
  258. data/test/requests/network/test_remove_security_rule.rb +49 -0
  259. data/test/requests/network/test_remove_subnets_from_virtual_network.rb +45 -0
  260. data/test/requests/resources/test_create_deployment.rb +49 -0
  261. data/test/requests/resources/test_create_resource_group.rb +31 -0
  262. data/test/requests/resources/test_delete_deployment.rb +31 -0
  263. data/test/requests/resources/test_delete_resource_group.rb +30 -0
  264. data/test/requests/resources/test_delete_resource_tag.rb +51 -0
  265. data/test/requests/resources/test_list_deployments.rb +32 -0
  266. data/test/requests/resources/test_list_resource_groups.rb +31 -0
  267. data/test/requests/resources/test_list_tagged_resources.rb +31 -0
  268. data/test/requests/resources/test_tag_resource.rb +51 -0
  269. data/test/requests/storage/test_check_storage_account_name_availability.rb +59 -0
  270. data/test/requests/storage/test_create_container.rb +31 -0
  271. data/test/requests/storage/test_create_storage_account.rb +56 -0
  272. data/test/requests/storage/test_delete_container.rb +30 -0
  273. data/test/requests/storage/test_delete_storage_account.rb +34 -0
  274. data/test/requests/storage/test_get_blob_metadata.rb +18 -0
  275. data/test/requests/storage/test_get_container_access_control_list.rb +31 -0
  276. data/test/requests/storage/test_get_container_metadata.rb +18 -0
  277. data/test/requests/storage/test_get_container_properties.rb +31 -0
  278. data/test/requests/storage/test_get_storage_access_keys.rb +31 -0
  279. data/test/requests/storage/test_list_containers.rb +23 -0
  280. data/test/requests/storage/test_list_storage_accounts.rb +47 -0
  281. data/test/requests/storage/test_list_storage_accounts_for_rg.rb +51 -0
  282. data/test/requests/storage/test_set_blob_metadata.rb +17 -0
  283. data/test/requests/storage/test_set_container_metadata.rb +17 -0
  284. data/test/test_credentials.rb +39 -0
  285. data/test/test_helper.rb +428 -0
  286. metadata +273 -14
  287. data/lib/fog/azurerm/models/compute/data_disk.rb +0 -26
  288. data/lib/fog/azurerm/requests/network/create_virtual_network.rb +0 -115
@@ -1,7 +1,7 @@
1
1
  module Fog
2
2
  module Network
3
3
  class AzureRM
4
- # Real class for Network Request
4
+ # Real class for Load-Balancer Request
5
5
  class Real
6
6
  def create_load_balancer(name, location, resource_group, frontend_ip_configurations, backend_address_pool_names, load_balancing_rules, probes, inbound_nat_rules, inbound_nat_pools)
7
7
  Fog::Logger.debug "Creating Load-Balancer: #{name}..."
@@ -23,7 +23,7 @@ module Fog
23
23
  lb_props = Azure::ARM::Network::Models::LoadBalancerPropertiesFormat.new
24
24
 
25
25
  if frontend_ip_configurations
26
- frontend_ip_configuration_arr = define_frontend_ip_configurations(frontend_ip_configurations)
26
+ frontend_ip_configuration_arr = define_lb_frontend_ip_configurations(frontend_ip_configurations)
27
27
  lb_props.frontend_ipconfigurations = []
28
28
  lb_props.frontend_ipconfigurations = frontend_ip_configuration_arr
29
29
  end
@@ -172,7 +172,7 @@ module Fog
172
172
  load_balancing_rule_arr
173
173
  end
174
174
 
175
- def define_frontend_ip_configurations(frontend_ip_configurations)
175
+ def define_lb_frontend_ip_configurations(frontend_ip_configurations)
176
176
  frontend_ip_configuration_arr = []
177
177
  frontend_ip_configurations.each do |fic|
178
178
  frontend_ip_configuration = Azure::ARM::Network::Models::FrontendIPConfiguration.new
@@ -198,7 +198,7 @@ module Fog
198
198
  end
199
199
  end
200
200
 
201
- # Mock class for Network Request
201
+ # Mock class for Load-Balancer Request
202
202
  class Mock
203
203
  def create_load_balancer(_name, _location, _resource_group, _frontend_ip_configuration_name, _subnet_id, _private_ip_address, _private_ip_allocation_method, _public_ip_address_id, _backend_address_pool_names, _load_balancing_rules, _probes, _inbound_nat_rules, _inbound_nat_pools)
204
204
  end
@@ -4,23 +4,23 @@ module Fog
4
4
  class AzureRM
5
5
  # Real class for Network Request
6
6
  class Real
7
- def create_network_interface(resource_group, name, location, subnet_id, public_ip_address_id, ip_config_name, prv_ip_alloc_method)
8
- Fog::Logger.debug "Creating Network Interface Card: #{name}..."
9
- network_interface = define_network_interface(name, location, subnet_id, public_ip_address_id, ip_config_name, prv_ip_alloc_method)
7
+ def create_or_update_network_interface(resource_group_name, name, location, subnet_id, public_ip_address_id, ip_config_name, private_ip_allocation_method, private_ip_address)
8
+ Fog::Logger.debug "Creating/Updating Network Interface Card: #{name}..."
9
+ network_interface = get_network_interface_object(name, location, subnet_id, public_ip_address_id, ip_config_name, private_ip_allocation_method, private_ip_address)
10
10
  begin
11
- promise = @network_client.network_interfaces.create_or_update(resource_group, name, network_interface)
11
+ promise = @network_client.network_interfaces.create_or_update(resource_group_name, name, network_interface)
12
12
  result = promise.value!
13
- Fog::Logger.debug "Network Interface #{name} created successfully."
13
+ Fog::Logger.debug "Network Interface #{name} created/updated successfully."
14
14
  Azure::ARM::Network::Models::NetworkInterface.serialize_object(result.body)
15
15
  rescue MsRestAzure::AzureOperationError => e
16
- msg = "Exception creating Network Interface #{name} in Resource Group: #{resource_group}. #{e.body['error']['message']}"
16
+ msg = "Exception creating/updating Network Interface #{name} in Resource Group: #{resource_group_name}. #{e.body['error']['message']}"
17
17
  raise msg
18
18
  end
19
19
  end
20
20
 
21
21
  private
22
22
 
23
- def define_network_interface(name, location, subnet_id, public_ip_address_id, ip_config_name, prv_ip_alloc_method)
23
+ def get_network_interface_object(name, location, subnet_id, public_ip_address_id, ip_config_name, private_ip_allocation_method, private_ip_address)
24
24
  subnet = Azure::ARM::Network::Models::Subnet.new
25
25
  subnet.id = subnet_id
26
26
 
@@ -30,7 +30,8 @@ module Fog
30
30
  end
31
31
 
32
32
  ip_configs_props = Azure::ARM::Network::Models::NetworkInterfaceIPConfigurationPropertiesFormat.new
33
- ip_configs_props.private_ipallocation_method = prv_ip_alloc_method
33
+ ip_configs_props.private_ipallocation_method = private_ip_allocation_method
34
+ ip_configs_props.private_ipaddress = private_ip_address
34
35
  ip_configs_props.public_ipaddress = public_ipaddress
35
36
  ip_configs_props.subnet = subnet
36
37
 
@@ -52,9 +53,9 @@ module Fog
52
53
 
53
54
  # Mock class for Network Request
54
55
  class Mock
55
- def create_network_interface(resource_group, name, location, subnet_id, public_ip_address_id, ip_configs_name, prv_ip_alloc_method)
56
+ def create_or_update_network_interface(resource_group_name, name, location, subnet_id, public_ip_address_id, ip_configs_name, private_ip_allocation_method, private_ip_address)
56
57
  {
57
- 'id' => "/subscriptions/########-####-####-####-############/resourceGroups/#{resource_group}/providers/Microsoft.Network/networkInterfaces/#{name}",
58
+ 'id' => "/subscriptions/########-####-####-####-############/resourceGroups/#{resource_group_name}/providers/Microsoft.Network/networkInterfaces/#{name}",
58
59
  'name' => name,
59
60
  'type' => 'Microsoft.Network/networkInterfaces',
60
61
  'location' => location,
@@ -63,11 +64,11 @@ module Fog
63
64
  'ipConfigurations' =>
64
65
  [
65
66
  {
66
- 'id' => "/subscriptions/########-####-####-####-############/resourceGroups/#{resource_group}/providers/Microsoft.Network/networkInterfaces/#{name}/ipConfigurations/#{ip_configs_name}",
67
+ 'id' => "/subscriptions/########-####-####-####-############/resourceGroups/#{resource_group_name}/providers/Microsoft.Network/networkInterfaces/#{name}/ipConfigurations/#{ip_configs_name}",
67
68
  'properties' =>
68
69
  {
69
- 'privateIPAddress' => '10.0.0.5',
70
- 'privateIPAllocationMethod' => prv_ip_alloc_method,
70
+ 'privateIPAddress' => private_ip_address,
71
+ 'privateIPAllocationMethod' => private_ip_allocation_method,
71
72
  'subnet' =>
72
73
  {
73
74
  'id' => subnet_id
@@ -3,28 +3,28 @@ module Fog
3
3
  class AzureRM
4
4
  # Real class for Network Request
5
5
  class Real
6
- def create_network_security_group(resource_group, name, location, security_rules)
7
- Fog::Logger.debug "Creating Network Security Group #{name} in Resource Group #{resource_group}."
6
+ def create_or_update_network_security_group(resource_group_name, security_group_name, location, security_rules)
7
+ Fog::Logger.debug "Creating/Updating Network Security Group #{security_group_name} in Resource Group #{resource_group_name}."
8
8
  properties = Azure::ARM::Network::Models::NetworkSecurityGroupPropertiesFormat.new
9
- properties.security_rules = define_security_rules(security_rules)
9
+ properties.security_rules = create_security_rule_objects(security_rules)
10
10
 
11
11
  params = Azure::ARM::Network::Models::NetworkSecurityGroup.new
12
12
  params.location = location
13
13
  params.properties = properties
14
14
  begin
15
- promise = @network_client.network_security_groups.begin_create_or_update(resource_group, name, params)
15
+ promise = @network_client.network_security_groups.begin_create_or_update(resource_group_name, security_group_name, params)
16
16
  result = promise.value!
17
- Fog::Logger.debug "Network Security Group #{name} Created Successfully!"
17
+ Fog::Logger.debug "Network Security Group #{security_group_name} Created/Updated Successfully!"
18
18
  Azure::ARM::Network::Models::NetworkSecurityGroup.serialize_object(result.body)
19
19
  rescue MsRestAzure::AzureOperationError => e
20
- msg = "Exception creating Network Security Group #{name} in Resource Group: #{resource_group}. #{e.body['error']['message']}"
20
+ msg = "Exception creating/updating Network Security Group #{security_group_name} in Resource Group: #{resource_group_name}. #{e.body['error']['message']}"
21
21
  raise msg
22
22
  end
23
23
  end
24
24
 
25
25
  private
26
26
 
27
- def define_security_rules(security_rules)
27
+ def create_security_rule_objects(security_rules)
28
28
  rules = []
29
29
  security_rules.each do |sr|
30
30
  properties = Azure::ARM::Network::Models::SecurityRulePropertiesFormat.new
@@ -49,37 +49,19 @@ module Fog
49
49
 
50
50
  # Mock class for Network Request
51
51
  class Mock
52
- def create_network_security_group(resource_group, name, location, _security_rules)
52
+ def create_or_update_network_security_group(resource_group_name, security_group_name, location, security_rules)
53
53
  {
54
- 'id' => "/subscriptions/########-####-####-####-############/resourceGroups/#{resource_group}/providers/Microsoft.Network/networkSecurityGroups/#{name}",
55
- 'name' => name,
54
+ 'id' => "/subscriptions/########-####-####-####-############/resourceGroups/#{resource_group_name}/providers/Microsoft.Network/networkSecurityGroups/#{security_group_name}",
55
+ 'name' => security_group_name,
56
56
  'type' => 'Microsoft.Network/networkSecurityGroups',
57
57
  'location' => location,
58
58
  'properties' =>
59
59
  {
60
- 'securityRules' =>
61
- [
62
- {
63
- 'id' => "/subscriptions/########-####-####-####-############/resourceGroups/#{resource_group}/providers/Microsoft.Network/networkSecurityGroups/#{name}/securityRules/testRule",
64
- 'properties' =>
65
- {
66
- 'protocol' => 'tcp',
67
- 'sourceAddressPrefix' => '0.0.0.0/0',
68
- 'destinationAddressPrefix' => '0.0.0.0/0',
69
- 'access' => 'Allow',
70
- 'direction' => 'Inbound',
71
- 'sourcePortRange' => '22',
72
- 'destinationPortRange' => '22',
73
- 'priority' => 100,
74
- 'provisioningState' => 'Updating'
75
- },
76
- 'name' => 'testRule'
77
- }
78
- ],
60
+ 'securityRules' => security_rules,
79
61
  'defaultSecurityRules' =>
80
62
  [
81
63
  {
82
- 'id' => "/subscriptions/########-####-####-####-############/resourceGroups/#{resource_group}/providers/Microsoft.Network/networkSecurityGroups/#{name}/defaultSecurityRules/AllowVnetInBound",
64
+ 'id' => "/subscriptions/########-####-####-####-############/resourceGroups/#{resource_group_name}/providers/Microsoft.Network/networkSecurityGroups/#{security_group_name}/defaultSecurityRules/AllowVnetInBound",
83
65
  'properties' =>
84
66
  {
85
67
  'protocol' => '*',
@@ -96,7 +78,7 @@ module Fog
96
78
  'name' => 'AllowVnetInBound'
97
79
  },
98
80
  {
99
- 'id' => "/subscriptions/########-####-####-####-############/resourceGroups/#{resource_group}/providers/Microsoft.Network/networkSecurityGroups/#{name}/defaultSecurityRules/AllowAzureLoadBalancerInBound",
81
+ 'id' => "/subscriptions/########-####-####-####-############/resourceGroups/#{resource_group_name}/providers/Microsoft.Network/networkSecurityGroups/#{security_group_name}/defaultSecurityRules/AllowAzureLoadBalancerInBound",
100
82
  'properties' =>
101
83
  {
102
84
  'protocol' => '*',
@@ -113,7 +95,7 @@ module Fog
113
95
  'name' => 'AllowAzureLoadBalancerInBound'
114
96
  },
115
97
  {
116
- 'id' => "/subscriptions/########-####-####-####-############/resourceGroups/#{resource_group}/providers/Microsoft.Network/networkSecurityGroups/#{name}/defaultSecurityRules/DenyAllInBound",
98
+ 'id' => "/subscriptions/########-####-####-####-############/resourceGroups/#{resource_group_name}/providers/Microsoft.Network/networkSecurityGroups/#{security_group_name}/defaultSecurityRules/DenyAllInBound",
117
99
  'properties' =>
118
100
  {
119
101
  'protocol' => '*',
@@ -130,7 +112,7 @@ module Fog
130
112
  'name' => 'DenyAllInBound'
131
113
  },
132
114
  {
133
- 'id' => "/subscriptions/########-####-####-####-############/resourceGroups/#{resource_group}/providers/Microsoft.Network/networkSecurityGroups/#{name}/defaultSecurityRules/AllowVnetOutBound",
115
+ 'id' => "/subscriptions/########-####-####-####-############/resourceGroups/#{resource_group_name}/providers/Microsoft.Network/networkSecurityGroups/#{security_group_name}/defaultSecurityRules/AllowVnetOutBound",
134
116
  'properties' =>
135
117
  {
136
118
  'protocol' => '*',
@@ -147,7 +129,7 @@ module Fog
147
129
  'name' => 'AllowVnetOutBound'
148
130
  },
149
131
  {
150
- 'id' => "/subscriptions/########-####-####-####-############/resourceGroups/#{resource_group}/providers/Microsoft.Network/networkSecurityGroups/#{name}/defaultSecurityRules/AllowInternetOutBound",
132
+ 'id' => "/subscriptions/########-####-####-####-############/resourceGroups/#{resource_group_name}/providers/Microsoft.Network/networkSecurityGroups/#{security_group_name}/defaultSecurityRules/AllowInternetOutBound",
151
133
  'properties' =>
152
134
  {
153
135
  'protocol' => '*',
@@ -164,7 +146,7 @@ module Fog
164
146
  'name' => 'AllowInternetOutBound'
165
147
  },
166
148
  {
167
- 'id' => "/subscriptions/########-####-####-####-############/resourceGroups/#{resource_group}/providers/Microsoft.Network/networkSecurityGroups/#{name}/defaultSecurityRules/DenyAllOutBound",
149
+ 'id' => "/subscriptions/########-####-####-####-############/resourceGroups/#{resource_group_name}/providers/Microsoft.Network/networkSecurityGroups/#{security_group_name}/defaultSecurityRules/DenyAllOutBound",
168
150
  'properties' =>
169
151
  {
170
152
  'protocol' => '*',
@@ -0,0 +1,116 @@
1
+ module Fog
2
+ module Network
3
+ class AzureRM
4
+ # Real class for Network Request
5
+ class Real
6
+ def create_or_update_virtual_network(resource_group_name, virtual_network_name, location, dns_servers, subnets, address_prefixes)
7
+ virtual_network = define_vnet_object(location, address_prefixes, dns_servers, subnets)
8
+ vnet = create_or_update_vnet(resource_group_name, virtual_network_name, virtual_network)
9
+ Azure::ARM::Network::Models::VirtualNetwork.serialize_object(vnet)
10
+ end
11
+
12
+ private
13
+
14
+ def create_or_update_vnet(resource_group_name, virtual_network_name, virtual_network)
15
+ Fog::Logger.debug "Creating/Updating Virtual Network: #{virtual_network_name}"
16
+ begin
17
+ response = @network_client.virtual_networks.create_or_update(resource_group_name, virtual_network_name, virtual_network).value!
18
+ Fog::Logger.debug "Virtual Network #{virtual_network_name} created/updated successfully."
19
+ response.body
20
+ rescue MsRestAzure::AzureOperationError => e
21
+ msg = "Exception creating/updating Virtual Network #{virtual_network_name} in Resource Group: #{resource_group_name}. #{e.body['error']['message']}"
22
+ raise msg
23
+ end
24
+ end
25
+
26
+ def define_vnet_object(location, address_prefixes, dns_servers, subnets)
27
+ virtual_network = Azure::ARM::Network::Models::VirtualNetwork.new
28
+ virtual_network.location = location
29
+ virtual_network_properties = Azure::ARM::Network::Models::VirtualNetworkPropertiesFormat.new
30
+
31
+ if address_prefixes.nil? || !address_prefixes.any?
32
+ address_space = Azure::ARM::Network::Models::AddressSpace.new
33
+ address_space.address_prefixes = DEFAULT_ADDRESS_PREFIXES
34
+ else
35
+ address_space = Azure::ARM::Network::Models::AddressSpace.new
36
+ address_space.address_prefixes = address_prefixes
37
+ end
38
+ virtual_network_properties.address_space = address_space
39
+
40
+ if !dns_servers.nil? && dns_servers.any?
41
+ dhcp_options = Azure::ARM::Network::Models::DhcpOptions.new
42
+ dhcp_options.dns_servers = dns_servers
43
+ virtual_network_properties.dhcp_options = dhcp_options
44
+ end
45
+
46
+ if !subnets.nil? && subnets.any?
47
+ subnet_objects = define_subnet_objects(subnets)
48
+ virtual_network_properties.subnets = subnet_objects
49
+ end
50
+
51
+ virtual_network.properties = virtual_network_properties
52
+ virtual_network
53
+ end
54
+
55
+ def define_subnet_objects(subnets)
56
+ subnet_objects = []
57
+ subnets.each do |subnet|
58
+ network_security_group = Azure::ARM::Network::Models::NetworkSecurityGroup.new
59
+ network_security_group.id = subnet[:network_security_group_id]
60
+
61
+ route_table = Azure::ARM::Network::Models::RouteTable.new
62
+ route_table.id = subnet[:route_table_id]
63
+
64
+ subnet_properties = Azure::ARM::Network::Models::SubnetPropertiesFormat.new
65
+ subnet_properties.address_prefix = subnet[:address_prefix]
66
+ subnet_properties.network_security_group = network_security_group unless subnet[:network_security_group_id].nil?
67
+ subnet_properties.route_table = route_table unless subnet[:route_table_id].nil?
68
+
69
+ subnet_object = Azure::ARM::Network::Models::Subnet.new
70
+ subnet_object.name = subnet[:name]
71
+ subnet_object.properties = subnet_properties
72
+ subnet_objects << subnet_object
73
+ end
74
+ subnet_objects
75
+ end
76
+ end
77
+
78
+ # Mock class for Network Request
79
+ class Mock
80
+ def create_or_update__virtual_network(*)
81
+ {
82
+ 'id' => '/subscriptions/########-####-####-####-############/resourceGroups/fog-rg/providers/Microsoft.Network/virtualNetworks/fog-vnet',
83
+ 'name' => 'fog-vnet',
84
+ 'type' => 'Microsoft.Network/virtualNetworks',
85
+ 'location' => 'westus',
86
+ 'properties' =>
87
+ {
88
+ 'addressSpace' =>
89
+ {
90
+ 'addressPrefixes' =>
91
+ [
92
+ '10.1.0.0/16',
93
+ '10.2.0.0/16'
94
+ ]
95
+ },
96
+ 'subnets' =>
97
+ [
98
+ {
99
+ 'id' => '/subscriptions/########-####-####-####-############/resourceGroups/fog-rg/providers/Microsoft.Network/virtualNetworks/fog-vnet/subnets/fog-subnet',
100
+ 'properties' =>
101
+ {
102
+ 'addressPrefix' => [],
103
+ 'provisioningState' => 'Succeeded'
104
+ },
105
+ 'name' => "subnet_0_#{name}"
106
+ }
107
+ ],
108
+ 'resourceGuid' => 'c573f8e2-d916-493f-8b25-a681c31269ef',
109
+ 'provisioningState' => 'Succeeded'
110
+ }
111
+ }
112
+ end
113
+ end
114
+ end
115
+ end
116
+ end
@@ -3,37 +3,51 @@ module Fog
3
3
  class AzureRM
4
4
  # Real class for Network Request
5
5
  class Real
6
- def create_subnet(resource_group, name, virtual_network_name, address_prefix)
7
- Fog::Logger.debug "Creating Subnet: #{name}..."
8
- subnet_properties = Azure::ARM::Network::Models::SubnetPropertiesFormat.new
9
- subnet_properties.address_prefix = address_prefix unless address_prefix.nil?
6
+ def create_subnet(resource_group, subnet_name, virtual_network_name, address_prefix, network_security_group_id, route_table_id)
7
+ Fog::Logger.debug "Creating Subnet: #{subnet_name}."
10
8
 
11
- subnet = Azure::ARM::Network::Models::Subnet.new
12
- subnet.name = name
13
- subnet.properties = subnet_properties
9
+ subnet = get_subnet_object(address_prefix, network_security_group_id, route_table_id)
14
10
  begin
15
- promise = @network_client.subnets.create_or_update(resource_group, virtual_network_name, name, subnet)
11
+ promise = @network_client.subnets.create_or_update(resource_group, virtual_network_name, subnet_name, subnet)
16
12
  result = promise.value!
17
- Fog::Logger.debug "Subnet #{name} created successfully."
13
+ Fog::Logger.debug "Subnet #{subnet_name} created successfully."
18
14
  Azure::ARM::Network::Models::Subnet.serialize_object(result.body)
19
15
  rescue MsRestAzure::AzureOperationError => e
20
- msg = "Exception creating Subnet #{name} in Resource Group: #{resource_group}. #{e.body['error']['message']}"
16
+ msg = "Exception creating Subnet #{subnet_name} in Resource Group: #{resource_group}. #{e.body['error']['message']}"
21
17
  raise msg
22
18
  end
23
19
  end
20
+
21
+ private
22
+
23
+ def get_subnet_object(address_prefix, network_security_group_id, route_table_id)
24
+ subnet = Azure::ARM::Network::Models::Subnet.new
25
+ subnet_properties = Azure::ARM::Network::Models::SubnetPropertiesFormat.new
26
+ network_security_group = Azure::ARM::Network::Models::NetworkSecurityGroup.new
27
+ route_table = Azure::ARM::Network::Models::RouteTable.new
28
+
29
+ subnet_properties.address_prefix = address_prefix
30
+ network_security_group.id = network_security_group_id
31
+ route_table.id = route_table_id
32
+
33
+ subnet_properties.network_security_group = network_security_group unless network_security_group_id.nil?
34
+ subnet_properties.route_table = route_table unless route_table_id.nil?
35
+ subnet.properties = subnet_properties
36
+ subnet
37
+ end
24
38
  end
25
39
 
26
40
  # Mock class for Network Request
27
41
  class Mock
28
- def create_subnet(resource_group, name, virtual_network_name, address_prefix)
42
+ def create_subnet(*)
29
43
  {
30
- 'id' => "/subscriptions/########-####-####-####-############/resourceGroups/#{resource_group}/providers/Microsoft.Network/virtualNetworks/#{virtual_network_name}/subnets/#{name}",
44
+ 'id' => '/subscriptions/########-####-####-####-############/resourceGroups/fog-rg/providers/Microsoft.Network/virtualNetworks/fog-vnet/subnets/fog-subnet',
31
45
  'properties' =>
32
46
  {
33
- 'addressPrefix' => address_prefix,
47
+ 'addressPrefix' => '10.1.0.0/24',
34
48
  'provisioningState' => 'Succeeded'
35
49
  },
36
- 'name' => name
50
+ 'name' => 'fog-subnet'
37
51
  }
38
52
  end
39
53
  end
@@ -0,0 +1,53 @@
1
+ module Fog
2
+ module Network
3
+ class AzureRM
4
+ # Real class for Network Request
5
+ class Real
6
+ def detach_network_security_group_from_subnet(resource_group, subnet_name, virtual_network_name, address_prefix, route_table_id)
7
+ Fog::Logger.debug "Detaching Network Security Group from Subnet: #{subnet_name}."
8
+
9
+ subnet = define_subnet_object_for_detach_network_security_group(address_prefix, route_table_id)
10
+ begin
11
+ promise = @network_client.subnets.create_or_update(resource_group, virtual_network_name, subnet_name, subnet)
12
+ result = promise.value!
13
+ Fog::Logger.debug 'Network Security Group detached successfully.'
14
+ Azure::ARM::Network::Models::Subnet.serialize_object(result.body)
15
+ rescue MsRestAzure::AzureOperationError => e
16
+ msg = "Exception detaching Network Security Group from Subnet: #{subnet_name}. #{e.body['error']['message']}"
17
+ raise msg
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ def define_subnet_object_for_detach_network_security_group(address_prefix, route_table_id)
24
+ subnet = Azure::ARM::Network::Models::Subnet.new
25
+ subnet_properties = Azure::ARM::Network::Models::SubnetPropertiesFormat.new
26
+ route_table = Azure::ARM::Network::Models::RouteTable.new
27
+
28
+ route_table.id = route_table_id
29
+ subnet_properties.address_prefix = address_prefix
30
+ subnet_properties.route_table = route_table unless route_table_id.nil?
31
+ subnet_properties.network_security_group = nil
32
+ subnet.properties = subnet_properties
33
+ subnet
34
+ end
35
+ end
36
+
37
+ # Mock class for Network Request
38
+ class Mock
39
+ def detach_network_security_group_from_subnet(*)
40
+ {
41
+ 'id' => '/subscriptions/########-####-####-####-############/resourceGroups/fog-rg/providers/Microsoft.Network/virtualNetworks/fog-vnet/subnets/fog-subnet',
42
+ 'properties' =>
43
+ {
44
+ 'addressPrefix' => '10.1.0.0/24',
45
+ 'provisioningState' => 'Succeeded'
46
+ },
47
+ 'name' => 'fog-subnet'
48
+ }
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end