'check whether the certificate exists and has the clusterIP'

def exists(self):

    cert_path = self.config.config_options['cert']['value']
    if (not os.path.exists(cert_path)):
        return False
    cert_names = []
    hostnames = self.config.config_options['hostnames']['value'].split(',')
    proc = subprocess.Popen(['openssl', 'x509', '-noout', '-text', '-in', cert_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    (x509output, _) = proc.communicate()
    if (proc.returncode == 0):
        regex = re.compile('^\\s*X509v3    Subject    Alternative    Name:\\s*?\\n\\s*(.*)\\s*\\n', re.MULTILINE)
        match = regex.search(x509output.decode())
        if (not match):
            return False
        for entry in re.split(',    *', match.group(1)):
            if (entry.startswith('DNS') or entry.startswith('IP    Address')):
                cert_names.append(entry.split(':')[1])
        cert_set = set(cert_names)
        hname_set = set(hostnames)
        if (cert_set.issubset(hname_set) and hname_set.issubset(cert_set)):
            return True
    return False
