'Generate a keypair.'

def generate(self, module):

    if ((not os.path.exists(self.path)) or self.force):
        self.privatekey = crypto.PKey()
        if (self.type == 'RSA'):
            crypto_type = crypto.TYPE_RSA
        else:
            crypto_type = crypto.TYPE_DSA
        try:
            self.privatekey.generate_key(crypto_type, self.size)
        except (TypeError, ValueError):
            raise PrivateKeyError(get_exception())
        try:
            privatekey_file = os.open(self.path, ((os.O_WRONLY | os.O_CREAT) | os.O_TRUNC), self.mode)
            os.write(privatekey_file, crypto.dump_privatekey(crypto.FILETYPE_PEM, self.privatekey))
            os.close(privatekey_file)
        except IOError:
            self.remove()
            raise PrivateKeyError(get_exception())
    else:
        self.changed = False
    file_args = module.load_file_common_arguments(module.params)
    if module.set_fs_attributes_if_different(file_args, False):
        self.changed = True
