def export_fs(self, fs_id, export_path, root_list, rw_list, ro_list, anon_uid, anon_gid, auth_type, options, flags=0): """ Exports a filesystem as specified in the export """ if export_path is None: raise LsmError(ErrorNumber.INVALID_ARGUMENT, "Export path is required") md5_id = md5(export_path) fs_dict = {'auth_type': 'sys', 'anonymous': 'false'} if ro_list: fs_dict['read_only'] = ','.join(ro_list) if rw_list: fs_dict['read_write'] = ','.join(rw_list) if anon_uid or anon_gid: fs_dict['anonymous'] = 'true' if root_list: fs_dict['root'] = ','.join(root_list) if auth_type: fs_dict['auth_type'] = str(auth_type) if '*' in rw_list: fs_dict['anonymous'] = 'true' if options: fs_dict['extra_options'] = str(options) result = self._request("share_folder", "netstorsvc", ['svc:/network/nfs/server:default', fs_id, fs_dict]) return NfsExport(md5_id, fs_id, export_path, auth_type, root_list, rw_list, ro_list, anon_uid, anon_gid, options)
def exports(self, search_key=None, search_value=None, flags=0): """ Get a list of all exported file systems on the controller. """ exp_list = self._request("get_shared_folders", "netstorsvc", ['svc:/network/nfs/server:default', '']) exports = [] for e in exp_list: opts = self._request("get_shareopts", "netstorsvc", ['svc:/network/nfs/server:default', e]) exports.append(NfsExport(md5(opts['name']), e, opts['name'], opts['auth_type'], opts['root'], opts['read_write'], opts['read_only'], 'N/A', 'N/A', opts['extra_options'])) return search_property(exports, search_key, search_value)
def exports(self, search_key=None, search_value=None, flags=0): tmp_exports = {} exports = [] fs_full_paths = {} all_nfs_exports = self._jsonrequest("nfs_export_list") nfs_exports = [] # Remove those that are not of FS origin fs_list = self._jsonrequest("fs_list") for f in fs_list: fs_full_paths[f['full_path']] = f for export in all_nfs_exports: if export['path'] in fs_full_paths: nfs_exports.append(export) # Collect like exports to minimize results for export in nfs_exports: key = export['path'] + \ TargetdStorage._option_string(export['options']) if key in tmp_exports: tmp_exports[key].append(export) else: tmp_exports[key] = [export] # Walk through the options for le in tmp_exports.values(): export_id = "" root = [] rw = [] ro = [] sec = None anonuid = NfsExport.ANON_UID_GID_NA anongid = NfsExport.ANON_UID_GID_NA options = None for export in le: host = export['host'] export_id += host export_id += export['path'] export_id += fs_full_paths[export['path']]['uuid'] options = export['options'] if 'rw' in options: rw.append(host) if 'ro' in options: ro.append(host) sec = TargetdStorage._get_value(options, 'sec') if sec is None: sec = 'sys' if 'no_root_squash' in options: root.append(host) uid = TargetdStorage._get_value(options, 'anonuid') if uid is not None: anonuid = uid gid = TargetdStorage._get_value(options, 'anongid') if gid is not None: anongid = gid exports.append( NfsExport( TargetdStorage._calculate_export_md5( export['path'], options), fs_full_paths[export['path']]['uuid'], export['path'], sec, root, rw, ro, anonuid, anongid, TargetdStorage._option_string(options))) return search_property(exports, search_key, search_value)
def export_fs(self, fs_id, export_path, root_list, rw_list, ro_list, anon_uid=NfsExport.ANON_UID_GID_NA, anon_gid=NfsExport.ANON_UID_GID_NA, auth_type=None, options=None, flags=None): """Add an export""" if fs_id is None and export_path is None: raise LsmError(ErrorNumber.INVALID_ARGUMENT, 'Must provide fs_id or export_path') if fs_id is None: try: fs_id = get_fsid(export_path) except: raise LsmError(ErrorNumber.NOT_FOUND_FS, 'FileSystem not found') else: if NFSPlugin._get_fsid_path(fs_id) is None: raise LsmError(ErrorNumber.NOT_FOUND_FS, 'No FileSystem found with that ID') if export_path is None: export_path = NFSPlugin._get_fsid_path(fs_id) if export_path is None: raise LsmError(ErrorNumber.INVALID_ARGUMENT, 'Could not locate filesystem') else: try: get_fsid(export_path) except: raise LsmError(ErrorNumber.NOT_FOUND_FS, 'Export path not found') if auth_type is not None: authlist = NFSPlugin._AUTH_LIST if auth_type not in authlist: raise LsmError(ErrorNumber.INVALID_ARGUMENT, 'Unsupported auth type') for host in root_list: if host not in rw_list and host not in ro_list: raise LsmError(ErrorNumber.INVALID_ARGUMENT, 'Root hosts must also be in rw or ro lists') expid = NFSPlugin._export_id(export_path, auth_type, anon_uid, anon_gid, options) newexp = NfsExport(expid, fs_id, export_path, auth_type, root_list, rw_list, ro_list, anon_uid, anon_gid, options) efile = NFSPlugin._open_exports(readonly=False) exports = NFSPlugin._read_exports(efile) result = None for idx, oldexp in enumerate(exports): if NFSPlugin._match_path(newexp, oldexp): exports[idx] = newexp result = exports[idx] newexp = None if newexp is not None: exports.append(newexp) result = newexp NFSPlugin._write_exports(efile, exports) NFSPlugin._close_exports(efile) NFSPlugin._update_exports() return result
def _parse_export(parts=None): """Parse a line of export file""" if len(parts) < 1: return None path = parts[0] host = '*' optionstring = "" if len(parts) > 1: host = parts[1] if '(' and ')' in host: if host[0] != '(': host, optionstring = host[:-1].split('(') else: optionstring = host[1:-1] host = '*' options = NFSPlugin._parse_options(optionstring) root_list = [] rw_list = [] ro_list = [] sec = None anonuid = None anongid = None if 'rw' in options: rw_list.append(host) del options['rw'] if 'ro' in options: ro_list.append(host) del options['ro'] if 'no_root_squash' in options: root_list.append(host) del options['no_root_squash'] else: if 'root_squash' in options: del options['root_squash'] if 'sec' in options: sec = options['sec'] del options['sec'] else: sec = None if 'anonuid' in options: anonuid = int(options['anonuid']) del options['anonuid'] else: anonuid = NfsExport.ANON_UID_GID_NA if 'anongid' in options: anongid = int(options['anongid']) del options['anongid'] else: anongid = NfsExport.ANON_UID_GID_NA try: fsid = get_fsid(path) optionstring = NFSPlugin._print_option(options) export_id = NFSPlugin._export_id(path, sec, anonuid, anongid, optionstring) result = NfsExport(export_id, fsid, path, sec, root_list, rw_list, ro_list, anonuid, anongid, optionstring) return result except: pass return None