Skip to content

Commit

Permalink
blacken
Browse files Browse the repository at this point in the history
  • Loading branch information
ITJamie committed Aug 22, 2022
1 parent ffab4a4 commit 1324765
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
1 change: 0 additions & 1 deletion development/check_if_nb_api_up.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,3 @@
print("netbox not yet up. sleeping for 10s and trying again")
current_attempts = current_attempts + 1
sleep(10)

39 changes: 19 additions & 20 deletions rt2nb/racktables2netbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ def create_device_interfaces(self, dev_id, dev_ints, ip_ints, force_int_type=Fal
logger.debug("attempting to assign ip")
print(nb_ip.update(ip_update))
else:
split_ip = ip.split('/')[0]
split_ip = ip.split("/")[0]
nb_ip2 = self.py_netbox.ipam.ip_addresses.get(address=split_ip)
if nb_ip2:
logger.debug("attempting to assign ip. found by removing /")
Expand Down Expand Up @@ -1274,7 +1274,7 @@ def remove_device_by_rt_id(self, rt_id):

except:
logger.info("failed to find / remove device from netbox")

def get_ip_prefix_size(self, ip):
nb = self.py_netbox
if not netbox.all_prefixes:
Expand All @@ -1297,10 +1297,10 @@ def get_ip_prefix_size(self, ip):
return smallest_prefix
else:
return None

def update_object_file_links(self, object_type, object_id, file_links):
nb = self.py_netbox
update_data = {"custom_fields":{"external_urls": file_links}}
update_data = {"custom_fields": {"external_urls": file_links}}
if object_type == "object":
# might be device or vm
print(f"checking for device via rt_dev_id:{object_id}")
Expand All @@ -1326,7 +1326,7 @@ def update_object_file_links(self, object_type, object_id, file_links):
nb_rack.update(update_data)
else:
dev_type = object_type

print(dev_type)


Expand Down Expand Up @@ -1467,7 +1467,7 @@ def get_ips(self):
found_prefix = prefix
print(f"prefix to be used: {found_prefix}")
if smallest_prefix > 0:
net['address'] = f"{ip}/{smallest_prefix}"
net["address"] = f"{ip}/{smallest_prefix}"
# net['display'] = net['address']
found_in_nb = False
found_in_nb_obj = None
Expand Down Expand Up @@ -1513,7 +1513,7 @@ def get_ips(self):
found_prefix = prefix
print(f"prefix to be used: {found_prefix}")
if smallest_prefix > 0:
net['address'] = f"{ip}/{smallest_prefix}"
net["address"] = f"{ip}/{smallest_prefix}"
# net['display'] = net['address']
found_in_nb = False
found_in_nb_obj = None
Expand Down Expand Up @@ -1599,7 +1599,7 @@ def get_ips_v6(self):
found_prefix = prefix
print(f"prefix to be used: {found_prefix}")
if smallest_prefix > 0:
net['address'] = f"{ip}/{smallest_prefix}"
net["address"] = f"{ip}/{smallest_prefix}"
# net['display'] = net['address']
found_in_nb = False
found_in_nb_obj = None
Expand Down Expand Up @@ -1640,7 +1640,7 @@ def get_ips_v6(self):
found_prefix = prefix
print(f"prefix to be used: {found_prefix}")
if smallest_prefix > 0:
net['address'] = f"{ip}/{smallest_prefix}"
net["address"] = f"{ip}/{smallest_prefix}"
# net['display'] = net['address']
found_in_nb = False
found_in_nb_obj = None
Expand Down Expand Up @@ -1904,7 +1904,7 @@ def get_custom_attribs(self):
attributes.append({"name": "Visible label", "type": "text"})
attributes.append({"name": "SW type", "type": "text"})
attributes.append({"name": "Operating System", "type": "text"})
attributes.append({"name": "External URLs", "type": "longtext"})
attributes.append({"name": "External URLs", "type": "longtext"})

netbox.createCustomFields(attributes)

Expand Down Expand Up @@ -2684,7 +2684,7 @@ def process_data(self, data, dev_id):
attrib_value,
attrib_type,
has_problems,
object_class_type
object_class_type,
) = x
logger.debug(x)
if rdesc is None:
Expand Down Expand Up @@ -2872,7 +2872,7 @@ def process_data(self, data, dev_id):
if not "site" in devicedata.keys():
netbox_sites_by_comment = netbox.get_sites_keyd_by_description()
devicedata["site"] = netbox_sites_by_comment[rlocation_name]["id"]

devicedata["device_role"] = self.nb_role_id(object_class_type)

if not "hardware" in devicedata.keys():
Expand Down Expand Up @@ -3253,7 +3253,7 @@ def get_pdus(self):
rack_id = rack_data["id"]
# pp.pprint(dict(rack_data))
pdudata["rack"] = rack_id

if rack_data["location"]["id"]:
rack_location = rack_data["location"]["id"]
else:
Expand Down Expand Up @@ -3667,7 +3667,6 @@ def get_vms(self):
netbox.create_device_interfaces(id, ports, ip_ints, True, "virtual")
logger.debug(f"end of vm: {id} {name}")


def get_files(self):
if not self.con:
self.connect()
Expand Down Expand Up @@ -3708,15 +3707,15 @@ def get_files(self):
print("file already exists")
else:
print("writing file")
f = open(current_file, 'wb')
f = open(current_file, "wb")
f.write(file_content)
f.close()
entity = f"{entity_type}_{entity_id}"
print(entity)
if not entity in entity_links.keys():
entity_links[entity] = []
entity_links[entity].append(file_link_data)

for entity, entity_data in entity_links.items():
entity_comment_data = ""
if len(entity_data) > 1:
Expand All @@ -3725,16 +3724,16 @@ def get_files(self):
else:
print("I have only one file attached")
for linkdata in entity_data:
filename = linkdata['export_file_name'].split("file_exports/")[1]
filename = linkdata["export_file_name"].split("file_exports/")[1]
description = f"external_file: {linkdata['file_name']}"
if not linkdata['file_comment'] == "":
if not linkdata["file_comment"] == "":
comment = f"\n\n{linkdata['file_comment']}"
else:
comment = ""
entity_comment_data = entity_comment_data + f"\n\n[{description}]({config['Misc']['FILE_SEARCH_URI']}{urllib.parse.quote(filename)}){comment}"
entity_comment_data = entity_comment_data.strip("\n\n")
print(entity_comment_data)
update_device = netbox.update_object_file_links(linkdata['entity_type'],linkdata['entity_id'],entity_comment_data )
update_device = netbox.update_object_file_links(linkdata["entity_type"], linkdata["entity_id"], entity_comment_data)
print("")


Expand Down Expand Up @@ -3828,7 +3827,7 @@ def get_files(self):
racktables.get_patch_panels()
if config["Migrate"]["VMS"] == True:
racktables.get_vms()
if config["Migrate"]["FILES"] == True:
if config["Migrate"]["FILES"] == True:
racktables.get_files()

migrator = Migrator()
Expand Down

0 comments on commit 1324765

Please sign in to comment.