fog-azure-rm 0.0.9 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -0
  3. data/CHANGELOG.md +9 -0
  4. data/lib/fog/azurerm/docs/compute.md +1 -1
  5. data/lib/fog/azurerm/docs/sql.md +39 -0
  6. data/lib/fog/azurerm/docs/storage.md +89 -2
  7. data/lib/fog/azurerm/models/application_gateway/gateways.rb +4 -7
  8. data/lib/fog/azurerm/models/compute/availability_sets.rb +4 -6
  9. data/lib/fog/azurerm/models/compute/servers.rb +5 -8
  10. data/lib/fog/azurerm/models/compute/virtual_machine_extensions.rb +0 -3
  11. data/lib/fog/azurerm/models/dns/record_sets.rb +5 -9
  12. data/lib/fog/azurerm/models/dns/zones.rb +4 -7
  13. data/lib/fog/azurerm/models/network/express_route_circuit_authorizations.rb +0 -3
  14. data/lib/fog/azurerm/models/network/express_route_circuit_peerings.rb +5 -9
  15. data/lib/fog/azurerm/models/network/express_route_circuits.rb +4 -7
  16. data/lib/fog/azurerm/models/network/express_route_service_providers.rb +2 -5
  17. data/lib/fog/azurerm/models/network/load_balancers.rb +4 -7
  18. data/lib/fog/azurerm/models/network/local_network_gateways.rb +0 -3
  19. data/lib/fog/azurerm/models/network/network_interfaces.rb +4 -7
  20. data/lib/fog/azurerm/models/network/network_security_groups.rb +4 -7
  21. data/lib/fog/azurerm/models/network/network_security_rules.rb +2 -6
  22. data/lib/fog/azurerm/models/network/public_ips.rb +4 -7
  23. data/lib/fog/azurerm/models/network/subnets.rb +5 -9
  24. data/lib/fog/azurerm/models/network/virtual_network_gateway_connections.rb +0 -3
  25. data/lib/fog/azurerm/models/network/virtual_network_gateways.rb +4 -7
  26. data/lib/fog/azurerm/models/network/virtual_networks.rb +4 -7
  27. data/lib/fog/azurerm/models/resources/azure_resources.rb +2 -5
  28. data/lib/fog/azurerm/models/resources/deployments.rb +4 -7
  29. data/lib/fog/azurerm/models/resources/resource_groups.rb +4 -7
  30. data/lib/fog/azurerm/models/sql/firewall_rule.rb +52 -0
  31. data/lib/fog/azurerm/models/sql/firewall_rules.rb +28 -0
  32. data/lib/fog/azurerm/models/storage/data_disk.rb +1 -0
  33. data/lib/fog/azurerm/models/storage/directories.rb +1 -4
  34. data/lib/fog/azurerm/models/storage/files.rb +1 -4
  35. data/lib/fog/azurerm/models/storage/recovery_vault.rb +50 -0
  36. data/lib/fog/azurerm/models/storage/recovery_vaults.rb +27 -0
  37. data/lib/fog/azurerm/models/storage/storage_account.rb +23 -4
  38. data/lib/fog/azurerm/models/storage/storage_accounts.rb +5 -7
  39. data/lib/fog/azurerm/requests/sql/create_or_update_database.rb +4 -4
  40. data/lib/fog/azurerm/requests/sql/create_or_update_firewall_rule.rb +56 -0
  41. data/lib/fog/azurerm/requests/sql/create_or_update_sql_server.rb +4 -5
  42. data/lib/fog/azurerm/requests/sql/delete_database.rb +4 -4
  43. data/lib/fog/azurerm/requests/sql/delete_firewall_rule.rb +36 -0
  44. data/lib/fog/azurerm/requests/sql/delete_sql_server.rb +2 -2
  45. data/lib/fog/azurerm/requests/sql/get_database.rb +2 -2
  46. data/lib/fog/azurerm/requests/sql/get_firewall_rule.rb +43 -0
  47. data/lib/fog/azurerm/requests/sql/get_sql_server.rb +2 -2
  48. data/lib/fog/azurerm/requests/sql/list_databases.rb +2 -2
  49. data/lib/fog/azurerm/requests/sql/list_firewall_rules.rb +55 -0
  50. data/lib/fog/azurerm/requests/sql/list_sql_servers.rb +2 -2
  51. data/lib/fog/azurerm/requests/storage/create_disk.rb +36 -0
  52. data/lib/fog/azurerm/requests/storage/create_or_update_recovery_vault.rb +54 -0
  53. data/lib/fog/azurerm/requests/storage/create_storage_account.rb +13 -2
  54. data/lib/fog/azurerm/requests/storage/delete_disk.rb +5 -9
  55. data/lib/fog/azurerm/requests/storage/delete_recovery_vault.rb +35 -0
  56. data/lib/fog/azurerm/requests/storage/disable_backup_protection.rb +60 -0
  57. data/lib/fog/azurerm/requests/storage/enable_backup_protection.rb +61 -0
  58. data/lib/fog/azurerm/requests/storage/get_all_backup_jobs.rb +56 -0
  59. data/lib/fog/azurerm/requests/storage/get_backup_container.rb +53 -0
  60. data/lib/fog/azurerm/requests/storage/get_backup_item.rb +58 -0
  61. data/lib/fog/azurerm/requests/storage/get_backup_job_for_vm.rb +53 -0
  62. data/lib/fog/azurerm/requests/storage/get_backup_protection_policy.rb +64 -0
  63. data/lib/fog/azurerm/requests/storage/get_recovery_vault.rb +49 -0
  64. data/lib/fog/azurerm/requests/storage/list_recovery_vaults.rb +48 -0
  65. data/lib/fog/azurerm/requests/storage/set_recovery_vault_context.rb +36 -0
  66. data/lib/fog/azurerm/requests/storage/start_backup.rb +54 -0
  67. data/lib/fog/azurerm/requests/storage/update_storage_account.rb +59 -0
  68. data/lib/fog/azurerm/sql.rb +9 -0
  69. data/lib/fog/azurerm/storage.rb +24 -0
  70. data/lib/fog/azurerm/version.rb +1 -1
  71. data/rake-script.sh +8 -0
  72. data/rakefile +11 -3
  73. data/test/api_stub.rb +4 -0
  74. data/test/api_stub/models/sql/sql_firewall_rule.rb +22 -0
  75. data/test/api_stub/models/storage/recovery_vault.rb +23 -0
  76. data/test/api_stub/requests/sql/firewall_rule.rb +46 -0
  77. data/test/api_stub/requests/storage/recovery_vault.rb +189 -0
  78. data/test/api_stub/requests/storage/storageaccount.rb +2 -1
  79. data/test/integration/container.rb +4 -3
  80. data/test/integration/data_disk.rb +77 -0
  81. data/test/integration/express_route_circuit.rb +9 -9
  82. data/test/integration/server.rb +9 -2
  83. data/test/integration/sql_server.rb +35 -0
  84. data/test/integration/storage_account.rb +9 -1
  85. data/test/models/sql/test_firewall_rule.rb +54 -0
  86. data/test/models/sql/test_firewall_rules.rb +41 -0
  87. data/test/models/storage/test_recovery_vault.rb +61 -0
  88. data/test/models/storage/test_recovery_vaults.rb +47 -0
  89. data/test/models/storage/test_storage_account.rb +8 -1
  90. data/test/requests/sql/test_create_or_update_firewall_rule.rb +27 -0
  91. data/test/requests/sql/test_delete_firewall_rule.rb +34 -0
  92. data/test/requests/sql/test_get_firewall_rule.rb +35 -0
  93. data/test/requests/sql/test_list_firewall_rules.rb +35 -0
  94. data/test/requests/storage/test_create_disk.rb +17 -0
  95. data/test/requests/storage/test_create_recovery_vault.rb +35 -0
  96. data/test/requests/storage/test_delete_disk.rb +23 -0
  97. data/test/requests/storage/test_delete_recovery_vault.rb +34 -0
  98. data/test/requests/storage/test_disable_backup_protection.rb +52 -0
  99. data/test/requests/storage/test_enable_backup_protection.rb +66 -0
  100. data/test/requests/storage/test_get_all_backup_jobs.rb +35 -0
  101. data/test/requests/storage/test_get_backup_container.rb +35 -0
  102. data/test/requests/storage/test_get_backup_item.rb +35 -0
  103. data/test/requests/storage/test_get_backup_job_for_vm.rb +26 -0
  104. data/test/requests/storage/test_get_backup_protection_policy.rb +35 -0
  105. data/test/requests/storage/test_get_recovery_vault.rb +35 -0
  106. data/test/requests/storage/test_list_recovery_vault.rb +35 -0
  107. data/test/requests/storage/test_set_recovery_vault_context.rb +34 -0
  108. data/test/requests/storage/test_start_backup.rb +55 -0
  109. data/test/requests/storage/test_update_storage_account.rb +34 -0
  110. data/test/smoke_tests/compute/test_resource_group_smoke.rb +34 -24
  111. data/test/test_helper.rb +26 -0
  112. metadata +55 -2
