Python Discussions

Python client library: Volume.get_collection(): Validation Error when volume is restricted


Hi Everyone,


We just found that the  Volume.get_collection() method throws an exception when executed against a SVM containing restricted volumes.


Here is a function calling the method:


def getvolumeuuids(vserver, pattern):
    uuidlist = []
        for volume in Volume.get_collection(**{"": vserver}, fields="*"):
             if root_match(str(
            if reg_match(str(, pattern):
                uuidlist.append(('{}'.format(, '{}'.format(volume.uuid), '{}'.format(volume.aggregates[0].name)))

    except NetAppRestError as error:
        print('Error: exception raised when calling Volume.get_collection for vserver {0}: [{1}]'.format(vserver, str(error)))
        return []
        return uuidlist


When called given a vserver with restricted volumes, we get this error:


Error: exception raised when calling Volume.get_collection for vserver xxxxx-xxx-xxxx: [Caused by ValidationError({'state': ['"restricted" is not one of [\'error\', \'mixed\', \'offline\', \'online\']']},)]


The issue was found to exist within version 9.7.3 and 9.9.1 of the netapp_ontap package.


Can you please have a look at why the restricted status is not considered as a valid returned value?




Pierre Kestremond




The issue here is that the /storage/volumes API declares that the valid state values must be one of "error", "mixed", "offline", or "online":



So when ONTAP returned something else, the library raised this validation error. This is something that should be addressed as a bug in ONTAP since the library appears to be doing the correct thing.


However, until that is addressed, you would have to work around it. The easiest way is if you don't need the state field (it didn't seem like you were actually using it here), then you could change your get_collection() call like this:

Volume.get_collection(**{"": vserver}, fields="*,!state")


This tells ONTAP to return all non-expensive fields except for state.