'Send command to DPL.'

def send_cmd(self, method, url, params, expected_status):

    retcode = 0
    data = {}
    header = {'Content-Type': 'application/cdmi-container', 'Accept': 'application/cdmi-container', 'x-cdmi-specification-version': '1.0.2'}
    auth = base64.encodestring(('%s:%s' % (self.username, self.password))).replace('\n', '')
    header['Authorization'] = ('Basic    %s' % auth)
    if (not params):
        payload = None
    else:
        try:
            payload = json.dumps(params, ensure_ascii=False)
            payload.encode('utf-8')
        except Exception as e:
            LOG.error('JSON    encode    params    %(param)s    error:    %(status)s.', {'param': params, 'status': e})
            retcode = errno.EINVAL
    retry = CONNECTION_RETRY
    func = getattr(requests, method.lower())
    cert_path = False
    if self.cert_verify:
        cert_path = self.cert_path
    else:
        cert_path = False
    while retry:
        try:
            r = func(url=('https://%s:%s%s' % (self.ip, self.port, url)), data=payload, headers=header, verify=cert_path)
            if (r.status_code == http_client.SERVICE_UNAVAILABLE):
                LOG.error('The    flexvisor    service    is    unavailable.')
                continue
            else:
                break
        except Exception as e:
            msg = (_('failed    to    %(method)s    due    to    %(error)s') % {'method': method, 'error': six.text_type(e)})
            LOG.error(msg)
            raise exception.VolumeBackendAPIException(data=msg)
    if ((r.status_code in expected_status) and (r.status_code == http_client.NOT_FOUND)):
        retcode = errno.ENODATA
    elif (r.status_code not in expected_status):
        LOG.error('%(method)s    %(url)s    unexpected    response    status:    %(response)s    (expects:    %(expects)s).', {'method': method, 'url': url, 'response': http_client.responses[r.status_code], 'expects': expected_status})
        if (r.status_code == http_client.UNAUTHORIZED):
            raise exception.NotAuthorized
        else:
            retcode = errno.EIO
    elif (r.status_code is http_client.NOT_FOUND):
        retcode = errno.ENODATA
    elif (r.status_code is http_client.ACCEPTED):
        retcode = errno.EAGAIN
        try:
            data = r.json()
        except (TypeError, ValueError) as e:
            LOG.error('Call    to    json.loads()    raised    an    exception:    %s.', e)
            retcode = errno.ENOEXEC
        except Exception as e:
            LOG.error('Read    response    raised    an    exception:    %s.', e)
            retcode = errno.ENOEXEC
    elif ((r.status_code in [http_client.OK, http_client.CREATED]) and (http_client.NO_CONTENT not in expected_status)):
        try:
            data = r.json()
        except (TypeError, ValueError) as e:
            LOG.error('Call    to    json.loads()    raised    an    exception:    %s.', e)
            retcode = errno.ENOEXEC
        except Exception as e:
            LOG.error('Read    response    raised    an    exception:    %s.', e)
            retcode = errno.ENOEXEC
    return (retcode, data)
