Return a serial number in hex using os.urandom() and a Unix timestamp
    in microseconds.

    ca_name
        name of the CA
    CN
        common name in the request

def _new_serial(ca_name):
    '''
    Return a serial number in hex using os.urandom() and a Unix timestamp
    in microseconds.

    ca_name
        name of the CA
    CN
        common name in the request
    '''
    hashnum = int(
        binascii.hexlify(
            b'_'.join((
                salt.utils.stringutils.to_bytes(_microtime()),
                os.urandom(5) if six.PY3 else os.urandom(5).encode('hex')
            ))
        ),
        16
    )
    log.debug('Hashnum: %s', hashnum)

    # record the hash somewhere
    cachedir = __opts__['cachedir']
    log.debug('cachedir: %s', cachedir)
    serial_file = '{0}/{1}.serial'.format(cachedir, ca_name)
    if not os.path.exists(cachedir):
        os.makedirs(cachedir)
    if not os.path.exists(serial_file):
        mode = 'w'
    else:
        mode = 'a+'
    with salt.utils.files.fopen(serial_file, mode) as ofile:
        ofile.write(str(hashnum))  # future lint: disable=blacklisted-function

    return hashnum