'Generate certificates in the given directory.
:param FilePath directory: Directory to use for certificate authority.
:param bytes control_hostname: The hostname of the control service.
:param int num_nodes: Number of nodes in the cluster.
:param UUID cluster_id: The unique identifier of the cluster for which
the certificates are being generated.  If not given, a random
identifier will be generated.
:return: ``Certificates`` instance.'

@classmethod
def generate(cls, directory, control_hostname, num_nodes, cluster_name, cluster_id=None):

    RootCredential.initialize(directory, cluster_name, cluster_id=cluster_id)
    def run(*arguments):
        check_call((['flocker-ca'] + list(arguments)), cwd=directory.path)
    run('create-control-certificate', control_hostname)
    run('create-api-certificate', 'allison')
    directory.child('allison.crt').moveTo(directory.child('user.crt'))
    directory.child('allison.key').moveTo(directory.child('user.key'))
    for i in range(num_nodes):
        run('create-node-certificate')
    for (i, child) in enumerate(directory.globChildren('????????-????-*.crt')):
        sibling = FilePath((child.path[:(-3)] + 'key'))
        child.moveTo(directory.child(('node-%d.crt' % (i,))))
        sibling.moveTo(directory.child(('node-%d.key' % (i,))))
    return cls(directory)
