def main(conninfo, credentials, args): if args.restrictions: restrictions = parse_nfs_restrictions_file(conninfo, credentials, args.restrictions) else: restrictions = [NFSRestriction.create_default()] print nfs.nfs_add_share(conninfo, credentials, args.export_path, args.fs_path, args.description, restrictions, args.create_fs_path)
def main(conninfo, credentials, args): sys.stderr.write( 'Warning: nfs_add_share is deprecated. See nfs_add_exports.\n') if args.restrictions: restrictions = parse_nfs_restrictions_file(conninfo, credentials, args.restrictions) else: restrictions = [NFSRestriction.create_default()] print nfs.nfs_add_share(conninfo, credentials, args.export_path, args.fs_path, args.description, restrictions, args.create_fs_path)
def main(conninfo, credentials, args): sys.stderr.write( 'Warning: nfs_mod_share is deprecated. See nfs_mod_export.\n') # Get existing share share_info = {} share_info, share_info['if_match'] = \ nfs.nfs_list_share(conninfo, credentials, args.id) # Modify share share_info['id_'] = share_info['id'] share_info['allow_fs_path_create'] = args.create_fs_path del share_info['id'] if args.export_path is not None: share_info['export_path'] = args.export_path if args.fs_path is not None: share_info['fs_path'] = args.fs_path if args.description is not None: share_info['description'] = args.description # Overwrite the NFS restrictions from JSON file. if args.restrictions: share_info['restrictions'] = parse_nfs_restrictions_file( conninfo, credentials, args.restrictions) elif args.no_restrictions: # Modify the share's restrictions to be the default ones (no # restrictions). share_info['restrictions'] = [NFSRestriction.create_default()] else: # If no restrictions were specified and the user didn't set the # --no-restrictions flag, let's preserve the ones that # were originally set for this share. However, we need to re-pack # them to be of type "NFSRestriction", in order to keep the REST # client consistent. share_info['restrictions'] = \ [NFSRestriction(r) for r in share_info['restrictions']] print nfs.nfs_modify_share(conninfo, credentials, **share_info)
def parse_nfs_restrictions_file(conninfo, credentials, path): # Parse JSON file. with open(path) as f: contents = f.read() try: restrictions = json.loads(contents) except ValueError as e: raise ValueError('Error parsing JSON restrictions file ' + str(e)) # Validate the restrictions are well formed, and create the # NFSRestriction object. nfs_restrictions = list() for r in restrictions['restrictions']: # Get read-only. read_only = r.get('read_only', False) # Process host restrictions. host_restrictions = r.get('host_restrictions', []) # Process user mapping values. try: user_mapping = process_user_mapping(r.get('user_mapping', 'none'), r.get('map_to_user_id', '0')) except ValueError as e: raise ValueError('When trying to process the following ' + 'restriction: ' + str(r) + ', this error was thrown: ' + str(e)) # Allow either auth_id or user name. user_id = users.get_user_id(conninfo, credentials, r.get('map_to_user_id', '0')) # Add the NFSRestriction to the list. nfs_restrictions.append( NFSRestriction({ 'read_only': read_only, 'host_restrictions': host_restrictions, 'user_mapping': user_mapping, 'map_to_user_id': str(user_id.data) })) # Return the list of restrictions. return nfs_restrictions
def main(conninfo, credentials, args): # Get existing share share_info = {} share_info, share_info['if_match'] = \ nfs.nfs_list_share(conninfo, credentials, args.id) # Modify share share_info['id_'] = share_info['id'] share_info['allow_fs_path_create'] = args.create_fs_path del share_info['id'] if args.export_path is not None: share_info['export_path'] = args.export_path if args.fs_path is not None: share_info['fs_path'] = args.fs_path if args.description is not None: share_info['description'] = args.description # Overwrite the NFS restrictions from JSON file. if args.restrictions: share_info['restrictions'] = parse_nfs_restrictions_file( conninfo, credentials, args.restrictions) elif args.no_restrictions: # Modify the share's restrictions to be the default ones (no # restrictions). share_info['restrictions'] = [NFSRestriction.create_default()] else: # If no restrictions were specified and the user didn't set the # --no-restrictions flag, let's preserve the ones that # were originally set for this share. However, we need to re-pack # them to be of type "NFSRestriction", in order to keep the REST # client consistent. share_info['restrictions'] = \ [NFSRestriction(r) for r in share_info['restrictions']] print nfs.nfs_modify_share(conninfo, credentials, **share_info)