|
| 1 | +"""Get storage details for a hardware server.""" |
| 2 | +# :license: MIT, see LICENSE for more details. |
| 3 | + |
| 4 | +import click |
| 5 | + |
| 6 | +import SoftLayer |
| 7 | +from SoftLayer.CLI import environment |
| 8 | +from SoftLayer.CLI import formatting |
| 9 | +from SoftLayer.CLI import helpers |
| 10 | + |
| 11 | + |
| 12 | +@click.command() |
| 13 | +@click.argument('identifier') |
| 14 | +@environment.pass_env |
| 15 | +def cli(env, identifier): |
| 16 | + """Get storage details for a hardware server.""" |
| 17 | + |
| 18 | + hardware = SoftLayer.HardwareManager(env.client) |
| 19 | + hardware_id = helpers.resolve_id(hardware.resolve_ids, identifier, 'hardware') |
| 20 | + iscsi_storage_data = hardware.get_storage_details(hardware_id, "ISCSI") |
| 21 | + nas_storage_data = hardware.get_storage_details(hardware_id, "NAS") |
| 22 | + storage_credentials = hardware.get_storage_credentials(hardware_id) |
| 23 | + hard_drives = hardware.get_hard_drives(hardware_id) |
| 24 | + |
| 25 | + table_credentials = formatting.Table(['Username', 'Password', 'IQN'], title="Block Storage Details \n iSCSI") |
| 26 | + if storage_credentials: |
| 27 | + table_credentials.add_row([storage_credentials['credential']['username'], |
| 28 | + storage_credentials['credential']['password'], |
| 29 | + storage_credentials['name']]) |
| 30 | + |
| 31 | + table_iscsi = formatting.Table(['LUN name', 'capacity', 'Target address', 'Location', 'Notes']) |
| 32 | + for iscsi in iscsi_storage_data: |
| 33 | + table_iscsi.add_row([iscsi['username'], iscsi['capacityGb'], |
| 34 | + iscsi['serviceResourceBackendIpAddress'], |
| 35 | + iscsi['allowedHardware'][0]['datacenter']['longName'], |
| 36 | + iscsi.get('notes', None)]) |
| 37 | + |
| 38 | + table_nas = formatting.Table(['Volume name', 'capacity', 'Host Name', 'Location', 'Notes'], |
| 39 | + title="File Storage Details") |
| 40 | + for nas in nas_storage_data: |
| 41 | + table_nas.add_row([nas['username'], nas['capacityGb'], |
| 42 | + nas['serviceResourceBackendIpAddress'], |
| 43 | + nas['allowedHardware'][0]['datacenter']['longName'], |
| 44 | + nas.get('notes', None)]) |
| 45 | + |
| 46 | + table_hard_drives = formatting.Table(['Type', 'Name', 'Capacity', 'Serial #'], title="Other storage details") |
| 47 | + for drives in hard_drives: |
| 48 | + type_drive = drives['hardwareComponentModel']['hardwareGenericComponentModel']['hardwareComponentType']['type'] |
| 49 | + name = drives['hardwareComponentModel']['manufacturer'] + " " + drives['hardwareComponentModel']['name'] |
| 50 | + capacity = str(drives['hardwareComponentModel']['hardwareGenericComponentModel']['capacity']) + " " + str( |
| 51 | + drives['hardwareComponentModel']['hardwareGenericComponentModel']['units']) |
| 52 | + serial = drives['serialNumber'] |
| 53 | + |
| 54 | + table_hard_drives.add_row([type_drive, name, capacity, serial]) |
| 55 | + |
| 56 | + env.fout(table_credentials) |
| 57 | + env.fout(table_iscsi) |
| 58 | + env.fout(table_nas) |
| 59 | + env.fout(table_hard_drives) |
0 commit comments