예제 #1
0
    def do_call(self, url, data, method,
                calltimeout=consts.SOCKET_TIMEOUT):
        """Send requests to Hpe3par storage server.
        """
        if 'http' not in url:
            if self.san_address:
                url = self.san_address + url

        kwargs = {'timeout': calltimeout}
        if data:
            kwargs['data'] = json.dumps(data)

        if method in ('POST', 'PUT', 'GET', 'DELETE'):
            func = getattr(self.session, method.lower())
        else:
            msg = _("Request method %s is invalid.") % method
            LOG.error(msg)
            raise exception.StorageBackendException(reason=msg)
        res = None
        try:
            res = func(url, **kwargs)
        except requests.exceptions.ConnectTimeout as ct:
            LOG.error('ConnectTimeout err: {}'.format(ct))
            raise exception.ConnectTimeout()
        except Exception as err:
            LOG.exception('Bad response from server: %(url)s.'
                          ' Error: %(err)s', {'url': url, 'err': err})
            if 'WSAETIMEDOUT' in str(err):
                raise exception.ConnectTimeout()
            else:
                raise exception.BadResponse()

        return res
예제 #2
0
 def get_rest_info(self, url, data=None, method='GET'):
     if 'login' == data:
         self.session.auth = requests.auth.HTTPBasicAuth(
             self.rest_username, cryptor.decode(self.rest_password))
     else:
         self.login()
         self.session.auth = requests.auth.HTTPBasicAuth(
             self.rest_username, self.rest_auth_token)
     res = self.do_call(url, data, method)
     try:
         if res.status_code == 200:
             result_json = json.loads(res.text)
         elif res.status_code == 500:
             LOG.error('Connect Timeout error')
             raise exception.ConnectTimeout()
         elif res.status_code == 401:
             LOG.error('User authentication failed')
             raise exception.InvalidUsernameOrPassword
         else:
             raise exception.BadResponse()
     except Exception as err:
         LOG.exception(
             'Get RestHandler.call failed: %(url)s.'
             ' Error: %(err)s', {
                 'url': url,
                 'err': err
             })
         raise exception.InvalidResults(err)
     return result_json
예제 #3
0
 def do_exec(self, command_str):
     result = ''
     try:
         with self.item() as ssh:
             utils.check_ssh_injection(command_str)
             if command_str is not None and ssh is not None:
                 stdin, stdout, stderr = ssh.exec_command(command_str)
                 res, err = stdout.read(), stderr.read()
                 re = res if res else err
                 result = re.decode()
     except paramiko.AuthenticationException as ae:
         LOG.error('doexec Authentication error:{}'.format(ae))
         raise exception.InvalidUsernameOrPassword()
     except Exception as e:
         err = six.text_type(e)
         LOG.error(err)
         if 'timed out' in err \
                 or 'SSH connect timeout' in err\
                 or 'Unable to connect to port' in err:
             raise exception.ConnectTimeout()
         elif 'No authentication methods available' in err \
                 or 'Authentication failed' in err \
                 or 'Invalid username or password' in err:
             raise exception.InvalidUsernameOrPassword()
         elif 'not a valid RSA private key file' in err \
                 or 'not a valid RSA private key' in err:
             raise exception.InvalidPrivateKey()
         else:
             raise exception.SSHException(err)
     if 'invalid command name' in result or 'login failed' in result or\
             'is not a recognized command' in result:
         raise exception.StorageBackendException(result)
     return result
예제 #4
0
 def ssh_do_exec(self, command_list):
     res = None
     with eventlet.Timeout(60, False):
         res = self.ssh_pool.do_exec_shell(command_list)
         while 'Failed to establish SSC connection' in res:
             res = self.ssh_pool.do_exec_shell(command_list)
     if res:
         return res
     else:
         raise \
             exception.ConnectTimeout(
                 'Failed to establish SSC connection from hitachi hnas'
             )
예제 #5
0
    def do_call(self, url, data, method, calltimeout=SOCKET_TIMEOUT):
        if 'http' not in url:
            if self.san_address:
                url = '%s%s' % (self.san_address, url)

        kwargs = {'timeout': calltimeout}
        if data:
            kwargs['data'] = json.dumps(data)

        if method in ('POST', 'PUT', 'GET', 'DELETE'):
            func = getattr(self.session, method.lower())
        else:
            msg = _("Request method %s is invalid.") % method
            LOG.error(msg)
            raise exception.StorageBackendException(msg)
        res = None
        try:
            res = func(url, **kwargs)
        except requests.exceptions.ConnectTimeout as ct:
            LOG.error('Connect Timeout err: {}'.format(ct))
            raise exception.InvalidIpOrPort()
        except requests.exceptions.ReadTimeout as rt:
            LOG.error('Read timed out err: {}'.format(rt))
            raise exception.StorageBackendException(six.text_type(rt))
        except requests.exceptions.SSLError as e:
            LOG.error('SSLError for %s %s' % (method, url))
            err_str = six.text_type(e)
            if 'certificate verify failed' in err_str:
                raise exception.SSLCertificateFailed()
            else:
                raise exception.SSLHandshakeFailed()
        except Exception as err:
            LOG.exception(
                'Bad response from server: %(url)s.'
                ' Error: %(err)s', {
                    'url': url,
                    'err': err
                })
            if 'WSAETIMEDOUT' in str(err):
                raise exception.ConnectTimeout()
            elif 'Failed to establish a new connection' in str(err):
                LOG.error('Failed to establish: {}'.format(err))
                raise exception.InvalidIpOrPort()
            elif 'Read timed out' in str(err):
                raise exception.StorageBackendException(six.text_type(err))
            else:
                raise exception.BadResponse()

        return res