@@ -15,8 +15,8 @@ module Fog
15
15
  content_type: :json,
16
16
  authorization: token
17
17
  )
18
- rescue MsRestAzure::AzureOperationError => e
19
- raise_azure_exception(e, JSON.parse(e.response)['message'])
18
+ rescue RestClient::Exception => e
19
+ raise JSON.parse(e.response)['message']
20
20
  end
21
21
  Fog::Logger.debug "Sql Server fetched successfully in Resource Group: #{resource_group}"
22
22
  JSON.parse(response)
@@ -15,8 +15,8 @@ module Fog
15
15
  content_type: :json,
16
16
  authorization: token
17
17
  )
18
- rescue MsRestAzure::AzureOperationError => e
19
- raise_azure_exception(e, JSON.parse(e.response)['message'])
18
+ rescue RestClient::Exception => e
19
+ raise JSON.parse(e.response)['message']
20
20
  end
21
21
  Fog::Logger.debug "Sql Databases listed successfully in Resource Group: #{resource_group}"
22
22
  JSON.parse(response)['value']
@@ -0,0 +1,55 @@
1
+ module Fog
2
+ module Sql
3
+ class AzureRM
4
+ # Real class for Sql Server Firewall Rule Request
5
+ class Real
6
+ def list_firewall_rules(resource_group, server_name)
7
+ msg = "Listing Sql Server Firewall rules on server: #{server_name} in Resource Group: #{resource_group}."
8
+ Fog::Logger.debug msg
9
+ resource_url = "#{AZURE_RESOURCE}/subscriptions/#{@subscription_id}/resourceGroups/#{resource_group}/providers/Microsoft.Sql/servers/#{server_name}/firewallRules/?api-version=2014-04-01-preview"
10
+ begin
11
+ token = Fog::Credentials::AzureRM.get_token(@tenant_id, @client_id, @client_secret)
12
+ response = RestClient.get(
13
+ resource_url,
14
+ accept: :json,
15
+ content_type: :json,
16
+ authorization: token
17
+ )
18
+ rescue RestClient::Exception => e
19
+ raise JSON.parse(e.response)['message']
20
+ end
21
+ Fog::Logger.debug "Sql Server Firewall Rules listed successfully on server: #{server_name} in Resource Group: #{resource_group}"
22
+ JSON.parse(response)['value']
23
+ end
24
+ end
25
+
26
+ # Mock class for Sql Server Firewall Rule Request
27
+ class Mock
28
+ def list_firewall_rules(*)
29
+ [
30
+ {
31
+ 'id' => '{uri-of-firewall-rule}',
32
+ 'name' => '{rule-name}',
33
+ 'type' => '{rule-type}',
34
+ 'location' => '{server-location}',
35
+ 'properties' => {
36
+ 'startIpAddress' => '{start-ip-address}',
37
+ 'endIpAddress' => '{end-ip-address}'
38
+ }
39
+ },
40
+ {
41
+ 'id' => '{uri-of-firewall-rule}',
42
+ 'name' => '{rule-name}',
43
+ 'type' => '{rule-type}',
44
+ 'location' => '{server-location}',
45
+ 'properties' => {
46
+ 'startIpAddress' => '{start-ip-address}',
47
+ 'endIpAddress' => '{end-ip-address}'
48
+ }
49
+ }
50
+ ]
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -15,8 +15,8 @@ module Fog
15
15
  content_type: :json,
