Python Discussions

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

pierrekestremond
1,765 Views

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 = []
    try:
        for volume in Volume.get_collection(**{"svm.name": vserver}, fields="*"):
             if root_match(str(volume.name)):
                 continue
            if reg_match(str(volume.name), pattern):
                uuidlist.append(('{}'.format(volume.name), '{}'.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 []
    else:
        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?

 

Thanks

 

Pierre Kestremond

 

1 REPLY 1

RobertBlackhart
1,733 Views

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

https://library.netapp.com/ecmdocs/ECMLP2876964/html/index.html#/storage/volume_collection_get

RobertBlackhart_0-1626444185604.png

 

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(**{"svm.name": vserver}, fields="*,!state")

 

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

Public