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
@@ -0,0 +1,53 @@
1
+ module Fog
2
+ module Storage
3
+ class AzureRM
4
+ # Real class for Recovery Vault request
5
+ class Real
6
+ def get_backup_container(resource_group, rv_name, vm_name)
7
+ msg = "Getting backup container from Recovery Vault #{rv_name}"
8
+ Fog::Logger.debug msg
9
+
10
+ resource_url = "#{AZURE_RESOURCE}/subscriptions/#{@subscription_id}/resourceGroups/#{resource_group}/providers/Microsoft.RecoveryServices/vaults/#{rv_name}/backupProtectionContainers?api-version=2016-05-01&$filter=backupManagementType eq 'AzureIaasVM' and status eq 'Registered' and friendlyName eq '#{vm_name}'"
11
+ begin
12
+ token = Fog::Credentials::AzureRM.get_token(@tenant_id, @client_id, @client_secret)
13
+ response = RestClient.get(
14
+ response = 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 container from 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_backup_container(*)
30
+ body = '{
31
+ "value": [{
32
+ "id": "/subscriptions/########-####-####-####-############/resourceGroups/fog-test-rg/providers/Microsoft.RecoveryServices/vaults/fog-test-vault/backupFabrics/Azure/protectionContainers/IaasVMContainer;iaasvmcontainerv2;fog-test-vm-rg;fog-test-vm",
33
+ "name": "IaasVMContainer;iaasvmcontainerv2;fog-test-vm-rg;fog-test-vm",
34
+ "type": "Microsoft.RecoveryServices/vaults/backupFabrics/protectionContainers",
35
+ "properties": {
36
+ "virtualMachineId": "/subscriptions/########-####-####-####-############/resourceGroups/TestRG/providers/Microsoft.Compute/virtualMachines/TestVM",
37
+ "virtualMachineVersion": "Compute",
38
+ "resourceGroup": "fog-test-vm-rg",
39
+ "friendlyName": "fog-test-vm",
40
+ "backupManagementType": "AzureIaasVM",
41
+ "registrationStatus": "Registered",
42
+ "healthStatus": "Healthy",
43
+ "containerType": "Microsoft.Compute/virtualMachines",
44
+ "protectableObjectType": "Microsoft.Compute/virtualMachines"
45
+ }
46
+ }]
47
+ }'
48
+ JSON.parse(body)['value']
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,58 @@
1
+ module Fog
2
+ module Storage
3
+ class AzureRM
4
+ # Real class for Recovery Vault request
5
+ class Real
6
+ def get_backup_item(resource_group, rv_name)
7
+ msg = "Getting backup item from Recovery Vault #{rv_name}"
8
+ Fog::Logger.debug msg
9
+
10
+ resource_url = "#{AZURE_RESOURCE}/subscriptions/#{@subscription_id}/resourceGroups/#{resource_group}/providers/Microsoft.RecoveryServices/vaults/#{rv_name}/backupProtectedItems?api-version=2016-05-01&$filter=backupManagementType eq 'AzureIaasVM' and itemType eq 'VM'"
11
+ begin
12
+ token = Fog::Credentials::AzureRM.get_token(@tenant_id, @client_id, @client_secret)
13
+ response = RestClient.get(
14
+ response = 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 item from 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_backup_item(*)
30
+ body = '{
31
+ "value": [{
32
+ "id": "/Subscriptions/########-####-####-####-############/resourceGroups/fog-test-rg/providers/Microsoft.RecoveryServices/vaults/fog-test-vault/backupFabrics/Azure/protectionContainers/IaasVMContainer;iaasvmcontainerv2;testrg;testvm/protectedItems/VM;fog-test-container-name",
33
+ "name": "iaasvmcontainerv2;fog-test-vm-rg;fog-test-vm",
34
+ "type": "Microsoft.RecoveryServices/vaults/backupFabrics/protectionContainers/protectedItems",
35
+ "properties": {
36
+ "friendlyName": "fog-test-vm",
37
+ "virtualMachineId": "/subscriptions/########-####-####-####-############/resourceGroups/fog-test-vm-rg/providers/Microsoft.Compute/virtualMachines/fog-test-vm",
38
+ "protectionStatus": "Healthy",
39
+ "protectionState": "Protected",
40
+ "lastBackupStatus": "Completed",
41
+ "lastBackupTime": "2016-10-17T10:30:47.2289274Z",
42
+ "protectedItemType": "Microsoft.Compute/virtualMachines",
43
+ "backupManagementType": "AzureIaasVM",
44
+ "workloadType": "VM",
45
+ "containerName": "iaasvmcontainerv2;fog-test-vm-rg;fog-test-vm",
46
+ "sourceResourceId": "/subscriptions/########-####-####-####-############/resourceGroups/fog-test-vm-rg/providers/Microsoft.Compute/virtualMachines/fog-test-vm",
47
+ "policyId": "/subscriptions/########-####-####-####-############/resourceGroups/fog-test-rg/providers/Microsoft.RecoveryServices/vaults/fog-test-vault/backupPolicies/DefaultPolicy",
48
+ "policyName": "DefaultPolicy",
49
+ "lastRecoveryPoint": "2016-10-17T10:32:38.4666692Z"
50
+ }
51
+ }]
52
+ }'
53
+ JSON.parse(body)['value']
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,53 @@
1
+ module Fog
2
+ module Storage
3
+ class AzureRM
4
+ # Real class for Recovery Vault request
5
+ class Real
6
+ def get_backup_job_for_vm(rv_name, rv_resource_group, vm_name, vm_resource_group, operation)
7
+ msg = "Getting backup job for VM #{vm_name} in Resource Group #{vm_resource_group}"
8
+ Fog::Logger.debug msg
9
+
10
+ backup_jobs = get_all_backup_jobs(rv_name, rv_resource_group)
11
+ backup_jobs = backup_jobs.select do |job|
12
+ (job['properties']['status'].eql? 'InProgress') &&
13
+ (job['properties']['entityFriendlyName'].eql? vm_name.downcase) &&
14
+ (job['properties']['operation'].eql? operation)
15
+ end
16
+
17
+ backup_jobs[0]
18
+ end
19
+ end
20
+
21
+ # Mock class for Recovery Vault request
22
+ class Mock
23
+ def get_backup_job_for_vm(*)
24
+ body = '{
25
+ "id": "/subscriptions/########-####-####-####-############/resourceGroups/fog-test-rg/providers/Microsoft.RecoveryServices/vaults/fog-test-vault/backupJobs/########-####-####-####-############",
26
+ "name": "########-####-####-####-############",
27
+ "type": "Microsoft.RecoveryServices/vaults/backupJobs",
28
+ "properties": {
29
+ "jobType": "AzureIaaSVMJob",
30
+ "duration": "00:00:52.3309441",
31
+ "virtualMachineVersion": "Compute",
32
+ "extendedInfo": {
33
+ "tasksList": [],
34
+ "propertyBag": {
35
+ "VM Name": "fog-test-vm",
36
+ "Policy Name": "DefaultPolicy"
37
+ }
38
+ },
39
+ "entityFriendlyName": "fog-test-vm",
40
+ "backupManagementType": "AzureIaasVM",
41
+ "operation": "ConfigureBackup",
42
+ "status": "Completed",
43
+ "startTime": "2016-10-13T09:55:49.1168243Z",
44
+ "endTime": "2016-10-13T09:56:41.4477684Z",
45
+ "activityId": "383f05d9-a4bf-4b95-bb41-d39849b3a86e-2016-10-13 09:55:53Z-PS"
46
+ }
47
+ }'
48
+ JSON.parse(body)
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,64 @@
1
+ module Fog
2
+ module Storage
3
+ class AzureRM
4
+ # Real class for Recovery Vault request
5
+ class Real
6
+ def get_backup_protection_policy(resource_group, name)
7
+ msg = "Get backup protection policy from 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}/backupPolicies?api-version=2016-05-01&$filter=backupManagementType eq 'AzureIaasVM'"
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 protection policy from Resource Group #{resource_group}"
23
+ JSON.parse(response)['value']
24
+ end
25
+ end
26
+
27
+ # Mock class for Recovery Vault request
28
+ class Mock
29
+ body = '{
30
+ "value": [{
31
+ "id": "/subscriptions/########-####-####-####-############/resourceGroups/fog-test-rg/providers/Microsoft.RecoveryServices/vaults/fog-test-vault/backupPolicies/DefaultPolicy",
32
+ "name": "DefaultPolicy",
33
+ "type": "Microsoft.RecoveryServices/vaults/backupPolicies",
34
+ "properties": {
35
+ "backupManagementType": "AzureIaasVM",
36
+ "schedulePolicy": {
37
+ "schedulePolicyType": "SimpleSchedulePolicy",
38
+ "scheduleRunFrequency": "Daily",
39
+ "scheduleRunTimes": [
40
+ "2016-10-13T19:30:00Z"
41
+ ],
42
+ "scheduleWeeklyFrequency": 0
43
+ },
44
+ "retentionPolicy": {
45
+ "retentionPolicyType": "LongTermRetentionPolicy",
46
+ "dailySchedule": {
47
+ "retentionTimes": [
48
+ "2016-10-13T19:30:00Z"
49
+ ],
50
+ "retentionDuration": {
51
+ "count": 30,
52
+ "durationType": "Days"
53
+ }
54
+ }
55
+ },
56
+ "protectedItemsCount": 0
57
+ }
58
+ }]
59
+ }'
60
+ JSON.parse(body)['value']
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,49 @@
1
+ module Fog
2
+ module Storage
3
+ class AzureRM
4
+ # Real class for Recovery Vault request
5
+ class Real
6
+ def get_recovery_vault(resource_group, name)
7
+ msg = "Retrieving 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?api-version=2016-05-01"
10
+ begin
11
+ token = Fog::Credentials::AzureRM.get_token(@tenant_id, @client_id, @client_secret)
12
+ recovery_vault_response = RestClient.get(
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} from Resource Group #{resource_group} retrieved successfully"
22
+ recovery_vault = JSON.parse(recovery_vault_response)['value']
23
+ recovery_vault.select { |vault| vault['name'].eql? name }[0]
24
+ end
25
+ end
26
+
27
+ # Mock class for Recovery Vault request
28
+ class Mock
29
+ def get_recovery_vault(*)
30
+ body = '{
31
+ "value": [{
32
+ "location": "westus",
33
+ "name": "fog-test-vault",
34
+ "properties": {
35
+ "provisioningState": "Succeeded"
36
+ },
37
+ "id": "/subscriptions/########-####-####-####-############/resourceGroups/fog-test-rg/providers/Microsoft.RecoveryServices/vaults/fog-test-vault",
38
+ "type": "Microsoft.RecoveryServices/vaults",
39
+ "sku": {
40
+ "name": "standard"
41
+ }
42
+ }]
43
+ }'
44
+ JSON.parse(body)['value'][0]
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,48 @@
1
+ module Fog
2
+ module Storage
3
+ class AzureRM
4
+ # Real class for Recovery Vault request
5
+ class Real
6
+ def list_recovery_vaults(resource_group)
7
+ msg = "Listing Recovery Vaults in Resource Group #{resource_group}"
8
+ Fog::Logger.debug msg
9
+ resource_url = "#{AZURE_RESOURCE}/subscriptions/#{@subscription_id}/resourceGroups/#{resource_group}/providers/Microsoft.RecoveryServices/vaults?api-version=2016-05-01"
10
+ begin
11
+ token = Fog::Credentials::AzureRM.get_token(@tenant_id, @client_id, @client_secret)
12
+ recovery_vaults_response = RestClient.get(
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 Vaults in Resource Group #{resource_group} listed successfully"
22
+ JSON.parse(recovery_vaults_response)['value']
23
+ end
24
+ end
25
+
26
+ # Mock class for Recovery Vault Request
27
+ class Mock
28
+ def list_recovery_vaults(*)
29
+ body = '{
30
+ "value": [{
31
+ "location": "westus",
32
+ "name": "fog-test-vault",
33
+ "properties": {
34
+ "provisioningState": "Succeeded"
35
+ },
36
+ "id": "/subscriptions/########-####-####-####-############/resourceGroups/fog-test-rg/providers/Microsoft.RecoveryServices/vaults/fog-test-vault",
37
+ "type": "Microsoft.RecoveryServices/vaults",
38
+ "sku": {
39
+ "name": "standard"
40
+ }
41
+ }]
42
+ }'
43
+ JSON.parse(body)['value']
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,36 @@
1
+ module Fog
2
+ module Storage
3
+ class AzureRM
4
+ # Real class for Recovery Vault request
5
+ class Real
6
+ def set_recovery_vault_context(resource_group, name)
7
+ msg = "Set context for Recovery Vault #{name}"
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
+ begin
12
+ token = Fog::Credentials::AzureRM.get_token(@tenant_id, @client_id, @client_secret)
13
+ 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 set context for Recovery Vault #{name}"
23
+ true
24
+ end
25
+ end
26
+
27
+ # Mock class for Recovery Vault request
28
+ class Mock
29
+ def set_recovery_vault_context(*)
30
+ Fog::Logger.debug 'Successfully set context for Recovery Vault {name}'
31
+ true
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,54 @@
1
+ IAAS_VM_BACKUP_REQUEST = 'IaasVMBackupRequest'.freeze
2
+
3
+ module Fog
4
+ module Storage
5
+ class AzureRM
6
+ # Real class for Recovery Vault request
7
+ class Real
8
+ def start_backup(resource_group, name, vm_name, vm_resource_group)
9
+ msg = "Starting backup for VM #{vm_name}"
10
+ Fog::Logger.debug msg
11
+
12
+ job = get_backup_job_for_vm(name, resource_group, vm_name, vm_resource_group, 'Backup')
13
+
14
+ unless job.nil?
15
+ Fog::Logger.debug "Backup already in progress for VM #{vm_name} in Recovery Vault #{name}"
16
+ return false
17
+ end
18
+
19
+ backup_items = get_backup_item(resource_group, name, vm_name)
20
+ backup_item = backup_items.select { |item| (item['properties']['friendlyName'].eql? vm_name.downcase) && (vm_resource_group.eql? get_resource_group_from_id(item['properties']['virtualMachineId'])) }[0]
21
+
22
+ resource_url = "#{AZURE_RESOURCE}/subscriptions/#{@subscription_id}/resourceGroups/#{resource_group}/providers/Microsoft.RecoveryServices/vaults/#{name}/backupFabrics/Azure/protectionContainers/iaasvmcontainer;#{backup_item['name']}/protectedItems/vm;#{backup_item['name']}/backup?api-version=2016-05-01"
23
+ body = {
24
+ properties: {
25
+ objectType: IAAS_VM_BACKUP_REQUEST
26
+ }
27
+ }
28
+ begin
29
+ token = Fog::Credentials::AzureRM.get_token(@tenant_id, @client_id, @client_secret)
30
+ RestClient.post(
31
+ resource_url,
32
+ body.to_json,
33
+ accept: 'application/json',
34
+ content_type: 'application/json',
35
+ authorization: token
36
+ )
37
+ rescue RestClient::Exception => e
38
+ raise_azure_exception(e, msg)
39
+ end
40
+ Fog::Logger.debug "Successfully started backup for VM #{vm_name} in Recovery Vault #{name}"
41
+ true
42
+ end
43
+ end
44
+
45
+ # Mock class for Recovery Vault request
46
+ class Mock
47
+ def start_backup(*)
48
+ Fog::Logger.debug 'Successfully started backup for VM {vm_name} in Recovery Vault {name}'
49
+ true
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,59 @@
1
+ module Fog
2
+ module Storage
3
+ class AzureRM
4
+ # This class provides the actual implementation for service calls.
5
+ class Real
6
+ def update_storage_account(storage_account_hash)
7
+ msg = "Updating Storage Account: #{storage_account_hash[:name]} in Resource Group #{storage_account_hash[:resource_group]}."
8
+ Fog::Logger.debug msg
9
+ storage_account_params = get_storage_account_update_params(storage_account_hash)
10
+ begin
11
+ storage_account = @storage_mgmt_client.storage_accounts.update(storage_account_hash[:resource_group],
12
+ storage_account_hash[:name],
13
+ storage_account_params)
14
+ rescue MsRestAzure::AzureOperationError => e
15
+ raise_azure_exception(e, msg)
16
+ end
17
+ Fog::Logger.debug 'Storage Account updated successfully.'
18
+ storage_account
19
+ end
20
+
21
+ private
22
+
23
+ def get_storage_account_update_params(storage_account_hash)
24
+ params = Azure::ARM::Storage::Models::StorageAccountUpdateParameters.new
25
+ sku = Azure::ARM::Storage::Models::Sku.new
26
+ sku.name = "#{storage_account_hash[:sku_name]}_#{storage_account_hash[:replication]}"
27
+ params.sku = sku
28
+ unless storage_account_hash[:encryption].nil?
29
+ encryption = Azure::ARM::Storage::Models::Encryption.new
30
+ encryption_services = Azure::ARM::Storage::Models::EncryptionServices.new
31
+ encryption_service = Azure::ARM::Storage::Models::EncryptionService.new
32
+ encryption_service.enabled = storage_account_hash[:encryption]
33
+ encryption_service.last_enabled_time = Time.new if encryption_service.enabled
34
+ encryption_services.blob = encryption_service
35
+ encryption.services = encryption_services
36
+ params.encryption = encryption
37
+ end
38
+ params
39
+ end
40
+ end
41
+ # This class provides the mock implementation for unit tests.
42
+ class Mock
43
+ def update_storage_account(*)
44
+ storage_account_hash = {
45
+ 'id' => '/subscriptions/67f2116d-4ea2-4c6c-b20a-f92183dbe3cb/resourceGroups/fog_test_rg/providers/Microsoft.Storage/storageAccounts/fogtestsasecond',
46
+ 'name' => 'fog-test-storage-account',
47
+ 'location' => 'west us',
48
+ 'sku' =>
49
+ {
50
+ 'name' => 'Standard_LRS'
51
+ }
52
+ }
53
+ storage_account_mapper = Azure::ARM::Storage::Models::StorageAccount.mapper
54
+ storage_mgmt_client.deserialize(storage_account_mapper, storage_account_hash, 'hash')
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end