diff options
author | Jeff Lane <jeffrey.lane@canonical.com> | 2015-08-19 08:54:26 +0000 |
---|---|---|
committer | Daniel Manrique <> | 2015-08-19 08:54:26 +0000 |
commit | 0a7f5180e75f8b13630df7b42fffe261a5a2cb33 (patch) | |
tree | ba2d922668a318b260d10893abbbf3cdc4f7330a | |
parent | 3321de1a9ee6131bf085d38ab4eb3542bd2685b0 (diff) | |
parent | 257077b625c7a6e2cab87f01adbc2ba9f86e8f98 (diff) |
"automatic merge of lp:~bladernr/checkbox/checkbox-replace-disk-detect/ by tarmac [r=zyga][bug=1483829][author=bladernr]"
-rwxr-xr-x | bin/disk_info | 72 | ||||
-rw-r--r-- | jobs/disk.txt.in | 8 |
2 files changed, 79 insertions, 1 deletions
diff --git a/bin/disk_info b/bin/disk_info new file mode 100755 index 0000000..d32bc13 --- /dev/null +++ b/bin/disk_info @@ -0,0 +1,72 @@ +#!/usr/bin/env python3 +# +# This file is part of Checkbox. +# +# Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications +# Industrial Technology Research Institute +# +# Authors: +# Nelson Chu <Nelson.Chu@itri.org.tw> +# Jeff Lane <jeff@ubuntu.com> +# +# Checkbox 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. +# +# Checkbox 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 Checkbox. If not, see <http://www.gnu.org/licenses/>. +""" +disk_info + +Uses lshw to gather information about disks seen by the OS. +Outputs logical name, vendor, description, size and product data +""" + +import sys +import xml.etree.ElementTree as ET +from subprocess import check_output + + +def get_item(disk, attribute): + try: + return disk.find(attribute).text + except AttributeError: + return "Unknown" + + +def main(): + hwinfo_xml = check_output(['lshw', '-c', 'disk', '-xml']) + 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 + + 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 TypeError: + 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..33a6dbc 100644 --- a/jobs/disk.txt.in +++ b/jobs/disk.txt.in @@ -1,7 +1,13 @@ +# This is for bin/disk_info +unit: packaging meta-data +os-id: debian +Depends: lshw + plugin: shell id: disk/detect estimated_duration: 0.25 -command: udev_resource | filter_templates -w "category=DISK" | awk -F': ' '$1 == "product" { print $2 }' +user: root +command: disk_info _description: Detects and displays disks attached to the system. unit: template |