def nfs_export_add(req, host, path, options=None, chown=None, export_path=None): if not isinstance(options, list): if options is not None and len(options) > 0: options = [options] else: options = [] if export_path is not None: raise TargetdError( TargetdError.NFS_NO_SUPPORT, "separate export path not supported at " "this time") bit_opt = 0 key_opt = {} for o in options: if '=' in o: k, v = o.split('=') key_opt[k] = v else: bit_opt |= Export.bool_option[o] if chown is not None: if not allow_chown: raise TargetdError( TargetdError.NO_SUPPORT, "Chown is disabled. Consult manual before enabling it.") items = chown.split(':') try: uid = int(items[0]) gid = -1 if len(items) > 1: gid = int(items[1]) os.chown(path, uid, gid) except ValueError as e: raise TargetdError(TargetdError.INVALID_ARGUMENT, "Wrong chown arguments: {}".format(e)) try: Nfs.export_add(host, path, bit_opt, key_opt) except ValueError as e: raise TargetdError(TargetdError.INVALID_ARGUMENT, "{}".format(e)) return dict(host=host, path=path)
def nfs_export_add(req, host, path, export_path, options): if export_path is not None: raise TargetdError( -401, "separate export path not supported at " "this time") bit_opt = 0 key_opt = {} for o in options: if '=' in o: k, v = o.split('=') key_opt[k] = v else: bit_opt |= Export.bool_option[o] Nfs.export_add(host, path, bit_opt, key_opt)