def _object_in_remote_container(self, name, sync_to, user_key, realm, realm_key, timestamp): """ Performs head object on remote to eliminate extra remote put and local get object calls :param name: The name of the object in the updated row in the local database triggering the sync update. :param sync_to: The URL to the remote container. :param user_key: The X-Container-Sync-Key to use when sending requests to the other container. :param realm: The realm from self.realms_conf, if there is one. If None, fallback to using the older allowed_sync_hosts way of syncing. :param realm_key: The realm key from self.realms_conf, if there is one. If None, fallback to using the older allowed_sync_hosts way of syncing. :param timestamp: last modified date of local object :returns: True if object already exists in remote """ headers = {'x-timestamp': timestamp.internal} self._update_sync_to_headers(name, sync_to, user_key, realm, realm_key, 'HEAD', headers) try: metadata, _ = head_object(sync_to, name=name, headers=headers, proxy=self.select_http_proxy(), logger=self.logger, retries=0) remote_ts = Timestamp(metadata.get('x-timestamp', 0)) self.logger.debug("remote obj timestamp %s local obj %s" % (timestamp.internal, remote_ts.internal)) if timestamp <= remote_ts: return True # Object in remote should be updated return False except ClientException as http_err: # Object not in remote if http_err.http_status == 404: return False raise http_err
def _object_in_remote_container(self, name, sync_to, user_key, realm, realm_key, timestamp): """ Performs head object on remote to eliminate extra remote put and local get object calls :param name: The name of the object in the updated row in the local database triggering the sync update. :param sync_to: The URL to the remote container. :param user_key: The X-Container-Sync-Key to use when sending requests to the other container. :param realm: The realm from self.realms_conf, if there is one. If None, fallback to using the older allowed_sync_hosts way of syncing. :param realm_key: The realm key from self.realms_conf, if there is one. If None, fallback to using the older allowed_sync_hosts way of syncing. :param timestamp: last modified date of local object :returns: True if object already exists in remote """ headers = {'x-timestamp': timestamp.internal} self._update_sync_to_headers(name, sync_to, user_key, realm, realm_key, 'HEAD', headers) try: metadata, _ = head_object(sync_to, name=name, headers=headers, proxy=self.select_http_proxy(), logger=self.logger, retries=0) remote_ts = Timestamp(metadata.get('x-timestamp', 0)) self.logger.debug("remote obj timestamp %s local obj %s" % (timestamp.internal, remote_ts.internal)) if timestamp <= remote_ts: return True # Object in remote should be updated return False except ClientException as http_err: # Object not in remote if http_err.http_status == 404: return False raise http_err