CiscoDevNet/python-viptela

device_templates.attach_to_device

jeremypng opened this issue · 0 comments

I would like to modify this function so that it will accept variable or property names in the uuid['variables'] data structure. I'm already constructing this data format to verify whether a sync is needed. It seems redundant to convert it all to variables for the function to then convert it back to property names.

Here is the secion I'm talking about:

           for entry in template_variables['columns']:
                if entry['variable']:
                    if entry['variable'] in uuid[device_uuid]['variables']:
                        device_template_variables[entry['property']] = uuid[device_uuid]['variables'][entry['variable']]
                    elif entry['property'] in uuid[device_uuid]['variables']:
                        device_template_variables[entry['property']] = uuid[device_uuid]['variables'][entry['property']]
                    else:
                        raise Exception(f"{entry['variable']} is missing for template {uuid[device_uuid]['host_name']}")

I would be adding the elif:

 elif entry['property'] in uuid[device_uuid]['variables']:
                        device_template_variables[entry['property']] = uuid[device_uuid]['variables'][entry['property']]

What do you think about that?