lib/fog/azurerm/utilities/general.rb in fog-azure-rm-temp-0.0.4 vs lib/fog/azurerm/utilities/general.rb in fog-azure-rm-temp-0.0.5

- old
+ new

@@ -45,20 +45,12 @@ def get_record_type(type) type.split('/').last end def raise_azure_exception(exception, msg) - if exception.respond_to? 'body' - message = if exception.body['error'].nil? - exception.body['message'] - else - exception.body['error']['message'] - end - exception_message = "Exception in #{msg} #{message} Type: #{exception.class}\n#{exception.backtrace.join("\n")}" - else - exception_message = "#{exception.inspect}\n#{exception.backtrace.join("\n")}" - end + description = exception.is_a?(Azure::Core::Http::HTTPError) ? exception.description : exception.error_message + exception_message = "Exception in #{msg} #{description} Type: #{exception.class}\n#{exception.backtrace.join('\n')}" Fog::Logger.debug exception.backtrace raise exception_message end @@ -163,6 +155,25 @@ end data['last_modified'] = Time.parse(data['last_modified']) data['etag'].delete!('"') data +end + +def resource_not_found?(azure_operation_error) + is_found = false + if azure_operation_error.response.status == HTTP_NOT_FOUND + if azure_operation_error.body['code'] + is_found = azure_operation_error.body['code'] == ERROR_CODE_NOT_FOUND + elsif azure_operation_error.body['error'] + is_found = azure_operation_error.body['error']['code'] == ERROR_CODE_NOT_FOUND || + azure_operation_error.body['error']['code'] == ERROR_CODE_RESOURCE_GROUP_NOT_FOUND || + azure_operation_error.body['error']['code'] == ERROR_CODE_RESOURCE_NOT_FOUND || + azure_operation_error.body['error']['code'] == ERROR_CODE_PARENT_RESOURCE_NOT_FOUND + end + end + is_found +end + +def get_image_name(id) + id.split('/').last end