diff options
author | Jeff Lane <jeffrey.lane@canonical.com> | 2015-08-18 14:57:25 -0400 |
---|---|---|
committer | Jeff Lane <jeffrey.lane@canonical.com> | 2015-08-18 14:57:25 -0400 |
commit | 89622e83cde8b494cc7d679380fcd2c00c9d9595 (patch) | |
tree | 238d12fff585fc5fa678f6694bd9b10bcd3ed198 | |
parent | fc0228be0111e0a9d9e3a5e159db424ecdeaefdf (diff) |
Replace disk/detect udev_resource call with a script that provides more info on detected disks
-rwxr-xr-x | bin/disk_info | 75 | ||||
-rw-r--r-- | jobs/disk.txt.in | 2 |
2 files changed, 76 insertions, 1 deletions
diff --git a/bin/disk_info b/bin/disk_info new file mode 100755 index 0000000..cbeaf6d --- /dev/null +++ b/bin/disk_info @@ -0,0 +1,75 @@ +#!/usr/bin/env python3 +""" +Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications +Industrial Technology Research Institute + +disk_info + Modified from the Open Compute Certification Suite tool + 1. Uses lshw command to gather disk information. + 2. The program will output: + Logical Name (sda, sdb) + Description + Vendor + Product + Size (in GB) + + +Authors + Nelson Chu <Nelson.Chu@itri.org.tw> + Jeff Lane <jeff@ubuntu.com> + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License version 3, +as published by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. + +""" + +import sys +import xml.etree.ElementTree as ET +from subprocess import Popen, PIPE + +def get_item(disk,attribute): + try: + attribute_name = disk.find(attribute).text + except AttributeError: + attribute_name = "Unknown" + + return attribute_name + +def main(): + command = 'lshw -xml' + hwinfo_xml = Popen(command, stdout=PIPE, stderr=PIPE, + shell=True).communicate()[0] + root = ET.fromstring(hwinfo_xml) + + # Parse lshw XML for gathering disk information. + disk_list = root.findall(".//node[@class='disk']") + + if not disk_list: + print("No disk information discovered.") + return 10 + + result = {} + for disk in disk_list: + if disk.get('id') == 'disk': + print("Name: {}".format(get_item(disk,'logicalname'))) + print("\t{k:15}\t{v}".format(k="Description:",v=get_item(disk,'description'))) + print("\t{k:15}\t{v}".format(k="Vendor:",v=get_item(disk,'vendor'))) + print("\t{k:15}\t{v}".format(k="Product:",v=get_item(disk,'product'))) + try: + disk_size = ("%dGB" % (int(disk.find('size').text) / (1000**3))) + except: + disk_size = "Unknown" + print("\t{k:15}\t{v}".format(k="Size:",v=disk_size)) + return 0 + +if __name__ == '__main__': + sys.exit(main()) diff --git a/jobs/disk.txt.in b/jobs/disk.txt.in index 446ce79..d91837a 100644 --- a/jobs/disk.txt.in +++ b/jobs/disk.txt.in @@ -1,7 +1,7 @@ plugin: shell id: disk/detect estimated_duration: 0.25 -command: udev_resource | filter_templates -w "category=DISK" | awk -F': ' '$1 == "product" { print $2 }' +command: disk_info _description: Detects and displays disks attached to the system. unit: template |