16
16
  authorization: token
17
17
  )
18
- rescue MsRestAzure::AzureOperationError => e
19
- raise_azure_exception(e, JSON.parse(e.response)['message'])
18
+ rescue RestClient::Exception => e
19
+ raise JSON.parse(e.response)['message']
20
20
  end
21
21
  Fog::Logger.debug "Sql Servers listed successfully in Resource Group: #{resource_group}"
22
22
  JSON.parse(response)['value']
@@ -0,0 +1,36 @@
1
+ module Fog
2
+ module Storage
3
+ class AzureRM
4
+ # This class provides the actual implemention for service calls.
5
+ class Real
6
+ def create_disk(blob_name, options = {})
7
+ msg = "Creating disk(blob) #{blob_name}"
8
+ Fog::Logger.debug msg
9
+ ::File.open('out.txt', 'w') { |f| f.write('Sample File') }
10
+ path = ::File.expand_path(::File.dirname('out.txt')) + '/' + 'out.txt'
11
+ begin
12
+ disk = upload_block_blob_from_file('vhds', "#{blob_name}.vhd", path.to_s, options)
13
+ rescue Azure::Core::Http::HTTPError => e
14
+ raise_azure_exception(e, msg)
15
+ end
16
+ disk
17
+ end
18
+ end
19
+ # This class provides the mock implementation for unit tests.
20
+ class Mock
21
+ def create_disk(*)
22
+ Fog::Logger.debug 'Disk(Blob) created successfully.'
23
+ {
24
+ 'name' => 'test_blob',
25
+ 'properties' =>
26
+ {
27
+ 'last_modified' => 'Thu, 28 Jul 2016 06:53:05 GMT',
28
+ 'etag' => '0x8D3B6B3D353FFCA',
29
+ 'content_md5' => 'tXAohIyxuu/t94Lp/ujeRw=='
30
+ }
31
+ }
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,54 @@
1
+ module Fog
2
+ module Storage
3
+ class AzureRM
4
+ # Real class for Recovery Vault request
5
+ class Real
6
+ def create_or_update_recovery_vault(resource_group, location, name)
7
+ msg = "Creating/Updating Recovery Vault #{name} in Resource Group #{resource_group}"
8
+ Fog::Logger.debug msg
9
+
10
+ resource_url = "#{AZURE_RESOURCE}/subscriptions/#{@subscription_id}/resourceGroups/#{resource_group}/providers/Microsoft.RecoveryServices/vaults/#{name}?api-version=2016-05-01"
11
+ body = {
12
+ location: location,
13
+ tags: {},
14
+ sku: { name: 'standard' },
15
+ properties: {}
16
+ }
17
+ begin
18
+ token = Fog::Credentials::AzureRM.get_token(@tenant_id, @client_id, @client_secret)
19
+ response = RestClient.put(
20
+ resource_url,
21
+ body.to_json,
22
+ accept: 'application/json',
23
+ content_type: 'application/json',
24
+ authorization: token
25
+ )
26
+ rescue RestClient::Exception => e
27
+ raise_azure_exception(e, msg)
28
+ end
29
+ Fog::Logger.debug "Recovery Vault #{name} created/updated successfully"
30
+ JSON.parse(response)
31
+ end
32
+ end
33
+
34
+ # Mock class for Recovery Vault request
35
+ class Mock
36
+ def create_or_update_recovery_vault(*)
37
+ recovery_vault = '{
38
+ "location": "westus",
39
+ "name": "fog-test-vault",
40
+ "properties": {
41
+ "provisioningState": "Succeeded"
42
+ },
43
+ "id": "/subscriptions/########-####-####-####-############/resourceGroups/fog-test-rg/providers/Microsoft.RecoveryServices/vaults/fog-test-vault",
44
+ "type": "Microsoft.RecoveryServices/vaults",
45
+ "sku": {
46
+ "name": "standard"
47
+ }
48
+ }'
49
+ JSON.parse(recovery_vault)
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -8,7 +8,8 @@ module Fog
8
8
  Fog::Logger.debug msg
