From 4afd3b91708cb74139f2b8a93ab7a7efadc40360 Mon Sep 17 00:00:00 2001 From: Solvik Blum Date: Tue, 20 Aug 2019 17:27:31 +0200 Subject: [PATCH] pep8 fixes --- netbox_agent/inventory.py | 4 ++-- netbox_agent/raid/base.py | 12 ++++++------ netbox_agent/raid/dell.py | 11 ++++++++--- netbox_agent/raid/hp.py | 7 ++++++- 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/netbox_agent/inventory.py b/netbox_agent/inventory.py index 4c50e63..91f69e2 100644 --- a/netbox_agent/inventory.py +++ b/netbox_agent/inventory.py @@ -6,7 +6,6 @@ from netbox_agent.config import netbox_instance as nb from netbox_agent.misc import is_tool from netbox_agent.raid.hp import HPRaid from netbox_agent.raid.dell import StorcliRaid -import netbox_agent.dmidecode as dmidecode INVENTORY_TAG = { 'cpu': {'name': 'hw:cpu', 'slug': 'hw-cpu'}, @@ -67,7 +66,7 @@ class Inventory(): def create_netbox_cpus(self): nb_cpus, model = self.get_cpus() for i in range(nb_cpus): - cpu = nb.dcim.inventory_items.create( + _ = nb.dcim.inventory_items.create( device=self.device_id, tags=[INVENTORY_TAG['cpu']['name']], name=model, @@ -134,6 +133,7 @@ class Inventory(): name='{}'.format(raid_card.get_product_name()), serial='{}'.format(raid_card.get_serial_number()), ) + return nb_raid_card def create_netbox_raid_cards(self): for raid_card in self.get_raid_cards(): diff --git a/netbox_agent/raid/base.py b/netbox_agent/raid/base.py index 28c34bd..230756e 100644 --- a/netbox_agent/raid/base.py +++ b/netbox_agent/raid/base.py @@ -1,17 +1,17 @@ class RaidController(): def get_product_name(self): - raise NotImplemented + raise NotImplementedError def get_serial_number(self): - raise NotImplemented + raise NotImplementedError def get_manufacturer(self): - raise NotImplemented - + raise NotImplementedError + def get_firmware_version(self): - raise NotImplemented + raise NotImplementedError class Raid(): def get_controllers(self): - raise NotImplemented + raise NotImplementedError diff --git a/netbox_agent/raid/dell.py b/netbox_agent/raid/dell.py index 97697a8..26bdf05 100644 --- a/netbox_agent/raid/dell.py +++ b/netbox_agent/raid/dell.py @@ -3,6 +3,7 @@ import json from netbox_agent.raid.base import Raid, RaidController + class StorcliController(RaidController): def __init__(self, controller_index, data): self.data = data @@ -22,14 +23,18 @@ class StorcliController(RaidController): def get_physical_disks(self): ret = [] - output = subprocess.getoutput('storcli /c{}/eall/sall show all J'.format(self.controller_index)) + output = subprocess.getoutput( + 'storcli /c{}/eall/sall show all J'.format(self.controller_index) + ) drive_infos = json.loads(output)['Controllers'][self.controller_index]['Response Data'] for physical_drive in self.data['PD LIST']: enclosure = physical_drive.get('EID:Slt').split(':')[0] slot = physical_drive.get('EID:Slt').split(':')[1] size = physical_drive.get('Size').strip() - drive_identifier = 'Drive /c{}/e{}/s{}'.format(str(self.controller_index), str(enclosure), str(slot)) + drive_identifier = 'Drive /c{}/e{}/s{}'.format( + str(self.controller_index), str(enclosure), str(slot) + ) drive_attr = drive_infos['{} - Detailed Information'.format(drive_identifier)]\ ['{} Device attributes'.format(drive_identifier)] ret.append({ @@ -46,7 +51,7 @@ class StorcliRaid(Raid): self.controllers = [] if len([ - x for x in self.data['Controllers'] \ + x for x in self.data['Controllers'] if x['Command Status']['Status'] == 'Success' ]) > 0: for controller in self.data['Controllers']: diff --git a/netbox_agent/raid/hp.py b/netbox_agent/raid/hp.py index 9128765..991ef0d 100644 --- a/netbox_agent/raid/hp.py +++ b/netbox_agent/raid/hp.py @@ -5,10 +5,12 @@ from netbox_agent.raid.base import Raid, RaidController REGEXP_CONTROLLER_HP = re.compile(r'Smart Array ([a-zA-Z0-9- ]+) in Slot ([0-9]+)') + def _get_indentation(string): """Return the number of spaces before the current line.""" return len(string) - len(string.lstrip(' ')) + def _get_key_value(string): """Return the (key, value) as a tuple from a string.""" # Normally all properties look like this: @@ -36,6 +38,7 @@ def _get_key_value(string): return key.lstrip(' ').rstrip(' '), value.lstrip(' ').rstrip(' ') + def _get_dict(lines, start_index, indentation): """Recursive function for parsing hpssacli/ssacli output.""" @@ -85,6 +88,7 @@ def _get_dict(lines, start_index, indentation): return info, i + class HPRaidController(RaidController): def __init__(self, controller_name, data): self.controller_name = controller_name @@ -102,6 +106,7 @@ class HPRaidController(RaidController): def get_firmware_version(self): return self.data['Firmware Version'] + class HPRaid(Raid): def __init__(self): self.output = subprocess.getoutput('ssacli ctrl all show detail') @@ -119,7 +124,7 @@ class HPRaid(Raid): product_name = REGEXP_CONTROLLER_HP.search(_product_name) if product_name: self.controllers.append( - HPRaidController(product_name.group(1), info_dict[_product_name]) + HPRaidController(product_name.group(1), info_dict[_product_name]) ) def get_controllers(self):