Migrate Ruleset with Tuple for Version check

Today i migrated a rule with a similar problem.

Dict element with an tuple as value.

Definition

def _parameter_valuespec_hyperv_vm_integration():
    return Dictionary(
        elements={
            "match_services": DictElement(
                parameter_form=List(
                    title=Title("Special States"),
                    migrate=_migrate_tuple,
                    element_template=Dictionary(
                        elements={
                            "service_name": DictElement(
                                required=True,
                                parameter_form=String(
                                    title=Title("Service name"),
                                    custom_validate=(LengthInRange(min_value=1),),
                                ),
                            ),
                            "state": DictElement(
                                required=True,
                                parameter_form=String(
                                    title=Title("State name"),
                                    custom_validate=(LengthInRange(min_value=1),),
                                ),
                            ),
                        }
                    ),
                ),
            ),
        }
    )

Result

{"match_services": [
    {"service_name": "testname123", "state": "running"}, 
    {"service_name": "testname456", "state": "stopped"},
]}

It’s more complex than the result before but it was ok in my case.

Link to the complete code - also the migrate function was not so easy.

1 Like