def do_request(self, method, action, body=None,
                   headers=None, params=None):
        """Connects to the server and issues a request.
        Returns the result data, or raises an appropriate exception if
        HTTP status code is not 2xx

        :param method: HTTP method ("GET", "POST", "PUT", etc...)
        :param body: string of data to send, or None (default)
        :param headers: mapping of key/value pairs to add as headers
        :param params: dictionary of key/value pairs to add to append
                             to action
        """

        # Ensure we have a tenant id
        if not self.tenant:
            raise Exception(_("Tenant ID not set"))

        # Add format and tenant_id
        action += ".%s" % self.format
        action = Client.action_prefix + action
        action = action.replace('{tenant_id}', self.tenant)

        if type(params) is dict:
            action += '?' + urllib.urlencode(params)

        try:
            connection_type = self.get_connection_type()
            headers = headers or {"Content-Type":
                                      "application/%s" % self.format}

            # Open connection and send request, handling SSL certs
            certs = {'key_file': self.key_file, 'cert_file': self.cert_file}
            certs = dict((x, certs[x]) for x in certs if certs[x] != None)

            if self.use_ssl and len(certs):
                c = connection_type(self.host, self.port, **certs)
            else:
                c = connection_type(self.host, self.port)

            if self.logger:
                self.logger.debug(
                    _("Quantum Client Request:\n%(method)s %(action)s\n" %
                                    locals()))
                if body:
                    self.logger.debug(body)

            c.request(method, action, body, headers)
            res = c.getresponse()
            status_code = self.get_status_code(res)
            data = res.read()

            if self.logger:
                self.logger.debug("Quantum Client Reply (code = %s) :\n %s" \
                        % (str(status_code), data))

            if status_code == httplib.NOT_FOUND:
                raise QuantumNotFoundException(
                    _("Quantum entity not found: %s" % data))

            if status_code in (httplib.OK,
                               httplib.CREATED,
                               httplib.ACCEPTED,
                               httplib.NO_CONTENT):
                if data is not None and len(data):
                    return self.deserialize(data, status_code)
            else:
                raise QuantumServerException(
                      _("Server %(status_code)s error: %(data)s"
                                        % locals()))

        except (socket.error, __HOLE__), e:
            raise QuantumIOException(_("Unable to connect to "
                              "server. Got error: %s" % e))
dataset/ETHPy150Open nii-cloud/dodai-compute/nova/network/quantum/client.py/Client.do_request