Skip to content

Conversation

@glennmatthews
Copy link
Collaborator

  • Replace all print_detailed APIs with str() methods (not __str__(), as we already have that for these classes, and these methods produce a verbose string rather than a brief description as __str__ does)
  • DSyncModel's dict() and json() APIs (inherited from Pydantic) now by default exclude the dsync field as it's not serializable.
  • Added dict() APIs on DSync, Diff, and DiffElement, for use in debugging and in serialization
  • Unfortunately, having dict() and str() APIs on classes prevents us from using them in type hints - mypy is smart enough to handle this just fine, but pylint started raising used-before-assignment errors, so I've had to replace various dict/str type hints with Dict, Mapping and/or Text types in a number of places.
  • Reworked the format of the dict returned by DiffElement's get_attrs_diffs() API so that it produces a dict of the form {src: {key1: value1, key2, value2}, dst: {key1: value1, key2: value2}} instead of the previous {key1: {src: value1, dst: value1}, key2: {src: value2, dst: value2}}, mostly for aesthetic/readability reasons.

Example output of the str() and dict() methods are encoded in the new unit test cases, but here's an example of dict output from a Diff:

{'location': {'ATL': {'_dst': {},
                      '_src': {'parent_location_name': 'USA',
                               'status': 'active'},
                      'device': {'atl-csr1': {'_dst': {},
                                              '_src': {'location_name': 'ATL',
                                                       'model': 'CSR1000v',
                                                       'platform': None,
                                                       'role': 'Router',
                                                       'status': 'active',
                                                       'vendor': 'Cisco'},
                                              'interface': {'GigabitEthernet1': {'_dst': {},
                                                                                 '_src': {'access_vlan': None,
                                                                                          'active': None,
                                                                                          'allowed_vlans': [],
                                                                                          'description': '',
                                                                                          'is_lag': False,
                                                                                          'is_lag_member': False,
                                                                                          'is_virtual': False,
                                                                                          'lag_members': [],
                                                                                          'mode': 'L3_SUB_VLAN',
                                                                                          'mtu': 9000,
                                                                                          'parent': None,
                                                                                          'speed': None,
                                                                                          'switchport_mode': 'NONE'}},
                                                            'GigabitEthernet2': {'_dst': {},
                                                                                 '_src': {'access_vlan': None,
                                                                                          'active': None,
                                                                                          'allowed_vlans': [],
                                                                                          'description': '',
                                                                                          'is_lag': False,
                                                                                          'is_lag_member': False,
                                                                                          'is_virtual': False,
                                                                                          'lag_members': [],
                                                                                          'mode': 'L3_SUB_VLAN',
                                                                                          'mtu': 9000,
                                                                                          'parent': None,
                                                                                          'speed': None,
                                                                                          'switchport_mode': 'NONE'}},
                                                            'GigabitEthernet3': {'_dst': {},
                                                                                 '_src': {'access_vlan': None,
                                                                                          'active': None,
                                                                                          'allowed_vlans': [],
                                                                                          'description': '',
                                                                                          'is_lag': False,
                                                                                          'is_lag_member': False,
                                                                                          'is_virtual': False,
                                                                                          'lag_members': [],
                                                                                          'mode': 'L3_SUB_VLAN',
                                                                                          'mtu': 9000,
                                                                                          'parent': None,
                                                                                          'speed': None,
                                                                                          'switchport_mode': 'NONE'}}}}}},
              'LON': {'_dst': {},
                      '_src': {'parent_location_name': None,
                               'status': 'active'}},
              'NYC': {'_dst': {},
                      '_src': {'parent_location_name': 'USA',
                               'status': 'planned'}},
              'RDU': {'_dst': {},
                      '_src': {'parent_location_name': 'USA',
                               'status': 'active'},
                      'device': {'rdu-n9kv1': {'_dst': {},
                                               '_src': {'location_name': 'RDU',
                                                        'model': 'Nexus 9000v',
                                                        'platform': None,
                                                        'role': 'Switch',
                                                        'status': 'active',
                                                        'vendor': 'Cisco'}}}},
              'USA': {'_dst': {},
                      '_src': {'parent_location_name': None, 'status': None}}}}

@glennmatthews
Copy link
Collaborator Author

Fixes #22.

Copy link
Contributor

@dgarros dgarros left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants