New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
400 Client Error when calling resources.check_existence/check_existence_by_id on virtual machine #2808
Comments
Hi @dharmab client.resources.check_existence_by_id(
'/subscriptions/REDACTED_GUID/resourceGroups/REDACTED/providers/Microsoft.Compute/virtualMachines/REDACTED',
'2017-12-01'
) Could you confirm? |
Ah, that makes sense! I retried using the same API version that the VM was provisioned with, and don't get the 400 error. However, I now get a 405:
A code snippet to demonstrate my usage: vm_resource_args = {
'resource_id': '/subscriptions/{}/resourceGroups/{}/providers/Microsoft.Compute/virtualMachines/{}'.format(config['Subscription'], config['ResourceGroup'], vm_name),
'api_version': azutil.resource.ApiVersion.VMSS.value
}
try:
if resource_client.resources.check_existence_by_id(**vm_resource_args):
logger.info(f'Deleting VM: {vm_name}')
poller = resource_client.resources.delete_by_id(**vm_resource_args)
__wait_for_long_azure_operation('Deletion', poller=poller)
else:
logger.info(f'Could not find etcd VM: {vm_name} (previously deleted?)')
except CloudError as e:
__log_inner_azure_errors_and_rethrow(e) |
"check existence" is implemented as HTTP HEAD, which is basically a HTTP GET without body (for performance). Not all RP supports this. def resource_exists(**vm_resource_args):
try:
return resource_client.resources.check_existence_by_id(**vm_resource_args)
except CloudError as e:
if e.status_code == 405: # HEAD not supported
try:
resource_client.resources.get_by_id(**vm_resource_args)
return True
except CloudError:
return False # Likely 404, might want to test it explicitly
raise # If not 405, not expected This should still raise for unrelated problems (connection, credentials, etc.), and return True/False if applicable. |
Adapting the In any case, the workaround is usable and I can accomplish what I initially wanted to do. Thanks! |
When calling
resources.check_existence
orresource.check_existence_by_id
on a resource of typeMicrosoft.Compute/virtualMachines
, the following exception is raised:I've tested with both
(azure-mgmt-resource==1.2.1, api_version=='2017-05-10')
and(azure-mgmt-resource==2.0.0rc2, api_version='2018-05-10')
.The text was updated successfully, but these errors were encountered: