How to use the azure-storage-common.azure.storage.common.models.LocationMode.SECONDARY function in azure-storage-common

To help you get started, we’ve selected a few azure-storage-common examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Azure / azure-storage-python / azure-storage-common / azure / storage / common / retry.py View on Github external
def _set_next_host_location(self, context):
        '''
        A function which sets the next host location on the request, if applicable. 

        :param ~azure.storage.models.RetryContext context: 
            The retry context containing the previous host location and the request 
            to evaluate and possibly modify.
        '''
        if len(context.request.host_locations) > 1:
            # If there's more than one possible location, retry to the alternative
            if context.location_mode == LocationMode.PRIMARY:
                context.location_mode = LocationMode.SECONDARY

                # if targeting the emulator (with path style), change path instead of host
                if context.is_emulated:
                    # replace the first instance of primary account name with the secondary account name
                    context.request.path = context.request.path.replace(DEV_ACCOUNT_NAME, DEV_ACCOUNT_SECONDARY_NAME, 1)
                else:
                    context.request.host = context.request.host_locations.get(context.location_mode)
            else:
                context.location_mode = LocationMode.PRIMARY

                # if targeting the emulator (with path style), change path instead of host
                if context.is_emulated:
                    # replace the first instance of secondary account name with the primary account name
                    context.request.path = context.request.path.replace(DEV_ACCOUNT_SECONDARY_NAME, DEV_ACCOUNT_NAME, 1)
                else:
                    context.request.host = context.request.host_locations.get(context.location_mode)
github Azure / azure-storage-python / azure-storage-common / azure / storage / common / retry.py View on Github external
example, network issues would trigger this.
            '''
            return True
        elif 200 <= status < 300:
            '''
            This method is called after a successful response, meaning we failed 
            during the response body download or parsing. So, success codes should 
            be retried.
            '''
            return True
        elif 300 <= status < 500:
            '''
            An exception occured, but in most cases it was expected. Examples could 
            include a 309 Conflict or 412 Precondition Failed.
            '''
            if status == 404 and context.location_mode == LocationMode.SECONDARY:
                # Response code 404 should be retried if secondary was used.
                return True
            if status == 408:
                # Response code 408 is a timeout and should be retried.
                return True
            return False
        elif status >= 500:
            '''
            Response codes above 500 with the exception of 501 Not Implemented and 
            505 Version Not Supported indicate a server issue and should be retried.
            '''
            if status == 501 or status == 505:
                return False
            return True
        else:
            # If something else happened, it's unexpected. Retry.
github Azure / azure-storage-python / azure-storage-common / azure / storage / common / storageclient.py View on Github external
def _get_host_locations(self, primary=True, secondary=False):
        locations = {}
        if primary:
            locations[LocationMode.PRIMARY] = self.primary_endpoint
        if secondary:
            locations[LocationMode.SECONDARY] = self.secondary_endpoint
        return locations

azure-storage-common

Microsoft Azure Storage Common Client Library for Python

MIT
Latest version published 5 years ago

Package Health Score

73 / 100
Full package analysis

Similar packages