def METHOD_NAME(self, force=False):
    need_cert = False
    if force:
        need_cert = True
    else:
        with OnlPkiContextReadOnly(self.logger):
            if not os.path.exists(self.cpath):
                need_cert = True
    if need_cert:
        self.logger.info("Generating self-signed certificate...")
        csr = tempfile.NamedTemporaryFile(prefix="pki-", suffix=".csr", delete=False)
        csr.close()
        fields = [ "%s=%s" % (k, v) for k,v in sysconfig.pki.cert.csr.fields.iteritems() ]
        subject = "/" + "/".join(fields)
        self.logger.debug("Subject: '%s'", subject)
        self.logger.debug("CSR: %s", csr.name)
        with OnlPkiContextReadWrite(self.logger):
            if not os.path.isdir(self.CONFIG_PKI_DIR):
                os.makedirs(self.CONFIG_PKI_DIR)
            self._execute(('openssl', 'req',
                           '-new', '-batch',
                           '-subj', subject,
                           '-key', self.kpath,
                           '-out', csr.name,),
                          logLevel=logging.INFO)
            self._execute(('openssl', 'x509',
                           '-req',
                           '-days', str(sysconfig.pki.cert.csr.cdays),
                           '-sha256',
                           '-in', csr.name,
                           '-signkey', self.kpath,
                           '-out', self.cpath,),
                          logLevel=logging.INFO)
        os.unlink(csr.name)
    else:
        self.logger.info("Using existing certificate.")