9
9
  storage_account_params = get_storage_account_params(storage_account_hash[:sku_name],
10
10
  storage_account_hash[:location],
11
- storage_account_hash[:replication])
11
+ storage_account_hash[:replication],
12
+ storage_account_hash[:encryption])
12
13
  begin
13
14
  storage_account = @storage_mgmt_client.storage_accounts.create(storage_account_hash[:resource_group],
14
15
  storage_account_hash[:name],
@@ -22,13 +23,23 @@ module Fog
22
23
 
23
24
  private
24
25
 
25
- def get_storage_account_params(sku_name, location, replication)
26
+ def get_storage_account_params(sku_name, location, replication, encryption_enabled)
26
27
  params = Azure::ARM::Storage::Models::StorageAccountCreateParameters.new
27
28
  sku = Azure::ARM::Storage::Models::Sku.new
28
29
  sku.name = "#{sku_name}_#{replication}"
29
30
  params.sku = sku
30
31
  params.kind = Azure::ARM::Storage::Models::Kind::Storage
31
32
  params.location = location
33
+ unless encryption_enabled.nil?
34
+ encryption = Azure::ARM::Storage::Models::Encryption.new
35
+ encryption_services = Azure::ARM::Storage::Models::EncryptionServices.new
36
+ encryption_service = Azure::ARM::Storage::Models::EncryptionService.new
37
+ encryption_service.enabled = encryption_enabled
38
+ encryption_service.last_enabled_time = Time.new if encryption_service.enabled
39
+ encryption_services.blob = encryption_service
40
+ encryption.services = encryption_services
41
+ params.encryption = encryption
42
+ end
32
43
  params
33
44
  end
34
45
  end
@@ -3,15 +3,11 @@ module Fog
3
3
  class AzureRM
4
4
  # This class provides the actual implementation for service calls.
5
5
  class Real
6
- def delete_disk(resource_group, storage_account_name, blob_name)
6
+ def delete_disk(blob_name)
7
7
  msg = "Deleting Disk: #{blob_name}."
8
8
  Fog::Logger.debug msg
9
- keys = get_storage_access_keys(resource_group, storage_account_name)
10
- access_key = keys[1].value
11
- client = Azure::Storage::Client.new(storage_account_name: storage_account_name, storage_access_key: access_key)
12
- blob_service = Azure::Storage::Blob::BlobService.new(client: client)
13
9
  begin
14
- result = blob_service.delete_blob('vhds', "#{blob_name}.vhd")
10
+ result = delete_blob('vhds', "#{blob_name}.vhd")
15
11
  rescue Azure::Core::Http::HTTPError => e
16
12
  raise_azure_exception(e, msg)
17
13
  end
@@ -26,9 +22,9 @@ module Fog
26
22
  end
27
23
  # This class provides the mock implementation for unit tests.
28
24
  class Mock
29
- def delete_disk(_resource_group, _storage_account_name, blob_name)
30
- Fog::Logger.debug "Deleting Disk: #{blob_name}."
31
- Fog::Logger.debug "Successfully deleted Disk: #{blob_name}."
25
+ def delete_disk(*)
26
+ Fog::Logger.debug 'Deleting Disk: test_blob.'
27
+ Fog::Logger.debug 'Successfully deleted Disk: test_blob.'
32
28
  true
33
29
  end
34
30
  end
@@ -0,0 +1,35 @@
1
+ module Fog
2
+ module Storage
3
+ class AzureRM
4
+ # Real class for Recovery Vault request
5
+ class Real
6
+ def delete_recovery_vault(resource_group, name)
7
+ msg = "Deleting Recovery Vault #{name} from Resource Group #{resource_group}"
8
+ Fog::Logger.debug msg
9
+ resource_url = "#{AZURE_RESOURCE}/subscriptions/#{@subscription_id}/resourceGroups/#{resource_group}/providers/Microsoft.RecoveryServices/vaults/#{name}?api-version=2016-05-01"
10
+ begin
11
+ token = Fog::Credentials::AzureRM.get_token(@tenant_id, @client_id, @client_secret)
12
+ RestClient.delete(
13
+ resource_url,
14
+ accept: 'application/json',
15
+ content_type: 'application/json',
16
+ authorization: token
17
+ )
18
+ rescue RestClient::Exception => e
19
+ raise_azure_exception(e, msg)
20
+ end
21
+ Fog::Logger.debug "Recovery Vault #{name} in Resource Group #{resource_group} deleted successfully"
22
+ true
23
+ end
24
+ end
25
+
26
+ # Mock class for Recovery Vault request
27
+ class Mock
28
+ def delete_recovery_vault(*)
29
+ Fog::Logger.debug 'Recovery Vault TestVault in Resource Group TestRG deleted successfully'
30
+ true
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,60 @@
1
+ PROTECTION_STOPPED = 'ProtectionStopped'.freeze
2
+
3
+ module Fog
4
+ module Storage
5
+ class AzureRM
6
+ # Real class for Recovery Vault request
7
+ class Real
8
+ def disable_backup_protection(rv_name, rv_resource_group, vm_name, vm_resource_group)
9
+ msg = "Disabling protection for VM #{vm_name} in Recovery Vault #{rv_name}"
10
+ Fog::Logger.debug msg
11
+
12
+ set_recovery_vault_context(rv_resource_group, rv_name)
13
+ vm_id = get_virtual_machine_id(vm_resource_group, vm_name)
14
+
15
+ resource_url = "#{AZURE_RESOURCE}/subscriptions/#{@subscription_id}/resourceGroups/#{rv_resource_group}/providers/Microsoft.RecoveryServices/vaults/#{rv_name}/backupFabrics/Azure/protectionContainers/iaasvmcontainer;iaasvmcontainerv2;#{vm_resource_group.downcase};#{vm_name.downcase}/protectedItems/vm;iaasvmcontainerv2;#{vm_resource_group.downcase};#{vm_name.downcase}?api-version=2016-05-01"
16
+ body = {
17
+ properties: {
18
+ protectedItemType: 'Microsoft.Compute/virtualMachines',
19
+ policyId: '',
20
+ sourceResourceId: vm_id,
21
+ protectionState: PROTECTION_STOPPED
22
+ },
23
+ tags: {}
24
+ }
25
+
26
+ begin
27
+ token = Fog::Credentials::AzureRM.get_token(@tenant_id, @client_id, @client_secret)
28
+ RestClient.put(
29
+ resource_url,
30
+ body.to_json,
31
+ accept: 'application/json',
32
+ content_type: 'application/json',
33
+ authorization: token
34
+ )
35
+ rescue RestClient::Exception => e
36
+ raise_azure_exception(e, msg)
37
+ end
38
+
39
+ Fog::Logger.debug "Successfully disabled protection for VM #{vm_name} in Recovery Vault #{rv_name}"
40
+ true
41
+ end
42
+
43
+ private
44
+
45
+ def get_virtual_machine_id(vm_resource_group, vm_name)
46
+ compute_service = Fog::Compute::AzureRM.new(tenant_id: @tenant_id, client_id: @client_id, client_secret: @client_secret, subscription_id: @subscription_id)
47
+ compute_service.get_virtual_machine(vm_resource_group, vm_name).id
48
+ end
49
+ end
50
+
51
+ # Mock class for Recovery Vault request
52
+ class Mock
53
+ def disable_backup_protection(*)
54
+ Fog::Logger.debug 'Successfully disabled protection for VM {vm_name} in Recovery Vault {rv_name}'
55
+ true
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,61 @@
1
+ CONFIGURE_BACKUP = 'ConfigureBackup'.freeze
2
+
3
+ module Fog
4
+ module Storage
5
+ class AzureRM
6
+ # Real class for Recovery Vault request
7
+ class Real
8
+ def enable_backup_protection(rv_name, rv_resource_group, vm_name, vm_resource_group)
9
+ msg = "Enabling backup protection for VM #{vm_name} in Resource Group #{vm_resource_group}"
10
+ Fog::Logger.debug msg
11
+
12
+ set_recovery_vault_context(rv_resource_group, rv_name)
13
+ backup_protection_policy = get_backup_protection_policy(rv_resource_group, rv_name)
14
+ policy = backup_protection_policy.select { |item| item['name'].eql? 'DefaultPolicy' }[0]
15
+ vm_id = get_virtual_machine_id(vm_resource_group, vm_name)
16
+
17
+ resource_url = "#{AZURE_RESOURCE}/subscriptions/#{@subscription_id}/resourceGroups/#{rv_resource_group}/providers/Microsoft.RecoveryServices/vaults/#{rv_name}/backupFabrics/Azure/protectionContainers/iaasvmcontainer;iaasvmcontainerv2;#{vm_resource_group.downcase};#{vm_name.downcase}/protectedItems/vm;iaasvmcontainerv2;#{vm_resource_group.downcase};#{vm_name.downcase}?api-version=2016-05-01"
18
+ body = {
19
+ properties: {
20
+ protectedItemType: 'Microsoft.Compute/virtualMachines',
21
+ policyId: policy['id'],
22
+ sourceResourceId: vm_id
23
+ },
24
+ tags: {}
25
+ }
26
+
27
+ begin
28
+ token = Fog::Credentials::AzureRM.get_token(@tenant_id, @client_id, @client_secret)
29
+ RestClient.put(
30
+ resource_url,
31
+ body.to_json,
32
+ accept: 'application/json',
33
+ content_type: 'application/json',
34
+ authorization: token
35
+ )
36
+ rescue RestClient::Exception => e
37
+ raise_azure_exception(e, msg)
38
+ end
39
+
40
+ @job = get_backup_job_for_vm(rv_name, rv_resource_group, vm_name, vm_resource_group, CONFIGURE_BACKUP)
41
+
42
+ until @job.nil?
43
+ sleep 10
44
+ @job = get_backup_job_for_vm(rv_name, rv_resource_group, vm_name, vm_resource_group, CONFIGURE_BACKUP)
45
+ end
46
+
47
+ Fog::Logger.debug "Successfully enabled backup protection for VM #{vm_name} in Resource Group #{vm_resource_group}"
48
+ true
49
+ end
50
+ end
51
+
52
+ # Mock class for Recovery Vault request
53
+ class Mock
54
+ def enable_backup_protection(*)
55
+ Fog::Logger.debug 'Successfully enabled backup protection for VM {vm_name} in Resource Group {vm_resource_group}'
56
+ true
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,56 @@
1
+ module Fog
2
+ module Storage
3
+ class AzureRM
4
+ # Real class for Recovery Vault request
5
+ class Real
6
+ def get_all_backup_jobs(rv_name, rv_resource_group)
7
+ msg = "Getting all backup jobs for Recovery Vault #{rv_name}"
8
+ Fog::Logger.debug msg
9
+
10
+ resource_url = "#{AZURE_RESOURCE}/subscriptions/#{@subscription_id}/resourceGroups/#{rv_resource_group}/providers/Microsoft.RecoveryServices/vaults/#{rv_name}/backupJobs?api-version=2016-05-01&$filter=status eq 'InProgress'"
11
+ begin
12
+ token = Fog::Credentials::AzureRM.get_token(@tenant_id, @client_id, @client_secret)
13
+ response = RestClient.get(
14
+ resource_url,
15
+ accept: 'application/json',
16
+ content_type: 'application/json',
17
+ authorization: token
18
+ )
19
+ rescue RestClient::Exception => e
20
+ raise_azure_exception(e, msg)
21
+ end
22
+ Fog::Logger.debug "Successfully retrieved backup jobs for Recovery Vault #{rv_name}"
23
+ JSON.parse(response)['value']
24
+ end
25
+ end
26
+
27
+ # Mock class for Recovery Vault request
28
+ class Mock
29
+ def get_all_backup_jobs(*)
30
+ body = '{
31
+ "value": [{
32
+ "id": "/subscriptions/########-####-####-####-############/resourceGroups/fog-test-rg/providers/Microsoft.RecoveryServices/vaults/fog-test-vault/backupJobs/########-####-####-####-############",
33
+ "name": "########-####-####-####-############",
34
+ "type": "Microsoft.RecoveryServices/vaults/backupJobs",
35
+ "properties": {
36
+ "jobType": "AzureIaaSVMJob",
37
+ "duration": "XX:XX:XX.XXXXXXX",
38
+ "actionsInfo": [
39
+ 1
40
+ ],
41
+ "virtualMachineVersion": "Compute",
42
+ "entityFriendlyName": "fog-test-vm",
43
+ "backupManagementType": "AzureIaasVM",
44
+ "operation": "Backup",
45
+ "status": "InProgress",
46
+ "startTime": "2016-10-19T07:49:31.1466534Z",
47
+ "activityId": "########-####-####-####-############"
48
+ }
49
+ }]
50
+ }'
51
+ JSON.parse(body)['value']
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end