Exemplo n.º 1
0
 def execute_action(self, **kwargs):
     """
     Process the support_bundle response from the business layer
     """
     # pylint:disable=too-many-function-args
     try:
         response_data = super(Status, self).execute_action(**kwargs)
         response_str = self.get_human_readable_response(response_data)
     # pylint:disable=broad-except
     except Exception:
         raise errors.InternalError()
     return response_str
Exemplo n.º 2
0
    def execute_action(self, **kwargs):
        # pylint:disable=too-many-function-args
        """
        Process the support_bundle response from the business layer
        """
        try:
            response = super(S3AccountCommand, self).execute_action(**kwargs)
            if self.action == Strings.CREATE:
                response = self.get_human_readable_response(
                    self.name, response)
            elif self.action == Strings.LIST:
                response = self.get_human_readable_list_response(response)
            elif self.action == Strings.REMOVE:
                response = self.get_human_readable_remove_response(
                    self.name, response)

        except Exception as ex:
            if Strings.SOCKET_ERROR in str(ex):
                raise errors.InternalError(err=Strings.COMMUNICATION_ERROR,
                                           desc=Strings.COMMUNICATION_ER_DESC)
            raise errors.InternalError(desc=str(ex))
        return response
Exemplo n.º 3
0
    def get_human_readable_response(result):
        """
        Parse the json to read the human readable response
        """
        try:
            result = result and result[-1]
            power_resp = result.get('power_status', {})
            sem_resp = result.get('sem_status', '')
            file_status_resp = result.get('file_system_status', None)

            active_nodes = power_resp.get('active_nodes', [])
            inactive_nodes = power_resp.get('inactive_nodes', [])
            pwr_response = ''
            if active_nodes:
                active_nodes = '\n\t'.join(active_nodes)
                pwr_response = 'Active Nodes:- \n\t{}'.format(active_nodes)
            if inactive_nodes:
                inactive_nodes = '\n\t'.join(inactive_nodes)
                pwr_response = '{} \nInactive Nodes:- \n\t{}'.format(
                    pwr_response, inactive_nodes)
            file_resp = None
            response = ''
            if file_status_resp:
                if file_status_resp[0]:
                    file_resp = file_status_resp[0]
                    if Status.is_json(file_resp):
                        file_resp = Status._parse_status_response(file_resp)
                        response = 'Filesystem status: {} \n\n'.format(
                            file_resp)
                    else:
                        response = 'Filesystem status: {} \n\n'.format(
                            file_resp)
            else:
                response = 'Filesystem status: No response \n\n'

            response += sem_resp
            response += '\n\n'
            response += pwr_response
            return response
        # pylint:disable=broad-except
        except Exception:
            raise errors.InternalError()
Exemplo n.º 4
0
    def execute_action(self, **kwargs):
        # pylint:disable=too-many-function-args
        """
        Process the operation response from the business layer
        """
        # print "execute_action called"
        try:
            response = super(S3AccessKeyCommand, self).execute_action(**kwargs)
            if self.action == Strings.CREATE:
                response = self.get_human_readable_response(response)
            elif self.action == Strings.LIST:
                response = self.get_human_readable_list_response(response)
            elif self.action == Strings.MODIFY:
                response = self.get_human_readable_modify_response(response)
            elif self.action == Strings.REMOVE:
                response = self.get_human_readable_remove_response(response)

        except Exception:
            raise errors.InternalError()
        return response
Exemplo n.º 5
0
 def execute_action(self, **kwargs):
     """
     Function to execute the action by sending
     request to data provider in business logic server
     """
     # pylint:disable=too-many-function-args
     url = 'http://{0}{1}data?{2}'.format(BL_HOST,
                                          self.get_provider_base_url(),
                                          self.get_action_params(**kwargs))
     try:
         response = urllib.urlopen(url=url)
     except KeyboardInterrupt:
         raise errors.CommandTerminated()
     if response.getcode() == 200:
         data = response.read()
         try:
             return json.loads(data)
         except ValueError:
             raise errors.InvalidResponse()
     else:
         raise errors.InternalError()