diff --git a/src/bosh_azure_cpi/lib/cloud/azure/restapi/azure_client.rb b/src/bosh_azure_cpi/lib/cloud/azure/restapi/azure_client.rb index 41dcf8a14..76e52c81b 100644 --- a/src/bosh_azure_cpi/lib/cloud/azure/restapi/azure_client.rb +++ b/src/bosh_azure_cpi/lib/cloud/azure/restapi/azure_client.rb @@ -80,7 +80,6 @@ class AzureClient # rubocop:todo Metrics/ClassLength ].freeze REST_API_PROVIDER_COMPUTE = 'Microsoft.Compute' - REST_API_PROVIDER_AND_TYPE_DISK = 'Microsoft.Compute/disks' REST_API_VIRTUAL_MACHINES = 'virtualMachines' REST_API_AVAILABILITY_SETS = 'availabilitySets' REST_API_DISKS = 'disks' @@ -2372,11 +2371,14 @@ def request_from_managed_identity_endpoint def http_url(url, params = {}) unless params.key?('api-version') - resource_provider = nil - resource_provider = if url.include?(REST_API_PROVIDER_AND_TYPE_DISK) - AZURE_RESOURCE_PROVIDER_COMPUTE_DISK - elsif url.include?(REST_API_PROVIDER_COMPUTE) - AZURE_RESOURCE_PROVIDER_COMPUTE + resource_provider = if url.include?(REST_API_PROVIDER_COMPUTE) + if url.include?(REST_API_DISKS) + AZURE_RESOURCE_PROVIDER_COMPUTE_DISK + elsif url.include?(REST_API_SNAPSHOTS) + AZURE_RESOURCE_PROVIDER_COMPUTE_SNAPSHOT + else + AZURE_RESOURCE_PROVIDER_COMPUTE + end elsif url.include?(REST_API_PROVIDER_NETWORK) AZURE_RESOURCE_PROVIDER_NETWORK elsif url.include?(REST_API_PROVIDER_STORAGE) diff --git a/src/bosh_azure_cpi/lib/cloud/azure/utils/helpers.rb b/src/bosh_azure_cpi/lib/cloud/azure/utils/helpers.rb index 594b060b1..753c0b40a 100644 --- a/src/bosh_azure_cpi/lib/cloud/azure/utils/helpers.rb +++ b/src/bosh_azure_cpi/lib/cloud/azure/utils/helpers.rb @@ -4,6 +4,7 @@ module Bosh::AzureCloud module Helpers AZURE_RESOURCE_PROVIDER_COMPUTE = 'crp' AZURE_RESOURCE_PROVIDER_COMPUTE_DISK = 'diskcrp' + AZURE_RESOURCE_PROVIDER_COMPUTE_SNAPSHOT = 'snapshotcrp' AZURE_RESOURCE_PROVIDER_NETWORK = 'nrp' AZURE_RESOURCE_PROVIDER_STORAGE = 'srp' AZURE_RESOURCE_PROVIDER_GROUP = 'rp' @@ -18,6 +19,7 @@ module Helpers API_VERSIONS = { AZURE_RESOURCE_PROVIDER_COMPUTE => '2021-11-01', AZURE_RESOURCE_PROVIDER_COMPUTE_DISK => '2023-04-02', + AZURE_RESOURCE_PROVIDER_COMPUTE_SNAPSHOT => '2021-04-01', AZURE_RESOURCE_PROVIDER_NETWORK => '2017-09-01', AZURE_RESOURCE_PROVIDER_STORAGE => '2017-10-01', AZURE_RESOURCE_PROVIDER_GROUP => '2016-06-01', diff --git a/src/bosh_azure_cpi/spec/spec_helper.rb b/src/bosh_azure_cpi/spec/spec_helper.rb index f948642d4..fbc8445b8 100644 --- a/src/bosh_azure_cpi/spec/spec_helper.rb +++ b/src/bosh_azure_cpi/spec/spec_helper.rb @@ -27,16 +27,17 @@ MOCK_REQUEST_ID = '47504c59-37af-42f3-a386-22d0c2c73175' # Let us keep the least API versions here for unit tests. -AZURE_API_VERSION = '2015-06-15' -AZURE_STACK_API_VERSION = '2015-06-15' -AZURE_CHINA_API_VERSION = '2015-06-15' -AZURE_USGOV_API_VERSION = '2015-06-15' -AZURE_GERMAN_API_VERSION = '2015-06-15' -AZURE_RESOURCE_PROVIDER_COMPUTE = '2021-11-01' -AZURE_RESOURCE_PROVIDER_COMPUTE_DISK = '2023-04-02' -AZURE_RESOURCE_PROVIDER_GROUP = '2016-06-01' -AZURE_RESOURCE_PROVIDER_NETWORK = '2017-09-01' -AZURE_RESOURCE_PROVIDER_STORAGE = '2017-10-01' +AZURE_API_VERSION = '2015-06-15' +AZURE_STACK_API_VERSION = '2015-06-15' +AZURE_CHINA_API_VERSION = '2015-06-15' +AZURE_USGOV_API_VERSION = '2015-06-15' +AZURE_GERMAN_API_VERSION = '2015-06-15' +AZURE_RESOURCE_PROVIDER_COMPUTE = '2021-11-01' +AZURE_RESOURCE_PROVIDER_COMPUTE_DISK = '2023-04-02' +AZURE_RESOURCE_PROVIDER_COMPUTE_SNAPSHOT = '2021-04-01' +AZURE_RESOURCE_PROVIDER_GROUP = '2016-06-01' +AZURE_RESOURCE_PROVIDER_NETWORK = '2017-09-01' +AZURE_RESOURCE_PROVIDER_STORAGE = '2017-10-01' WINDOWS_VM_NAME_LENGTH = 15 AZURE_MAX_RETRY_COUNT = 10 diff --git a/src/bosh_azure_cpi/spec/unit/azure_client/managed_snapshots_spec.rb b/src/bosh_azure_cpi/spec/unit/azure_client/managed_snapshots_spec.rb index 6724d96dc..b02b69934 100755 --- a/src/bosh_azure_cpi/spec/unit/azure_client/managed_snapshots_spec.rb +++ b/src/bosh_azure_cpi/spec/unit/azure_client/managed_snapshots_spec.rb @@ -16,7 +16,7 @@ let(:subscription_id) { mock_azure_config.subscription_id } let(:tenant_id) { mock_azure_config.tenant_id } let(:api_version) { AZURE_API_VERSION } - let(:api_version_compute) { AZURE_RESOURCE_PROVIDER_COMPUTE } + let(:api_version_snapshot) { AZURE_RESOURCE_PROVIDER_COMPUTE_SNAPSHOT } let(:api_version_disk) { AZURE_RESOURCE_PROVIDER_COMPUTE_DISK } let(:resource_group) { 'fake-resource-group-name' } let(:request_id) { 'fake-request-id' } @@ -34,7 +34,7 @@ end describe '#create_managed_snapshot' do - let(:snapshot_uri) { "https://management.azure.com/subscriptions/#{subscription_id}/resourceGroups/#{resource_group}/providers/Microsoft.Compute/snapshots/#{snapshot_name}?api-version=#{api_version_compute}" } + let(:snapshot_uri) { "https://management.azure.com/subscriptions/#{subscription_id}/resourceGroups/#{resource_group}/providers/Microsoft.Compute/snapshots/#{snapshot_name}?api-version=#{api_version_snapshot}" } let(:disk_uri) { "https://management.azure.com/subscriptions/#{subscription_id}/resourceGroups/#{resource_group}/providers/Microsoft.Compute/disks/#{disk_name}?api-version=#{api_version_disk}" } let(:snapshot_params) do @@ -115,7 +115,7 @@ end describe '#delete_managed_snapshot' do - let(:snapshot_uri) { "https://management.azure.com/subscriptions/#{subscription_id}/resourceGroups/#{resource_group}/providers/Microsoft.Compute/snapshots/#{snapshot_name}?api-version=#{api_version_compute}" } + let(:snapshot_uri) { "https://management.azure.com/subscriptions/#{subscription_id}/resourceGroups/#{resource_group}/providers/Microsoft.Compute/snapshots/#{snapshot_name}?api-version=#{api_version_snapshot}" } context 'when token is valid, delete operation is accepted and completed' do it 'should delete the managed snapshot without error' do @@ -141,7 +141,7 @@ end describe '#get_managed_snapshot_by_name' do - let(:snapshot_uri) { "https://management.azure.com/subscriptions/#{subscription_id}/resourceGroups/#{resource_group}/providers/Microsoft.Compute/snapshots/#{snapshot_name}?api-version=#{api_version_compute}" } + let(:snapshot_uri) { "https://management.azure.com/subscriptions/#{subscription_id}/resourceGroups/#{resource_group}/providers/Microsoft.Compute/snapshots/#{snapshot_name}?api-version=#{api_version_snapshot}" } context 'when response body is null' do it 'should return nil' do