fog-azure-rm-temp 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.arclint +8 -0
- data/.travis.yml +28 -14
- data/CHANGELOG.md +77 -0
- data/CONTRIBUTORS.md +4 -0
- data/fog-azure-rm.gemspec +3 -2
- data/lib/fog/azurerm.rb +1 -0
- data/lib/fog/azurerm/async_response.rb +9 -1
- data/lib/fog/azurerm/compute.rb +3 -1
- data/lib/fog/azurerm/constants.rb +11 -3
- data/lib/fog/azurerm/dns.rb +3 -1
- data/lib/fog/azurerm/docs/application_gateway.md +119 -117
- data/lib/fog/azurerm/docs/compute.md +299 -202
- data/lib/fog/azurerm/docs/dns.md +44 -43
- data/lib/fog/azurerm/docs/key_vault.md +31 -28
- data/lib/fog/azurerm/docs/network.md +407 -404
- data/lib/fog/azurerm/docs/resources.md +52 -49
- data/lib/fog/azurerm/docs/sql.md +56 -54
- data/lib/fog/azurerm/docs/storage.md +92 -157
- data/lib/fog/azurerm/docs/traffic_manager.md +55 -53
- data/lib/fog/azurerm/models/application_gateway/gateway.rb +5 -1
- data/lib/fog/azurerm/models/compute/availability_set.rb +4 -1
- data/lib/fog/azurerm/models/compute/managed_disk.rb +0 -1
- data/lib/fog/azurerm/models/compute/server.rb +61 -11
- data/lib/fog/azurerm/models/compute/servers.rb +2 -2
- data/lib/fog/azurerm/models/dns/a_record.rb +15 -0
- data/lib/fog/azurerm/models/dns/cname_record.rb +15 -0
- data/lib/fog/azurerm/models/dns/record_set.rb +20 -8
- data/lib/fog/azurerm/models/key_vault/vault.rb +3 -1
- data/lib/fog/azurerm/models/network/load_balancer.rb +3 -1
- data/lib/fog/azurerm/models/network/local_network_gateway.rb +3 -1
- data/lib/fog/azurerm/models/network/network_interface.rb +3 -1
- data/lib/fog/azurerm/models/network/network_security_group.rb +4 -2
- data/lib/fog/azurerm/models/network/public_ip.rb +4 -2
- data/lib/fog/azurerm/models/network/virtual_network.rb +4 -2
- data/lib/fog/azurerm/models/resources/resource_group.rb +3 -1
- data/lib/fog/azurerm/models/sql/sql_database.rb +3 -3
- data/lib/fog/azurerm/models/sql/sql_server.rb +3 -2
- data/lib/fog/azurerm/models/storage/directories.rb +6 -1
- data/lib/fog/azurerm/models/storage/file.rb +2 -0
- data/lib/fog/azurerm/models/storage/storage_account.rb +4 -1
- data/lib/fog/azurerm/models/storage/storage_accounts.rb +7 -0
- data/lib/fog/azurerm/models/traffic_manager/traffic_manager_profile.rb +3 -1
- data/lib/fog/azurerm/requests/application_gateway/check_ag_exists.rb +1 -1
- data/lib/fog/azurerm/requests/application_gateway/create_or_update_application_gateway.rb +1 -0
- data/lib/fog/azurerm/requests/compute/attach_data_disk_to_vm.rb +2 -2
- data/lib/fog/azurerm/requests/compute/check_availability_set_exists.rb +1 -1
- data/lib/fog/azurerm/requests/compute/check_managed_disk_exists.rb +1 -1
- data/lib/fog/azurerm/requests/compute/check_vm_exists.rb +1 -1
- data/lib/fog/azurerm/requests/compute/check_vm_extension_exists.rb +2 -2
- data/lib/fog/azurerm/requests/compute/create_availability_set.rb +4 -2
- data/lib/fog/azurerm/requests/compute/create_image.rb +68 -0
- data/lib/fog/azurerm/requests/compute/create_virtual_machine.rb +302 -135
- data/lib/fog/azurerm/requests/compute/delete_image.rb +29 -0
- data/lib/fog/azurerm/requests/compute/get_image.rb +45 -0
- data/lib/fog/azurerm/requests/compute/get_virtual_machine.rb +4 -2
- data/lib/fog/azurerm/requests/dns/check_record_set_exists.rb +1 -1
- data/lib/fog/azurerm/requests/dns/check_zone_exists.rb +3 -2
- data/lib/fog/azurerm/requests/dns/create_or_update_record_set.rb +3 -2
- data/lib/fog/azurerm/requests/dns/create_or_update_zone.rb +1 -2
- data/lib/fog/azurerm/requests/key_vault/check_vault_exists.rb +1 -1
- data/lib/fog/azurerm/requests/key_vault/create_or_update_vault.rb +1 -0
- data/lib/fog/azurerm/requests/network/check_express_route_cir_auth_exists.rb +1 -1
- data/lib/fog/azurerm/requests/network/check_express_route_circuit_exists.rb +1 -1
- data/lib/fog/azurerm/requests/network/check_load_balancer_exists.rb +1 -1
- data/lib/fog/azurerm/requests/network/check_local_net_gateway_exists.rb +1 -1
- data/lib/fog/azurerm/requests/network/check_net_sec_group_exists.rb +1 -1
- data/lib/fog/azurerm/requests/network/check_net_sec_rule_exists.rb +1 -1
- data/lib/fog/azurerm/requests/network/check_network_interface_exists.rb +1 -1
- data/lib/fog/azurerm/requests/network/check_public_ip_exists.rb +1 -1
- data/lib/fog/azurerm/requests/network/check_subnet_exists.rb +1 -1
- data/lib/fog/azurerm/requests/network/check_virtual_network_exists.rb +1 -1
- data/lib/fog/azurerm/requests/network/check_vnet_gateway_connection_exists.rb +1 -1
- data/lib/fog/azurerm/requests/network/check_vnet_gateway_exists.rb +1 -1
- data/lib/fog/azurerm/requests/network/create_load_balancer.rb +4 -4
- data/lib/fog/azurerm/requests/network/create_or_update_express_route_circuit.rb +1 -1
- data/lib/fog/azurerm/requests/network/create_or_update_local_network_gateway.rb +1 -2
- data/lib/fog/azurerm/requests/network/create_or_update_network_interface.rb +4 -3
- data/lib/fog/azurerm/requests/network/create_or_update_network_security_group.rb +4 -3
- data/lib/fog/azurerm/requests/network/create_or_update_public_ip.rb +5 -3
- data/lib/fog/azurerm/requests/network/create_or_update_virtual_network.rb +4 -3
- data/lib/fog/azurerm/requests/network/create_or_update_virtual_network_gateway_connection.rb +1 -1
- data/lib/fog/azurerm/requests/resources/check_azure_resource_exists.rb +4 -4
- data/lib/fog/azurerm/requests/resources/create_resource_group.rb +2 -1
- data/lib/fog/azurerm/requests/resources/delete_resource_tag.rb +4 -4
- data/lib/fog/azurerm/requests/resources/tag_resource.rb +4 -4
- data/lib/fog/azurerm/requests/sql/create_or_update_database.rb +13 -10
- data/lib/fog/azurerm/requests/sql/create_or_update_sql_server.rb +8 -5
- data/lib/fog/azurerm/requests/storage/check_storage_account_exists.rb +1 -1
- data/lib/fog/azurerm/requests/storage/create_storage_account.rb +4 -2
- data/lib/fog/azurerm/requests/traffic_manager/check_traffic_manager_endpoint_exists.rb +1 -1
- data/lib/fog/azurerm/requests/traffic_manager/check_traffic_manager_profile_exists.rb +1 -1
- data/lib/fog/azurerm/requests/traffic_manager/create_or_update_traffic_manager_profile.rb +13 -3
- data/lib/fog/azurerm/storage.rb +0 -18
- data/lib/fog/azurerm/utilities/general.rb +21 -10
- data/lib/fog/azurerm/version.rb +1 -1
- data/rake-script.sh +7 -1
- data/rakefile +1 -1
- data/test/api_stub.rb +19 -2
- data/test/api_stub/models/compute/server.rb +21 -5
- data/test/api_stub/requests/compute/image.rb +41 -0
- data/test/api_stub/requests/compute/virtual_machine.rb +60 -62
- data/test/api_stub/requests/resources/resource_group.rb +1 -1
- data/test/integration/application_gateway.rb +8 -1
- data/test/integration/availability_set.rb +9 -2
- data/test/integration/external_load_balancer.rb +2 -1
- data/test/integration/internal_load_balancer.rb +2 -1
- data/test/integration/key_vault.rb +2 -1
- data/test/integration/managed_disk.rb +10 -5
- data/test/integration/network_interface.rb +2 -1
- data/test/integration/network_security_group.rb +2 -1
- data/test/integration/public_ip.rb +2 -1
- data/test/integration/record_set.rb +5 -5
- data/test/integration/resource_group.rb +5 -2
- data/test/integration/resource_tag.rb +4 -2
- data/test/integration/server.rb +113 -23
- data/test/integration/server_custom_image.rb +120 -20
- data/test/integration/sql_server.rb +10 -2
- data/test/integration/storage_account.rb +32 -20
- data/test/integration/traffic_manager.rb +6 -1
- data/test/integration/virtual_network.rb +2 -1
- data/test/integration/virtual_network_gateway_connection.rb +3 -3
- data/test/models/application_gateway/test_gateway.rb +2 -1
- data/test/models/compute/test_availability_set.rb +2 -1
- data/test/models/compute/test_managed_disk.rb +2 -1
- data/test/models/compute/test_server.rb +13 -4
- data/test/models/dns/test_zone.rb +2 -1
- data/test/models/key_vault/test_vault.rb +2 -1
- data/test/models/network/test_load_balancer.rb +2 -1
- data/test/models/network/test_network_interface.rb +2 -1
- data/test/models/network/test_network_security_group.rb +2 -1
- data/test/models/network/test_public_ip.rb +2 -1
- data/test/models/network/test_virtual_network.rb +2 -1
- data/test/models/resources/test_resource_group.rb +2 -1
- data/test/models/sql/test_database.rb +2 -1
- data/test/models/sql/test_sql_server.rb +2 -1
- data/test/models/storage/test_storage_account.rb +2 -1
- data/test/models/traffic_manager/test_traffic_manager_profile.rb +2 -1
- data/test/requests/application_gateway/test_check_ag_exists.rb +11 -4
- data/test/requests/compute/test_attach_data_disk_to_vm.rb +2 -2
- data/test/requests/compute/test_check_availability_set_exists.rb +9 -2
- data/test/requests/compute/test_check_managed_disk_exists.rb +9 -2
- data/test/requests/compute/test_check_vm_exists.rb +9 -2
- data/test/requests/compute/test_check_vm_extension_exists.rb +9 -2
- data/test/requests/compute/test_create_image.rb +27 -0
- data/test/requests/compute/test_create_virtual_machine.rb +41 -17
- data/test/requests/compute/test_delete_image.rb +23 -0
- data/test/requests/compute/test_get_image.rb +23 -0
- data/test/requests/dns/test_check_record_set_exists.rb +9 -2
- data/test/requests/dns/test_check_zone_exists.rb +16 -2
- data/test/requests/key_vault/test_check_vault_exists.rb +9 -2
- data/test/requests/network/test_check_express_route_cir_auth_exists.rb +9 -2
- data/test/requests/network/test_check_express_route_circuit_exists.rb +9 -2
- data/test/requests/network/test_check_load_balancer_exists.rb +9 -2
- data/test/requests/network/test_check_local_net_gateway_exists.rb +11 -4
- data/test/requests/network/test_check_net_sec_group_exists.rb +9 -2
- data/test/requests/network/test_check_net_sec_rule_exists.rb +9 -2
- data/test/requests/network/test_check_network_interface_exists.rb +9 -2
- data/test/requests/network/test_check_public_ip_exists.rb +9 -2
- data/test/requests/network/test_check_subnet_exists.rb +9 -2
- data/test/requests/network/test_check_virtual_network_exists.rb +10 -4
- data/test/requests/network/test_check_vnet_gateway_connection_exists.rb +9 -2
- data/test/requests/network/test_check_vnet_gateway_exists.rb +9 -2
- data/test/requests/network/test_create_load_balancer.rb +3 -2
- data/test/requests/network/test_create_network_interface.rb +4 -3
- data/test/requests/network/test_create_or_update_network_security_group.rb +3 -2
- data/test/requests/network/test_create_or_update_virtual_network.rb +5 -3
- data/test/requests/network/test_create_public_ip.rb +3 -2
- data/test/requests/network/test_update_public_ip.rb +3 -2
- data/test/requests/resources/test_create_resource_group.rb +3 -2
- data/test/requests/resources/test_delete_resource_tag.rb +3 -3
- data/test/requests/resources/test_tag_resource.rb +3 -3
- data/test/requests/storage/test_check_storage_account_exists.rb +8 -1
- data/test/requests/traffic_manager/test_check_traffic_manager_endpoint_exists.rb +9 -2
- data/test/requests/traffic_manager/test_check_traffic_manager_profile_exists.rb +9 -2
- data/test/test_helper.rb +5 -14
- metadata +67 -75
- data/lib/fog/azurerm/models/storage/recovery_vault.rb +0 -50
- data/lib/fog/azurerm/models/storage/recovery_vaults.rb +0 -27
- data/lib/fog/azurerm/requests/storage/create_or_update_recovery_vault.rb +0 -54
- data/lib/fog/azurerm/requests/storage/delete_recovery_vault.rb +0 -35
- data/lib/fog/azurerm/requests/storage/disable_backup_protection.rb +0 -60
- data/lib/fog/azurerm/requests/storage/enable_backup_protection.rb +0 -61
- data/lib/fog/azurerm/requests/storage/get_all_backup_jobs.rb +0 -56
- data/lib/fog/azurerm/requests/storage/get_backup_container.rb +0 -53
- data/lib/fog/azurerm/requests/storage/get_backup_item.rb +0 -58
- data/lib/fog/azurerm/requests/storage/get_backup_job_for_vm.rb +0 -53
- data/lib/fog/azurerm/requests/storage/get_backup_protection_policy.rb +0 -64
- data/lib/fog/azurerm/requests/storage/get_recovery_vault.rb +0 -49
- data/lib/fog/azurerm/requests/storage/list_recovery_vaults.rb +0 -48
- data/lib/fog/azurerm/requests/storage/set_recovery_vault_context.rb +0 -36
- data/lib/fog/azurerm/requests/storage/start_backup.rb +0 -54
- data/test/api_stub/models/storage/recovery_vault.rb +0 -23
- data/test/api_stub/requests/storage/recovery_vault.rb +0 -189
- data/test/models/storage/test_recovery_vault.rb +0 -61
- data/test/models/storage/test_recovery_vaults.rb +0 -47
- data/test/requests/storage/test_create_recovery_vault.rb +0 -35
- data/test/requests/storage/test_delete_recovery_vault.rb +0 -34
- data/test/requests/storage/test_disable_backup_protection.rb +0 -52
- data/test/requests/storage/test_enable_backup_protection.rb +0 -66
- data/test/requests/storage/test_get_all_backup_jobs.rb +0 -35
- data/test/requests/storage/test_get_backup_container.rb +0 -35
- data/test/requests/storage/test_get_backup_item.rb +0 -35
- data/test/requests/storage/test_get_backup_job_for_vm.rb +0 -26
- data/test/requests/storage/test_get_backup_protection_policy.rb +0 -35
- data/test/requests/storage/test_get_recovery_vault.rb +0 -35
- data/test/requests/storage/test_list_recovery_vault.rb +0 -35
- data/test/requests/storage/test_set_recovery_vault_context.rb +0 -34
- data/test/requests/storage/test_start_backup.rb +0 -55
@@ -1,50 +0,0 @@
|
|
1
|
-
module Fog
|
2
|
-
module Storage
|
3
|
-
class AzureRM
|
4
|
-
# This class is giving implementation of create/save and
|
5
|
-
# delete/destroy for Recovery Vault.
|
6
|
-
class RecoveryVault < Fog::Model
|
7
|
-
attribute :id
|
8
|
-
identity :name
|
9
|
-
attribute :resource_group
|
10
|
-
attribute :location
|
11
|
-
attribute :type
|
12
|
-
attribute :sku_name
|
13
|
-
|
14
|
-
def self.parse(recovery_vault)
|
15
|
-
{
|
16
|
-
id: recovery_vault['id'],
|
17
|
-
name: recovery_vault['name'],
|
18
|
-
resource_group: get_resource_group_from_id(recovery_vault['id']),
|
19
|
-
location: recovery_vault['location'],
|
20
|
-
type: recovery_vault['type'],
|
21
|
-
sku_name: recovery_vault['sku']['name']
|
22
|
-
}
|
23
|
-
end
|
24
|
-
|
25
|
-
def save
|
26
|
-
requires :name, :location, :resource_group
|
27
|
-
recovery_vault = service.create_or_update_recovery_vault(resource_group, location, name)
|
28
|
-
merge_attributes(Fog::Storage::AzureRM::RecoveryVault.parse(recovery_vault))
|
29
|
-
end
|
30
|
-
|
31
|
-
def enable_backup_protection(vm_name, vm_resource_group)
|
32
|
-
requires :name, :resource_group
|
33
|
-
service.enable_backup_protection(name, resource_group, vm_name, vm_resource_group)
|
34
|
-
end
|
35
|
-
|
36
|
-
def start_backup(vm_name, vm_resource_group)
|
37
|
-
service.start_backup(resource_group, name, vm_name, vm_resource_group)
|
38
|
-
end
|
39
|
-
|
40
|
-
def disable_backup_protection(vm_name, vm_resource_group)
|
41
|
-
service.disable_backup_protection(name, resource_group, vm_name, vm_resource_group)
|
42
|
-
end
|
43
|
-
|
44
|
-
def destroy
|
45
|
-
service.delete_recovery_vault(resource_group, name)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
module Fog
|
2
|
-
module Storage
|
3
|
-
class AzureRM
|
4
|
-
# This class is giving implementation of all/get for Recovery Vaults
|
5
|
-
class RecoveryVaults < Fog::Collection
|
6
|
-
model Fog::Storage::AzureRM::RecoveryVault
|
7
|
-
attribute :resource_group
|
8
|
-
attribute :name
|
9
|
-
|
10
|
-
def all
|
11
|
-
requires :resource_group
|
12
|
-
recovery_vaults = []
|
13
|
-
service.list_recovery_vaults(resource_group).each do |recovery_vault|
|
14
|
-
recovery_vaults << Fog::Storage::AzureRM::RecoveryVault.parse(recovery_vault)
|
15
|
-
end
|
16
|
-
load(recovery_vaults)
|
17
|
-
end
|
18
|
-
|
19
|
-
def get(resource_group, name)
|
20
|
-
recovery_vault = service.get_recovery_vault(resource_group, name)
|
21
|
-
recovery_vault_fog = Fog::Storage::AzureRM::RecoveryVault.new(service: service)
|
22
|
-
recovery_vault_fog.merge_attributes(Fog::Storage::AzureRM::RecoveryVault.parse(recovery_vault))
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,54 +0,0 @@
|
|
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=#{REST_CLIENT_API_VERSION[1]}"
|
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
|
-
Fog::JSON.decode(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
|
-
Fog::JSON.decode(recovery_vault)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
@@ -1,35 +0,0 @@
|
|
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=#{REST_CLIENT_API_VERSION[1]}"
|
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
|
@@ -1,60 +0,0 @@
|
|
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=#{REST_CLIENT_API_VERSION[1]}"
|
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
|
@@ -1,61 +0,0 @@
|
|
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=#{REST_CLIENT_API_VERSION[1]}"
|
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
|
@@ -1,56 +0,0 @@
|
|
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=#{REST_CLIENT_API_VERSION[1]}&$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
|
-
Fog::JSON.decode(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
|
-
Fog::JSON.decode(body)['value']
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
@@ -1,53 +0,0 @@
|
|
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=#{REST_CLIENT_API_VERSION[1]}&$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
|
-
Fog::JSON.decode(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
|
-
Fog::JSON.decode(body)['value']
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
@@ -1,58 +0,0 @@
|
|
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=#{REST_CLIENT_API_VERSION[1]}&$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
|
-
Fog::JSON.decode(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
|
-
Fog::JSON.decode(body)['value']
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|