From 5d4c48736343a975f973bfb42780a11c596bd1e1 Mon Sep 17 00:00:00 2001 From: Noah Meyerhans Date: Thu, 30 Apr 2020 23:23:58 +0000 Subject: [PATCH] ebsnvme-id: fix flake8 warnings No functional changes Note that there are a few lines that still fail the "line too long" check, mostly due to comments or embedded human-readable text. In my opinion, fixing these errors had a negative impact on readability, so I left the lines in place and suppressed the warnings. Signed-off-by: Noah Meyerhans --- ebsnvme-id | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/ebsnvme-id b/ebsnvme-id index 88d3891..8716817 100755 --- a/ebsnvme-id +++ b/ebsnvme-id @@ -13,7 +13,8 @@ the volume. """ import argparse -from ctypes import * +from ctypes import Structure, c_uint8, c_uint16, \ + c_uint32, c_uint64, c_char, addressof, sizeof from fcntl import ioctl import sys @@ -22,6 +23,7 @@ NVME_IOCTL_ADMIN_CMD = 0xC0484E41 AMZN_NVME_VID = 0x1D0F AMZN_NVME_EBS_MN = "Amazon Elastic Block Store" + class nvme_admin_command(Structure): _pack_ = 1 _fields_ = [("opcode", c_uint8), # op code @@ -41,11 +43,13 @@ class nvme_admin_command(Structure): ("cdw15", c_uint32), ("reserved1", c_uint64)] + class nvme_identify_controller_amzn_vs(Structure): _pack_ = 1 _fields_ = [("bdev", c_char * 32), # block device name ("reserved0", c_char * (1024 - 32))] + class nvme_identify_controller_psd(Structure): _pack_ = 1 _fields_ = [("mp", c_uint16), # maximum power @@ -58,6 +62,7 @@ class nvme_identify_controller_psd(Structure): ("rwl", c_uint8), # relative write latency ("reserved1", c_char * 16)] + class nvme_identify_controller(Structure): _pack_ = 1 _fields_ = [("vid", c_uint16), # PCI Vendor ID @@ -77,7 +82,7 @@ class nvme_identify_controller(Structure): ("lpa", c_uint8), # Log Page Attributes ("elpe", c_uint8), # Error Log Page Entries ("npss", c_uint8), # Number of Power States Support - ("avscc", c_uint8), # Admin Vendor Specific Command Configuration + ("avscc", c_uint8), # Admin Vendor Specific Command Configuration # noqa ("reserved1", c_uint8 * (512 - 265)), ("sqes", c_uint8), # Submission Queue Entry Size ("cqes", c_uint8), # Completion Queue Entry Size @@ -89,22 +94,23 @@ class nvme_identify_controller(Structure): ("vwc", c_uint8), # Volatile Write Cache ("awun", c_uint16), # Atomic Write Unit Normal ("awupf", c_uint16), # Atomic Write Unit Power Fail - ("nvscc", c_uint8), # NVM Vendor Specific Command Configuration + ("nvscc", c_uint8), # NVM Vendor Specific Command Configuration # noqa ("reserved3", c_uint8 * (704 - 531)), ("reserved4", c_uint8 * (2048 - 704)), - ("psd", nvme_identify_controller_psd * 32), # Power State Descriptor + ("psd", nvme_identify_controller_psd * 32), # Power State Descriptor # noqa ("vs", nvme_identify_controller_amzn_vs)] # Vendor Specific + class ebs_nvme_device: def __init__(self, device): self.device = device self.ctrl_identify() def _nvme_ioctl(self, id_response, id_len): - admin_cmd = nvme_admin_command(opcode = NVME_ADMIN_IDENTIFY, - addr = id_response, - alen = id_len, - cdw10 = 1) + admin_cmd = nvme_admin_command(opcode=NVME_ADMIN_IDENTIFY, + addr=id_response, + alen=id_len, + cdw10=1) with open(self.device, "r+") as nvme: ioctl(nvme, NVME_IOCTL_ADMIN_CMD, admin_cmd) @@ -113,8 +119,9 @@ class ebs_nvme_device: self.id_ctrl = nvme_identify_controller() self._nvme_ioctl(addressof(self.id_ctrl), sizeof(self.id_ctrl)) - if self.id_ctrl.vid != AMZN_NVME_VID or self.id_ctrl.mn.decode().strip() != AMZN_NVME_EBS_MN: - raise TypeError("[ERROR] Not an EBS device: '{0}'".format(self.device)) + if self.id_ctrl.vid != AMZN_NVME_VID \ + or self.id_ctrl.mn.decode().strip() != AMZN_NVME_EBS_MN: + raise TypeError("[ERROR] Not an EBS device: '{0}'".format(self.device)) # noqa def get_volume_id(self): vol = self.id_ctrl.sn.decode() @@ -132,17 +139,19 @@ class ebs_nvme_device: return dev + if __name__ == "__main__": - parser = argparse.ArgumentParser(description="Reads EBS information from NVMe devices.") + parser = \ + argparse.ArgumentParser(description="Reads EBS information from NVMe devices.") # noqa parser.add_argument("device", nargs=1, help="Device to query") display = parser.add_argument_group("Display Options") display.add_argument("-v", "--volume", action="store_true", - help="Return volume-id") + help="Return volume-id") display.add_argument("-b", "--block-dev", action="store_true", - help="Return block device mapping") + help="Return block device mapping") display.add_argument("-u", "--udev", action="store_true", - help="Output data in format suitable for udev rules") + help="Output data in format suitable for udev rules") if len(sys.argv) < 2: parser.print_help()