From 29b0296ef0e38c860d8bdeeeccff77079d9e76cf Mon Sep 17 00:00:00 2001 From: "ricardo.bartels@telekom.de" Date: Wed, 20 Nov 2024 22:05:52 +0100 Subject: [PATCH] fixes typos --- module/common/cli_parser.py | 2 +- module/common/misc.py | 4 +-- module/common/support.py | 4 +-- module/netbox/connection.py | 20 ++++++------- module/netbox/inventory.py | 26 ++++++++-------- module/netbox/object_classes.py | 30 +++++++++---------- module/sources/__init__.py | 4 +-- .../sources/check_redfish/import_inventory.py | 4 +-- module/sources/common/excluded_vlan.py | 1 + module/sources/common/permitted_subnets.py | 2 +- module/sources/common/source_base.py | 14 ++++----- module/sources/vmware/connection.py | 30 +++++++++---------- 12 files changed, 71 insertions(+), 70 deletions(-) diff --git a/module/common/cli_parser.py b/module/common/cli_parser.py index 07d69ac..824f7fd 100644 --- a/module/common/cli_parser.py +++ b/module/common/cli_parser.py @@ -23,7 +23,7 @@ def parse_command_line(self_description=None): Parameters ---------- self_description: str - short self description of this program + short self-description of this program Returns ------- diff --git a/module/common/misc.py b/module/common/misc.py index e966a97..1302291 100644 --- a/module/common/misc.py +++ b/module/common/misc.py @@ -15,7 +15,7 @@ def grab(structure=None, path=None, separator=".", fallback=None): """ get data from a complex object/json structure with a "." separated path information. If a part of a path - is not not present then this function returns the + is not present then this function returns the value of fallback (default: "None"). example structure: @@ -38,7 +38,7 @@ def grab(structure=None, path=None, separator=".", fallback=None): Parameters ---------- structure: dict, list, object - object structure to extract data from + an object structure to extract data from path: str nested path to extract separator: str diff --git a/module/common/support.py b/module/common/support.py index 7fca9ae..8a3677d 100644 --- a/module/common/support.py +++ b/module/common/support.py @@ -51,9 +51,9 @@ def perform_ptr_lookups(ips, dns_servers=None): Parameters ---------- ips: list - list of IP addresses to look up + a list of IP addresses to look up dns_servers: list - list of DNS servers to use to look up list of IP addresses + a list of DNS servers to use to look up list of IP addresses Returns ------- diff --git a/module/netbox/connection.py b/module/netbox/connection.py index e1b943a..ccdc203 100644 --- a/module/netbox/connection.py +++ b/module/netbox/connection.py @@ -217,20 +217,20 @@ class NetBoxHandler: Parameters ---------- - object_class: NetBoxObject sub class + object_class: NetBoxObject subclass class definition of the desired NetBox object req_type: str GET, PATCH, PUT, DELETE data: dict - data which shall be send to NetBox + data which shall be sent to NetBox params: dict - dict of URL params which should be passed to NetBox + dictionary of URL params which should be passed to NetBox nb_id: int ID of the NetBox object which will be appended to the requested NetBox URL Returns ------- - (dict, bool, None): of returned NetBox data. If object was requested to be deleted and it was + dict, bool, None: of returned NetBox data. If object was requested to be deleted, and it was successful then True will be returned. None if request failed or was empty """ @@ -373,12 +373,12 @@ class NetBoxHandler: """ Request all current NetBox objects. Use caching whenever possible. Objects must provide "last_updated" attribute to support caching for this object type. - Otherwise it's not possible to query only changed objects since last run. If attribute is + Otherwise, it's not possible to query only changed objects since last run. If attribute is not present all objects will be requested (looking at you *Interfaces) Parameters ---------- - netbox_objects_to_query: list of NetBoxObject sub classes + netbox_objects_to_query: list of NetBoxObject subclasses NetBox items to query """ @@ -585,14 +585,14 @@ class NetBoxHandler: def update_object(self, nb_object_sub_class, unset=False, last_run=False): """ - Iterate over all objects of a certain NetBoxObject sub class and add/update them. + Iterate over all objects of a certain NetBoxObject subclass and add/update them. But first update objects which this object class depends on. If some dependencies are unresolvable then these will be removed from the request and re added later to the object to try update object in a third run. Parameters ---------- - nb_object_sub_class: NetBoxObject sub class + nb_object_sub_class: NetBoxObject subclass NetBox objects to update unset: bool True if only unset items should be deleted @@ -660,7 +660,7 @@ class NetBoxHandler: # special case for IP address if isinstance(this_object, NBIPAddress): - # if object is new and and has no id, then we need to remove assigned_object_type from data_to_patch + # if object is new and has no id, then we need to remove assigned_object_type from data_to_patch if "assigned_object_id" in unresolved_dependency_data.keys() and \ "assigned_object_type" in data_to_patch.keys(): del data_to_patch["assigned_object_type"] @@ -674,7 +674,7 @@ class NetBoxHandler: req_type = "POST" action = "Creating new" - # if its not a new object then update it + # if it's not a new object then update it if this_object.is_new is False: nb_id = this_object.nb_id req_type = "PATCH" diff --git a/module/netbox/inventory.py b/module/netbox/inventory.py index ab18d7d..d07ce98 100644 --- a/module/netbox/inventory.py +++ b/module/netbox/inventory.py @@ -19,7 +19,7 @@ log = get_logger() class NetBoxInventory: """ - Singleton class to manage a inventory of NetBoxObject objects + Singleton class to manage an inventory of NetBoxObject objects """ base_structure = dict() @@ -62,18 +62,18 @@ class NetBoxInventory: Parameters ---------- - object_type: NetBoxObject sub class + object_type: NetBoxObject subclass object type to find nb_id: int NetBox ID of object Returns ------- - (NetBoxObject sub class, None): return object instance if object was found, None otherwise + (NetBoxObject subclass, None): return object instance if object was found, None otherwise """ if object_type not in NetBoxObject.__subclasses__(): - raise AttributeError("'%s' object must be a sub class of '%s'." % + raise AttributeError("'%s' object must be a subclass of '%s'." % (object_type.__name__, NetBoxObject.__name__)) if nb_id is None or self.base_structure[object_type.name] is None: @@ -90,18 +90,18 @@ class NetBoxInventory: Parameters ---------- - object_type: NetBoxObject sub class + object_type: NetBoxObject subclass object type to find data: dict params of object to match Returns ------- - (NetBoxObject sub class, None): return object instance if object was found, None otherwise + (NetBoxObject subclass, None): return object instance if object was found, None otherwise """ if object_type not in NetBoxObject.__subclasses__(): - raise AttributeError("'%s' object must be a sub class of '%s'." % + raise AttributeError("'%s' object must be a subclass of '%s'." % (object_type.__name__, NetBoxObject.__name__)) if data is None or len(self.get_all_items(object_type)) == 0: @@ -169,7 +169,7 @@ class NetBoxInventory: """ if object_type not in NetBoxObject.__subclasses__(): - raise AttributeError("'%s' object must be a sub class of '%s'." % + raise AttributeError("'%s' object must be a subclass of '%s'." % (object_type.__name__, NetBoxObject.__name__)) if "slug" in object_type.data_model.keys(): @@ -185,7 +185,7 @@ class NetBoxInventory: Parameters ---------- - object_type: NetBoxObject sub class + object_type: NetBoxObject subclass object type to add data: dict Object data to add to the inventory @@ -216,10 +216,10 @@ class NetBoxInventory: Parameters ---------- - object_type: NetBoxObject sub class + object_type: NetBoxObject subclass object type to add/update data: dict - data used to create a new object or update a existing object + data used to create a new object or update an existing object read_from_netbox: bool True if data was read directly from NetBox source: object handler of source @@ -265,7 +265,7 @@ class NetBoxInventory: Parameters ---------- - object_type: NetBoxObject sub class + object_type: NetBoxObject subclass object type to find Returns @@ -274,7 +274,7 @@ class NetBoxInventory: """ if object_type not in NetBoxObject.__subclasses__(): - raise ValueError(f"'{object_type.__name__}' object must be a sub class of '{NetBoxObject.__name__}'.") + raise ValueError(f"'{object_type.__name__}' object must be a subclass of '{NetBoxObject.__name__}'.") return self.base_structure.get(object_type.name, list()) diff --git a/module/netbox/object_classes.py b/module/netbox/object_classes.py index dd84862..043180a 100644 --- a/module/netbox/object_classes.py +++ b/module/netbox/object_classes.py @@ -60,7 +60,7 @@ class NetBoxInterfaceType: "400gbase-x-osfp": 400_000 } - # assign common types for a interface speed value + # assign common types for an interface speed value common_types = { 100: "100base-tx", 1_000: "1000base-t", @@ -99,14 +99,14 @@ class NetBoxInterfaceType: Returns ------- valid_interface_types: list - list with valid types + a list with valid types """ return list(self.valid_types.keys()) def get_common_type(self) -> str: """ - return a interface type from the common type list + return an interface type from the common type list Returns ------- @@ -160,7 +160,7 @@ class NetBoxInterfaceType: Returns ------- human_speed: str - human readable string of interface speed + human-readable string of interface speed """ if self.detected_speed == 0: @@ -215,7 +215,7 @@ class NetBoxObject: """ Base class for all NetBox object types. Implements all methods used on a NetBox object. - Sub classes need to have following attributes: + subclasses need to have the following attributes: name: name of the object type (i.e. "virtual machine") api_path: @@ -244,14 +244,14 @@ class NetBoxObject: can be a string with an undefined length bool (class): attribute must be True or False - NetBoxObject sub class: + NetBoxObject subclass: value of this key is a reference to another NetBoxObject of exact defined type list (instance): - value can be one of the predefined values in that list - list of NetBoxObject sub classes: + value can be one of the predefined values in that list. + list of NetBoxObject subclasses: value must be an instance of predefined netBoxObject classes in list - NBObjectList sub class: - value mast be the defined sub class of NBObjectList + NBObjectList subclass: + value mast be the defined subclass of NBObjectList """ @@ -434,7 +434,7 @@ class NetBoxObject: new_slug = f"{slug}-{x}" if self.inventory.slug_used(self.__class__, new_slug) is False and len(new_slug) <= max_len: log.info(f"Slug '{slug}' for {self.name} '{text}' has been used. " - f"Assignin slug '{new_slug}'") + f"Assigning slug '{new_slug}'") return new_slug raise ValueError(f"Unable to find uniq slug for {self.name} '{text}'") @@ -750,7 +750,7 @@ class NetBoxObject: def resolve_relations(self): """ - Resolve object relations for this object. Substitute a dict of data with a id with the instantiated + Resolve object relations for this object. Substitute a dict of data with an id with the instantiated reference of this object """ @@ -810,11 +810,11 @@ class NetBoxObject: def get_dependencies(self): """ - returns a list of NetBoxObject sub classes this object depends on + returns a list of NetBoxObject subclasses this object depends on Returns ------- - list: of NetBoxObject sub classes + list: of NetBoxObject subclasses """ r = [x for x in self.data_model.values() if x in NetBoxObject.__subclasses__()] @@ -1168,7 +1168,7 @@ class NBObjectList(list): Base class of listed NetBox objects. Extends list(). Currently used for tags and untagged VLANs Mandatory attributes: - member_type: NetBoxObject sub class + member_type: NetBoxObject subclass defines the type objects contained in this type of list """ diff --git a/module/sources/__init__.py b/module/sources/__init__.py index dc2b7dc..cdb1f84 100644 --- a/module/sources/__init__.py +++ b/module/sources/__init__.py @@ -33,7 +33,7 @@ def validate_source(source_class_object=None, state="pre"): source_class_object: Source handler class/object class/object to investigate state: str - pre if validating a class, post if validating a initialized object + pre if validating a class, post if validating an initialized object """ @@ -70,7 +70,7 @@ def validate_source(source_class_object=None, state="pre"): def instantiate_sources(): """ Instantiate a source handler and add necessary attributes. Also - validate source handler pre and post initialization. + validate source handler on pre- and post-initialization. Returns ------- diff --git a/module/sources/check_redfish/import_inventory.py b/module/sources/check_redfish/import_inventory.py index 36cc53b..8427467 100644 --- a/module/sources/check_redfish/import_inventory.py +++ b/module/sources/check_redfish/import_inventory.py @@ -895,7 +895,7 @@ class CheckRedfish(SourceBase): Parameters ---------- items: list - list of items to update + a list of items to update Returns ------- @@ -974,7 +974,7 @@ class CheckRedfish(SourceBase): Parameters ---------- item_data: dict - dict with data for item to update + a dict with data for item to update inventory_object: NBInventoryItem, None the NetBox inventory item to update. diff --git a/module/sources/common/excluded_vlan.py b/module/sources/common/excluded_vlan.py index 40c16d3..99a9626 100644 --- a/module/sources/common/excluded_vlan.py +++ b/module/sources/common/excluded_vlan.py @@ -46,6 +46,7 @@ class ExcludedVLAN: return True # string or regex matches + # noinspection PyBroadException try: if ([self.site, site_name]).count(None) == 0 and re.search(f"^{self.site}$", site_name): log.debug2(f"VLAN exclude site name '{site_name}' matches '{self.site}'") diff --git a/module/sources/common/permitted_subnets.py b/module/sources/common/permitted_subnets.py index caffb5b..36412d3 100644 --- a/module/sources/common/permitted_subnets.py +++ b/module/sources/common/permitted_subnets.py @@ -16,7 +16,7 @@ log = get_logger() class PermittedSubnets: """ - initializes and verifies if an IP address is part of an permitted subnet + initializes and verifies if an IP address is part of a permitted subnet """ def __init__(self, config_string: str): diff --git a/module/sources/common/source_base.py b/module/sources/common/source_base.py index 86f06b8..d6e535c 100644 --- a/module/sources/common/source_base.py +++ b/module/sources/common/source_base.py @@ -60,7 +60,7 @@ class SourceBase: MAC address of interfaces match exactly, type of interface does not matter If there are interfaces which don't match at all then the unmatched interfaces will be - matched 1:1. Sort both lists (unmatched current interfaces, unmatched new new interfaces) + matched 1:1. Sort both lists (unmatched current interfaces, unmatched new interfaces) by name and assign them each other. eth0 > vNIC 1 @@ -80,7 +80,7 @@ class SourceBase: Returns ------- dict: {"$interface_name": associated_interface_object} - if no current current interface was left to match "None" will be returned instead of + if no current interface was left to match "None" will be returned instead of a matching interface object """ @@ -159,7 +159,7 @@ class SourceBase: if grab(matching_int, "data.name") in current_object_interface_names: current_object_interface_names.remove(grab(matching_int, "data.name")) - # no match found, we match the left overs just by #1 -> #1, #2 -> #2, ... + # no match found, we match the leftovers just by #1 -> #1, #2 -> #2, ... else: unmatched_interface_names.append(int_name) @@ -182,7 +182,7 @@ class SourceBase: def return_longest_matching_prefix_for_ip(self, ip_to_match=None, site_name=None): """ - This is a lazy approach to find longest matching prefix to an IP address. + This is a lazy approach to find the longest matching prefix to an IP address. If site_name is set only IP prefixes from that site are matched. Parameters @@ -254,7 +254,7 @@ class SourceBase: interface_data: dict dictionary with interface attributes to add to this interface interface_ips: list - list of ip addresses which are assigned to this interface + a list of ip addresses which are assigned to this interface vmware_object: (vim.HostSystem, vim.VirtualMachine) object to add to list of objects to reevaluate @@ -618,7 +618,7 @@ class SourceBase: Returns ------- data_to_update: dict - dict with data to append/patch + A dict with data to append/patch """ if overwrite is True: @@ -644,7 +644,7 @@ class SourceBase: Parameters ---------- vlan_data: dict - dict with NBVLAN data attributes + A dict with NBVLAN data attributes vlan_site: str name of site the VLAN could be present diff --git a/module/sources/vmware/connection.py b/module/sources/vmware/connection.py index f8f8bfd..66a0005 100644 --- a/module/sources/vmware/connection.py +++ b/module/sources/vmware/connection.py @@ -421,9 +421,9 @@ class VMWareHandler(SourceBase): name: str name of the object to check include_filter: regex object - regex object of include filter + A regex object of include filter exclude_filter: regex object - regex object of exclude filter + A regex object of exclude filter Returns ------- @@ -511,7 +511,7 @@ class VMWareHandler(SourceBase): object_type: (NBDevice, NBVM) type of NetBox device to find in inventory mac_list: list - list of MAC addresses to compare against NetBox interface objects + a list of MAC addresses to compare against NetBox interface objects Returns ------- @@ -710,7 +710,7 @@ class VMWareHandler(SourceBase): Returns ------- tag_list: list - list of NBTag objets retrieved from vCenter for this object + a list of NBTag objets retrieved from vCenter for this object """ if obj is None: @@ -960,7 +960,7 @@ class VMWareHandler(SourceBase): look for longest matching IP Prefix in the same site. If this failed we try to find the longest matching global IP Prefix. - If a IP Prefix was found then we try to get the VRF and VLAN for this prefix. Now we compare + If an IP Prefix was found then we try to get the VRF and VLAN for this prefix. Now we compare if interface VLAN and prefix VLAN match up and warn if they don't. Then we try to add data to the IP address if not already set: @@ -971,7 +971,7 @@ class VMWareHandler(SourceBase): And we also set primary IP4/6 for this object depending on the "set_primary_ip" setting. - If a IP address is set as primary IP for another device then using this IP on another + If an IP address is set as primary IP for another device then using this IP on another device will be rejected by NetBox. Setting "always": @@ -991,7 +991,7 @@ class VMWareHandler(SourceBase): Parameters ---------- object_type: (NBDevice, NBVM) - NetBoxObject sub class of object to add + NetBoxObject subclass of object to add object_data: dict data of object to add/update pnic_data: dict @@ -999,13 +999,13 @@ class VMWareHandler(SourceBase): vnic_data: dict data of virtual interfaces of this object, interface name as key nic_ips: dict - dict of ips per interface of this object, interface name as key + a dict of ips per interface of this object, interface name as key p_ipv4: str primary IPv4 as string including netmask/prefix p_ipv6: str primary IPv6 as string including netmask/prefix vmware_object: (vim.HostSystem, vim.VirtualMachine) - vmware object to pass on to 'add_update_interface' method to setup reevaluation + vmware object to pass on to 'add_update_interface' method to set up reevaluation disk_data: list data of discs which belong to a VM @@ -1121,7 +1121,7 @@ class VMWareHandler(SourceBase): object_type == NBVM and disk_data is not None and len(disk_data) > 0: # create pairs of existing and discovered disks. - # currently these disks are only used within the VM model. that's we we use this simple approach and + # currently these disks are only used within the VM model. that's why we use this simple approach and # just rewrite disk as they appear in order. # otherwise we would need to implement a matching function like matching interfaces. disk_zip_list = zip_longest( @@ -1301,7 +1301,7 @@ class VMWareHandler(SourceBase): Parameters ---------- obj: vim.Datacenter - datacenter object + a datacenter object """ if self.settings.set_source_name_as_cluster_group is True: @@ -2017,8 +2017,8 @@ class VMWareHandler(SourceBase): vnic_ips[vnic_name].append(int_v6) # set first valid IPv6 address as primary IPv6 - # not the best way but maybe we can find more information in "spec.ipRouteSpec" - # about default route and we could use that to determine the correct IPv6 address + # not the best way, but maybe we can find more information in "spec.ipRouteSpec" + # about default route, and we could use that to determine the correct IPv6 address if vnic_is_primary is True and host_primary_ip6 is None: host_primary_ip6 = int_v6 @@ -2034,10 +2034,10 @@ class VMWareHandler(SourceBase): Parse a vCenter VM add to NetBox once all data is gathered. VMs are parsed twice. First only "online" VMs are parsed and added. In the second - round also "offline" VMs will be parsed. This helps of VMs are cloned and used + round also "offline" VMs will be parsed. This helps if VMs are cloned and used for upgrades but then have the same name. - First VM is filtered: + First VM will be filtered: VM has a cluster and is it permitted was VM with same name and cluster already parsed does the VM pass the vm_include_filter and vm_exclude_filter