Skip to content

Commit 463589a

Browse files
committed
Updated command slcli image detail, added tables virtual disks and share image
1 parent 0e65657 commit 463589a

File tree

2 files changed

+55
-4
lines changed

2 files changed

+55
-4
lines changed

SoftLayer/CLI/image/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
MASK = ('id,accountId,name,globalIdentifier,parentId,publicFlag,flexImageFlag,'
77
'imageType')
88
DETAIL_MASK = MASK + (',firstChild,children[id,blockDevicesDiskSpaceTotal,datacenter,'
9-
'transaction[transactionGroup,transactionStatus]],'
10-
'note,createDate,status,transaction')
9+
'transaction[transactionGroup,transactionStatus],'
10+
'blockDevices[diskImage[capacity,name,units,softwareReferences[softwareDescription]],diskSpace]],'
11+
'note,createDate,status,transaction,accountReferences')
1112
PUBLIC_TYPE = formatting.FormattedItem('PUBLIC', 'Public')
1213
PRIVATE_TYPE = formatting.FormattedItem('PRIVATE', 'Private')

SoftLayer/CLI/image/detail.py

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ def cli(env, identifier):
4242
formatting.listing(_get_transaction_groups(children_images), separator=','),
4343
])
4444
table.add_row(['account', image.get('accountId', formatting.blank())])
45+
table.add_row(['created', image.get('createDate')])
46+
table.add_row(['total_size', formatting.b_to_gb(total_size)])
4547
table.add_row(['visibility',
4648
image_mod.PUBLIC_TYPE if image['publicFlag']
4749
else image_mod.PRIVATE_TYPE])
@@ -52,9 +54,9 @@ def cli(env, identifier):
5254
)])
5355
table.add_row(['flex', image.get('flexImageFlag')])
5456
table.add_row(['note', image.get('note')])
55-
table.add_row(['created', image.get('createDate')])
56-
table.add_row(['total_size', formatting.b_to_gb(total_size)])
5757
table.add_row(['datacenters', _get_datacenter_table(children_images)])
58+
table.add_row(['virtual disks', _get_virtual_disks(children_images)])
59+
table.add_row(['share image', _get_share_image(image)])
5860

5961
env.fout(table)
6062

@@ -85,3 +87,51 @@ def _get_transaction_groups(children_images):
8587
transactions.add(utils.lookup(child, 'transaction', 'transactionGroup', 'name'))
8688

8789
return transactions
90+
91+
92+
def _get_virtual_disks(children_images):
93+
"""Returns image details as datacenter, size, and transaction within a formatting table.
94+
95+
:param children_images: A list of images.
96+
"""
97+
98+
table_virtual_disks = formatting.Table(['Device', 'capacity', 'size on disk'])
99+
100+
if utils.lookup(children_images[0], 'blockDevices'):
101+
for block_devices in children_images[0]['blockDevices']:
102+
device_name = utils.lookup(block_devices, 'diskImage', 'name')
103+
software_references = utils.lookup(block_devices, 'diskImage', 'softwareReferences')
104+
if len(software_references) > 0:
105+
device_name = utils.lookup(software_references[0], 'softwareDescription', 'longDescription')
106+
107+
size_on_disk = formatting.b_to_gb(block_devices.get('diskSpace', 0))
108+
if block_devices.get('diskSpace', 0) == 0:
109+
size_on_disk = 'N/A'
110+
111+
capacity = str(utils.lookup(block_devices, 'diskImage', 'capacity')) + \
112+
' ' + utils.lookup(block_devices, 'diskImage', 'units')
113+
114+
table_virtual_disks.add_row([
115+
device_name,
116+
capacity,
117+
size_on_disk
118+
])
119+
120+
return table_virtual_disks
121+
122+
123+
def _get_share_image(image):
124+
"""Returns image details as datacenter, size, and transaction within a formatting table.
125+
126+
:param image: Detail information about image.
127+
"""
128+
table_share_account = formatting.Table(['Account', 'shared on'])
129+
if utils.lookup(image, 'accountReferences'):
130+
for account in image['accountReferences']:
131+
if account['accountId'] != image['accountId']:
132+
table_share_account.add_row([
133+
utils.lookup(account, 'accountId'),
134+
utils.lookup(account, 'createDate'),
135+
])
136+
137+
return table_share_account

0 commit comments

Comments
 (0)