How can I pass a nested list as a argument in a flask application

Viewed 44

Context: I want to add multiple volumes to one storage device.

I have a flask application/API and I want to create a post method which can take a few arguments but some of the arguments needs to take a list.

My code looks like this:

@API.route("/flows/new_volume")
class NewVolume(SAFResource):

    @API.expect(new_volume_parser)
    def post(self):
        args = new_volume_parser.parse_args()

new_volume_parser - contains the arguments

new_volume_parser = reqparse.RequestParser()
new_volume_parser.add_argument(
    "environment",
    required=True,
    location="json",
    default="shared_env",
)
...

I want to do something like this (without the comments ofc):

curl http://localhost/flows/new_volume --data  {
    "change_order": 123456,             
    "environment": "stor env",   
    "ci_list": [
        "CI12345678", "HI12345"
    ],                    
    "volumes": [                      // LIST of Dictionaries - List of all volumes requested 
        // Non Replicated volume:
        {
            "name": "volume1",        // String - Volume Name
            "size": 10,               // Integer - Volume size
            "replicated": false       // Boolean - Replicated volume
        },
        // Replicated volume:
        {
            "name": "volume2",          // String - Volume Name
            "size": 500,                // Integer - Volume size
            "replicated": true,         // Boolean - Replicated volume
            "repl_type": "synchronous", // String: ['synchronous', 'asynchronous']
        }
    ],
    "dr_ci_list": [                     // LIST of Strings - List of CI for the DR hosts. Field is empty if the volume is not replicated.
        "CI00065232"
    ] }

As you can see the volumes argument contains a list of dictionaries.

I found this in the docs but that's not quite what I want. Does anyone know a way to do this?

0 Answers
Related