netdevops / hier_config

Hierarchical Configuration
MIT License
126 stars 24 forks source link

Create a common base class for HConfig and HConfigChild #60

Closed aedwardstx closed 6 years ago

aedwardstx commented 6 years ago

Instead of HConfig using HConfigChild as a base class, which exposes some methods that are not relevant to HConfig objects, create a common base class that they each inherit.

In [2]: a = host.running_config

In [3]: root = a

In [4]: child = a.children[0]

In [5]: properties_of_root = set(dir(root))

In [6]: properties_of_child = set(dir(child))

In [7]: properties_of_root
Out[7]:
{'__bool__',
 '__class__',
 '__contains__',
 '__delattr__',
 '__dict__',
 '__dir__',
 '__doc__',
 '__eq__',
 '__format__',
 '__ge__',
 '__getattribute__',
 '__gt__',
 '__hash__',
 '__init__',
 '__init_subclass__',
 '__le__',
 '__len__',
 '__lt__',
 '__module__',
 '__ne__',
 '__new__',
 '__nonzero__',
 '__reduce__',
 '__reduce_ex__',
 '__repr__',
 '__setattr__',
 '__sizeof__',
 '__str__',
 '__subclasshook__',
 '__weakref__',
 '_add_acl_sequence_numbers',
 '_config_to_get_to_left',
 '_config_to_get_to_right',
 '_duplicate_child_allowed_check',
 '_explode_lineage_rule',
 '_host',
 '_lineage_eval_object_rules',
 '_lineage_eval_text_match_rules',
 '_logs',
 '_options',
 '_remove_acl_remarks',
 '_rm_ipv6_acl_sequence_numbers',
 'add_ancestor_copy_of',
 'add_child',
 'add_children',
 'add_deep_copy_of',
 'add_sectional_exiting',
 'add_shallow_copy_of',
 'add_tags',
 'all_children',
 'all_children_sorted',
 'all_children_sorted_by_tags',
 'all_children_sorted_untagged',
 'all_children_sorted_with_lineage_rules',
 'children',
 'children_dict',
 'config_to_get_to',
 'del_child',
 'del_child_by_text',
 'depth',
 'dump',
 'get_child',
 'get_child_deep',
 'get_children',
 'host',
 'lineage_test',
 'load_from_dump',
 'load_from_file',
 'load_from_string',
 'logs',
 'merge',
 'options',
 'real_indent_level',
 'rebuild_children_dict',
 'root',
 'set_order_weight',
 'to_tag_spec',
 'with_tags'}

In [8]: properties_of_child
Out[8]:
{'__bool__',
 '__class__',
 '__contains__',
 '__delattr__',
 '__dict__',
 '__dir__',
 '__doc__',
 '__eq__',
 '__format__',
 '__ge__',
 '__getattribute__',
 '__gt__',
 '__hash__',
 '__init__',
 '__init_subclass__',
 '__le__',
 '__len__',
 '__lt__',
 '__module__',
 '__ne__',
 '__new__',
 '__nonzero__',
 '__reduce__',
 '__reduce_ex__',
 '__repr__',
 '__setattr__',
 '__sizeof__',
 '__str__',
 '__subclasshook__',
 '__weakref__',
 '_config_to_get_to_left',
 '_config_to_get_to_right',
 '_default',
 '_duplicate_child_allowed_check',
 '_explode_lineage_rule',
 '_idempotent_acl_check',
 '_lineage_eval_object_rules',
 '_lineage_eval_text_match_rules',
 '_swap_negation',
 '_text',
 'add_child',
 'add_children',
 'add_deep_copy_of',
 'add_shallow_copy_of',
 'all_children',
 'all_children_sorted',
 'all_children_sorted_by_tags',
 'all_children_sorted_untagged',
 'ancestor_append_tags',
 'ancestor_remove_tags',
 'append_tags',
 'children',
 'children_dict',
 'cisco_style_text',
 'comments',
 'config_to_get_to',
 'deep_append_tags',
 'deep_remove_tags',
 'del_child',
 'del_child_by_text',
 'delete',
 'depth',
 'get_child',
 'get_child_deep',
 'get_children',
 'has_children',
 'host',
 'instances',
 'is_idempotent_command',
 'line_inclusion_test',
 'lineage',
 'lineage_test',
 'logs',
 'move',
 'negate',
 'new_in_config',
 'options',
 'order_weight',
 'overwrite_with',
 'parent',
 'path',
 'real_indent_level',
 'rebuild_children_dict',
 'remove_tags',
 'root',
 'sectional_overwrite_check',
 'sectional_overwrite_no_negate_check',
 'tags',
 'text',
 'to_tag_spec',
 'with_tags'}

In [9]: properties_of_root.difference(properties_of_child)
Out[9]:
{'_add_acl_sequence_numbers',
 '_host',
 '_logs',
 '_options',
 '_remove_acl_remarks',
 '_rm_ipv6_acl_sequence_numbers',
 'add_ancestor_copy_of',
 'add_sectional_exiting',
 'add_tags',
 'all_children_sorted_with_lineage_rules',
 'dump',
 'load_from_dump',
 'load_from_file',
 'load_from_string',
 'merge',
 'set_order_weight'}

In [10]: properties_of_child.difference(properties_of_root)
Out[10]:
{'_default',
 '_idempotent_acl_check',
 '_swap_negation',
 '_text',
 'ancestor_append_tags',
 'ancestor_remove_tags',
 'append_tags',
 'cisco_style_text',
 'comments',
 'deep_append_tags',
 'deep_remove_tags',
 'delete',
 'has_children',
 'instances',
 'is_idempotent_command',
 'line_inclusion_test',
 'lineage',
 'move',
 'negate',
 'new_in_config',
 'order_weight',
 'overwrite_with',
 'parent',
 'path',
 'remove_tags',
 'sectional_overwrite_check',
 'sectional_overwrite_no_negate_check',
 'tags',
 'text'}

In [11]: properties_of_child.intersection(properties_of_root)
Out[11]:
{'__bool__',
 '__class__',
 '__contains__',
 '__delattr__',
 '__dict__',
 '__dir__',
 '__doc__',
 '__eq__',
 '__format__',
 '__ge__',
 '__getattribute__',
 '__gt__',
 '__hash__',
 '__init__',
 '__init_subclass__',
 '__le__',
 '__len__',
 '__lt__',
 '__module__',
 '__ne__',
 '__new__',
 '__nonzero__',
 '__reduce__',
 '__reduce_ex__',
 '__repr__',
 '__setattr__',
 '__sizeof__',
 '__str__',
 '__subclasshook__',
 '__weakref__',
 '_config_to_get_to_left',
 '_config_to_get_to_right',
 '_duplicate_child_allowed_check',
 '_explode_lineage_rule',
 '_lineage_eval_object_rules',
 '_lineage_eval_text_match_rules',
 'add_child',
 'add_children',
 'add_deep_copy_of',
 'add_shallow_copy_of',
 'all_children',
 'all_children_sorted',
 'all_children_sorted_by_tags',
 'all_children_sorted_untagged',
 'children',
 'children_dict',
 'config_to_get_to',
 'del_child',
 'del_child_by_text',
 'depth',
 'get_child',
 'get_child_deep',
 'get_children',
 'host',
 'lineage_test',
 'logs',
 'options',
 'real_indent_level',
 'rebuild_children_dict',
 'root',
 'to_tag_spec',
 'with_tags'}