def parse_response()

in pantri/scripts/lib/fb_objectstore.py [0:0]


  def parse_response(self, response):
    """
    parse_response(self, response)

    Parses response to determine if action was seccessful and logs messages to
    stdout.
    """

    # Try/Except will catch wrong response values. ie, empty dict or string
    try:
      # Exclude 'create_container' failures since current setup doesnt give
      # users rights to create container. Not an issue unless container
      # doesnt exist
      if response['action'] == 'create_container':
        self.logger.debug('SKIP: (action: create_container)')
        return False

      if response['success']:
        success_msg = 'SUCCESS'
        action = response['action']
        if (
          action == 'upload_object' and
          response['status'] == 'skipped-changed'
        ):
          action = response['status']
          success_msg = 'NOTHING'
        message = '%s (action: %s) Object: %s' % (
          success_msg,
          action,
          response['object'],
        )
        self.logger.info(message)
        return True

      if not response['success']:
        message = ' FAILURE (action: %s) Object: %s Traceback: %s' % (
          response['action'],
          response['object'],
          response['traceback'],
        )
        self.logger.warn(message)
        return False
    except:
      self.logger.warn('FAILURE: Unknown response from Swift')
      return False