-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update smartctl.py #46
base: master
Are you sure you want to change the base?
Conversation
Try to add hard raid support for smartctl.py Signed-off-by: 1234Erwan <84467245+1234Erwan@users.noreply.github.com>
Signed-off-by: 1234Erwan <84467245+1234Erwan@users.noreply.github.com>
Hey thanks a lot for your contribution! We'll review your PR ASAP 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thx a lot for your PR. I added some comments.
@@ -14,32 +14,47 @@ def _list_disks(): | |||
disks = [] | |||
result = run_command(['smartctl', '--scan']) | |||
for line in result['stdout'].splitlines(): | |||
if line.startswith('/dev/') and not line.startswith('/dev/bus/'): | |||
disks.append(line.split()[0]) | |||
disks.append(line.split()[0]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that you can get the type of the disk here. No need to an extra function _list_raids.
Maybe return a tuple here with line.split()[0] and line.split()[2]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'v tryed te solve that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the most readable way to do that is to use a dict. For example you can do:
devices.append({'name': line.split()[0], 'type': line.split()[2]})
By doing this way we know what is expecting and when calling the smartctl
later in the code you won't need the index you will be able to use the explicit field.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that I used devices
here because it looks like it is closer from the man page of the smartctl and IMHO we are getting the device name and the device type so it looks better :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And also renamed _list_disks
into _list_devices
if you decide to rename it.
return disks | ||
|
||
@error_wrapped | ||
def _list_raids(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it looks like you are getting the type. It is not specifically for raids. And I think that this function is not needed because we are already doing the scan in _list_disks(). See my previous comment
@error_wrapped | ||
def get_information(session, args): | ||
results = {} | ||
raids = {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not needed if disks holds a tuple with device and type
with OperationLocker(): | ||
disks = _list_disks() | ||
raids = _list_raids() | ||
for disk in disks: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here you can get disk, disk_type from disks if it holds the tuple
Removed unnecessary lines from smartctl.py Signed-off-by: 1234Erwan <84467245+1234Erwan@users.noreply.github.com>
I thought about a solution like this instead of managing an index.
|
How do we move on on this PR? |
@
I think that managing index is error prone and IMHO using the solution I posted looks better but I don't have a strong opinion so if it is ok for you we can merge it and fix it later. @1234Erwan what do you think? |
Try to add hard raid support for smartctl.py