コード例 #1
0
 def _do_request(self, method, action, body=None, headers=None):
     if self.broken:
         raise c_exc.VSMError(reason='VSM:Internal Server Error')
     if self.inject_params and body:
         body['invalidKey'] = 'catchMeIfYouCan'
     if method == 'POST':
         return _validate_resource(action, body)
     elif method == 'GET':
         if 'virtual-port-profile' in action:
             return _policy_profile_generator(self._get_total_profiles())
         else:
             raise c_exc.VSMError(reason='VSM:Internal Server Error')
コード例 #2
0
ファイル: fake_client.py プロジェクト: pjh03/quantum
def _validate_resource(action, body=None):
    if body:
        body_set = set(body.keys())
    else:
        return
    if 'vm-network' in action and 'port' not in action:
        vmnetwork_set = set(_resource_metadata['vmnetwork'])
        if body_set - vmnetwork_set:
            raise cisco_exceptions.VSMError(reason='Invalid Request')
    elif 'port' in action:
        port_set = set(_resource_metadata['port'])
        if body_set - port_set:
            raise cisco_exceptions.VSMError(reason='Invalid Request')
    else:
        return
コード例 #3
0
ファイル: fake_client.py プロジェクト: pjh03/quantum
 def _do_request(self, method, action, body=None, headers=None):
     if self.broken:
         raise cisco_exceptions.VSMError(reason='VSM:Internal Server Error')
     if self.inject_params and body:
         body['invalidKey'] = 'catchMeIfYouCan'
     if method == 'POST':
         return _validate_resource(action, body)
コード例 #4
0
ファイル: n1kv_client.py プロジェクト: tarunmohanty/neutron
    def _do_request(self, method, action, body=None,
                    headers=None):
        """
        Perform the HTTP request.

        The response is in either JSON format or plain text. A GET method will
        invoke a JSON response while a PUT/POST/DELETE returns message from the
        VSM in plain text format.
        Exception is raised when VSM replies with an INTERNAL SERVER ERROR HTTP
        status code (500) i.e. an error has occurred on the VSM or SERVICE
        UNAVAILABLE (503) i.e. VSM is not reachable.

        :param method: type of the HTTP request. POST, GET, PUT or DELETE
        :param action: path to which the client makes request
        :param body: dict for arguments which are sent as part of the request
        :param headers: header for the HTTP request
        :returns: JSON or plain text in HTTP response
        """
        action = self.action_prefix + action
        if not headers and self.hosts:
            headers = self._get_auth_header(self.hosts[0])
        headers['Content-Type'] = self._set_content_type('json')
        headers['Accept'] = self._set_content_type('json')
        if body:
            body = jsonutils.dumps(body, indent=2)
            LOG.debug("req: %s", body)
        try:
            resp = self.pool.spawn(requests.request,
                                   method,
                                   url=action,
                                   data=body,
                                   headers=headers,
                                   timeout=self.timeout).wait()
        except Exception as e:
            raise c_exc.VSMConnectionFailed(reason=e)
        LOG.debug("status_code %s", resp.status_code)
        if resp.status_code == requests.codes.OK:
            if 'application/json' in resp.headers['content-type']:
                try:
                    return resp.json()
                except ValueError:
                    return {}
            elif 'text/plain' in resp.headers['content-type']:
                LOG.debug("VSM: %s", resp.text)
        else:
            raise c_exc.VSMError(reason=resp.text)
コード例 #5
0
ファイル: n1kv_client.py プロジェクト: uramanan/neutron
    def _do_request(self, method, action, body=None,
                    headers=None):
        """
        Perform the HTTP request.

        The response is in either XML format or plain text. A GET method will
        invoke a XML response while a PUT/POST/DELETE returns message from the
        VSM in plain text format.
        Exception is raised when VSM replies with an INTERNAL SERVER ERROR HTTP
        status code (500) i.e. an error has occurred on the VSM or SERVICE
        UNAVAILABLE (503) i.e. VSM is not reachable.

        :param method: type of the HTTP request. POST, GET, PUT or DELETE
        :param action: path to which the client makes request
        :param body: dict for arguments which are sent as part of the request
        :param headers: header for the HTTP request
        :returns: XML or plain text in HTTP response
        """
        action = self.action_prefix + action
        if not headers and self.hosts:
            headers = self._get_auth_header(self.hosts[0])
        headers['Content-Type'] = self._set_content_type('json')
        if body:
            body = self._serialize(body)
            LOG.debug(_("req: %s"), body)
        try:
            resp, replybody = (httplib2.Http(timeout=self.timeout).
                               request(action,
                                       method,
                                       body=body,
                                       headers=headers))
        except Exception as e:
            raise c_exc.VSMConnectionFailed(reason=e)
        LOG.debug(_("status_code %s"), resp.status)
        if resp.status == 200:
            if 'application/xml' in resp['content-type']:
                return self._deserialize(replybody, resp.status)
            elif 'text/plain' in resp['content-type']:
                LOG.debug(_("VSM: %s"), replybody)
        else:
            raise c_exc.VSMError(reason=replybody)