Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions SoftLayer/CLI/hardware/detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,23 @@ def cli(env, identifier, passwords, price):
hardware_id = helpers.resolve_id(hardware.resolve_ids, identifier, 'hardware')
result = hardware.get_hardware(hardware_id)
result = utils.NestedDict(result)
hard_drives = hardware.get_hard_drives(hardware_id)

operating_system = utils.lookup(result, 'operatingSystem', 'softwareLicense', 'softwareDescription') or {}
memory = formatting.gb(result.get('memoryCapacity', 0))
owner = None
if utils.lookup(result, 'billingItem') != []:
owner = utils.lookup(result, 'billingItem', 'orderItem', 'order', 'userRecord', 'username')

table_hard_drives = formatting.Table(['Name', 'Capacity', 'Serial #'])
for drives in hard_drives:
name = drives['hardwareComponentModel']['manufacturer'] + " " + drives['hardwareComponentModel']['name']
capacity = str(drives['hardwareComponentModel']['hardwareGenericComponentModel']['capacity']) + " " + str(
drives['hardwareComponentModel']['hardwareGenericComponentModel']['units'])
serial = drives['serialNumber']

table_hard_drives.add_row([name, capacity, serial])

table.add_row(['id', result['id']])
table.add_row(['guid', result['globalIdentifier'] or formatting.blank()])
table.add_row(['hostname', result['hostname']])
Expand All @@ -43,6 +53,7 @@ def cli(env, identifier, passwords, price):
table.add_row(['datacenter', result['datacenter']['name'] or formatting.blank()])
table.add_row(['cores', result['processorPhysicalCoreAmount']])
table.add_row(['memory', memory])
table.add_row(['drives', table_hard_drives])
table.add_row(['public_ip', result['primaryIpAddress'] or formatting.blank()])
table.add_row(['private_ip', result['primaryBackendIpAddress'] or formatting.blank()])
table.add_row(['ipmi_ip', result['networkManagementIpAddress'] or formatting.blank()])
Expand Down
59 changes: 59 additions & 0 deletions SoftLayer/CLI/hardware/storage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
"""Get storage details for a hardware server."""
# :license: MIT, see LICENSE for more details.

import click

import SoftLayer
from SoftLayer.CLI import environment
from SoftLayer.CLI import formatting
from SoftLayer.CLI import helpers


@click.command()
@click.argument('identifier')
@environment.pass_env
def cli(env, identifier):
"""Get storage details for a hardware server."""

hardware = SoftLayer.HardwareManager(env.client)
hardware_id = helpers.resolve_id(hardware.resolve_ids, identifier, 'hardware')
iscsi_storage_data = hardware.get_storage_details(hardware_id, "ISCSI")
nas_storage_data = hardware.get_storage_details(hardware_id, "NAS")
storage_credentials = hardware.get_storage_credentials(hardware_id)
hard_drives = hardware.get_hard_drives(hardware_id)

table_credentials = formatting.Table(['Username', 'Password', 'IQN'], title="Block Storage Details \n iSCSI")
if storage_credentials:
table_credentials.add_row([storage_credentials['credential']['username'],
storage_credentials['credential']['password'],
storage_credentials['name']])

table_iscsi = formatting.Table(['LUN name', 'capacity', 'Target address', 'Location', 'Notes'])
for iscsi in iscsi_storage_data:
table_iscsi.add_row([iscsi['username'], iscsi['capacityGb'],
iscsi['serviceResourceBackendIpAddress'],
iscsi['allowedHardware'][0]['datacenter']['longName'],
iscsi.get('notes', None)])

table_nas = formatting.Table(['Volume name', 'capacity', 'Host Name', 'Location', 'Notes'],
title="File Storage Details")
for nas in nas_storage_data:
table_nas.add_row([nas['username'], nas['capacityGb'],
nas['serviceResourceBackendIpAddress'],
nas['allowedHardware'][0]['datacenter']['longName'],
nas.get('notes', None)])

table_hard_drives = formatting.Table(['Type', 'Name', 'Capacity', 'Serial #'], title="Other storage details")
for drives in hard_drives:
type_drive = drives['hardwareComponentModel']['hardwareGenericComponentModel']['hardwareComponentType']['type']
name = drives['hardwareComponentModel']['manufacturer'] + " " + drives['hardwareComponentModel']['name']
capacity = str(drives['hardwareComponentModel']['hardwareGenericComponentModel']['capacity']) + " " + str(
drives['hardwareComponentModel']['hardwareGenericComponentModel']['units'])
serial = drives['serialNumber']

table_hard_drives.add_row([type_drive, name, capacity, serial])

env.fout(table_credentials)
env.fout(table_iscsi)
env.fout(table_nas)
env.fout(table_hard_drives)
2 changes: 2 additions & 0 deletions SoftLayer/CLI/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
('virtual:ready', 'SoftLayer.CLI.virt.ready:cli'),
('virtual:reboot', 'SoftLayer.CLI.virt.power:reboot'),
('virtual:reload', 'SoftLayer.CLI.virt.reload:cli'),
('virtual:storage', 'SoftLayer.CLI.virt.storage:cli'),
('virtual:upgrade', 'SoftLayer.CLI.virt.upgrade:cli'),
('virtual:usage', 'SoftLayer.CLI.virt.usage:cli'),
('virtual:credentials', 'SoftLayer.CLI.virt.credentials:cli'),
Expand Down Expand Up @@ -248,6 +249,7 @@
('hardware:ready', 'SoftLayer.CLI.hardware.ready:cli'),
('hardware:toggle-ipmi', 'SoftLayer.CLI.hardware.toggle_ipmi:cli'),
('hardware:dns-sync', 'SoftLayer.CLI.hardware.dns:cli'),
('hardware:storage', 'SoftLayer.CLI.hardware.storage:cli'),

('securitygroup', 'SoftLayer.CLI.securitygroup'),
('securitygroup:list', 'SoftLayer.CLI.securitygroup.list:cli'),
Expand Down
20 changes: 20 additions & 0 deletions SoftLayer/CLI/virt/detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ def cli(env, identifier, passwords=False, price=False):
vs_id = helpers.resolve_id(vsi.resolve_ids, identifier, 'VS')
result = vsi.get_instance(vs_id)
result = utils.NestedDict(result)
local_disks = vsi.get_local_disks(vs_id)

table_local_disks = formatting.Table(['Type', 'Name', 'Capacity'])
for disks in local_disks:
if 'diskImage' in disks:
table_local_disks.add_row([get_local_type(disks), disks['mountType'],
str(disks['diskImage']['capacity']) + " " + str(disks['diskImage']['units'])])

table.add_row(['id', result['id']])
table.add_row(['guid', result['globalIdentifier']])
Expand All @@ -57,6 +64,7 @@ def cli(env, identifier, passwords=False, price=False):
table.add_row(['os_version', operating_system.get('version', '-')])
table.add_row(['cores', result['maxCpu']])
table.add_row(['memory', formatting.mb_to_gb(result['maxMemory'])])
table.add_row(['drives', table_local_disks])
table.add_row(['public_ip', result.get('primaryIpAddress', '-')])
table.add_row(['private_ip', result.get('primaryBackendIpAddress', '-')])
table.add_row(['private_only', result['privateNetworkOnlyFlag']])
Expand Down Expand Up @@ -192,3 +200,15 @@ def _get_security_table(result):
return secgroup_table
else:
return None


def get_local_type(disks):
"""Returns the virtual server local disk type.

:param disks: virtual serve local disks.
"""
disk_type = 'System'
if 'SWAP' in disks['diskImage']['description']:
disk_type = 'Swap'

return disk_type
73 changes: 73 additions & 0 deletions SoftLayer/CLI/virt/storage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
"""Get storage details for a virtual server."""
# :license: MIT, see LICENSE for more details.

import click

import SoftLayer
from SoftLayer.CLI import environment
from SoftLayer.CLI import formatting
from SoftLayer.CLI import helpers


@click.command()
@click.argument('identifier')
@environment.pass_env
def cli(env, identifier):
"""Get storage details for a virtual server."""

vsi = SoftLayer.VSManager(env.client)
vsi_id = helpers.resolve_id(vsi.resolve_ids, identifier, 'VS')
iscsi_storage_data = vsi.get_storage_details(vsi_id, "ISCSI")
nas_storage_data = vsi.get_storage_details(vsi_id, "NAS")
storage_credentials = vsi.get_storage_credentials(vsi_id)
portable_storage = vsi.get_portable_storage(vsi_id)
local_disks = vsi.get_local_disks(vsi_id)

table_credentials = formatting.Table(['Username', 'Password', 'IQN'], title="Block Storage Details \n iSCSI")
if storage_credentials:
table_credentials.add_row([storage_credentials['credential']['username'],
storage_credentials['credential']['password'],
storage_credentials['name']])

table_iscsi = formatting.Table(['LUN name', 'capacity', 'Target address', 'Location', 'Notes'])
for iscsi in iscsi_storage_data:
table_iscsi.add_row([iscsi['username'], iscsi['capacityGb'],
iscsi['serviceResourceBackendIpAddress'],
iscsi['allowedVirtualGuests'][0]['datacenter']['longName'],
iscsi.get('notes', None)])

table_portable = formatting.Table(['Description', 'Capacity'], title="Portable Storage")
for portable in portable_storage:
table_portable.add_row([portable.get('description', None), portable.get('capacity', None)])

table_nas = formatting.Table(['Volume name', 'capacity', 'Host Name', 'Location', 'Notes'],
title="File Storage Details")
for nas in nas_storage_data:
table_nas.add_row([nas['username'], nas['capacityGb'],
nas['serviceResourceBackendIpAddress'],
nas['allowedVirtualGuests'][0]['datacenter']['longName'],
nas.get('notes', None)])

table_local_disks = formatting.Table(['Type', 'Name', 'Capacity'], title="Other storage details")
for disks in local_disks:
if 'diskImage' in disks:
table_local_disks.add_row([get_local_type(disks), disks['mountType'],
str(disks['diskImage']['capacity']) + " " + str(disks['diskImage']['units'])])

env.fout(table_credentials)
env.fout(table_iscsi)
env.fout(table_portable)
env.fout(table_nas)
env.fout(table_local_disks)


def get_local_type(disks):
"""Returns the virtual server local disk type.

:param disks: virtual serve local disks.
"""
disk_type = 'System'
if 'SWAP' in disks['diskImage']['description']:
disk_type = 'Swap'

return disk_type
16 changes: 16 additions & 0 deletions SoftLayer/fixtures/SoftLayer_Account.py
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,22 @@
}
]


getPortableStorageVolumes = [
{
"capacity": 200,
"createDate": "2018-10-06T04:27:59-06:00",
"description": "Disk 2",
"id": 11111,
"modifyDate": "",
"name": "Disk 2",
"parentId": "",
"storageRepositoryId": 22222,
"typeId": 241,
"units": "GB",
"uuid": "fd477feb-bf32-408e-882f-02540gghgh111"
}
]
getAllTopLevelBillingItems = [
{
"allowCancellationFlag": 1,
Expand Down
93 changes: 93 additions & 0 deletions SoftLayer/fixtures/SoftLayer_Hardware_Server.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,96 @@
]

getMetricTrackingObjectId = 1000

getAttachedNetworkStorages = [
{
"accountId": 11111,
"capacityGb": 20,
"createDate": "2018-04-05T05:15:49-06:00",
"id": 22222,
"nasType": "NAS",
"serviceProviderId": 1,
"storageTypeId": "13",
"username": "SL02SEV311111_11",
"allowedHardware": [
{
"id": 12345,
"datacenter": {
"id": 449506,
"longName": "Frankfurt 2",
"name": "fra02",
"statusId": 2
}
}
],
"serviceResourceBackendIpAddress": "fsn-fra0201a-fz.service.softlayer.com",
"serviceResourceName": "Storage Type 02 File Aggregate stfm-fra0201a"
},
{
"accountId": 11111,
"capacityGb": 12000,
"createDate": "2018-01-28T04:57:30-06:00",
"id": 3777111,
"nasType": "ISCSI",
"notes": "BlockStorage12T",
"password": "",
"serviceProviderId": 1,
"storageTypeId": "7",
"username": "SL02SEL32222-9",
"allowedHardware": [
{
"id": 629222,
"datacenter": {
"id": 449506,
"longName": "Frankfurt 2",
"name": "fra02",
"statusId": 2
}
}
],
"serviceResourceBackendIpAddress": "10.31.95.152",
"serviceResourceName": "Storage Type 02 Block Aggregate stbm-fra0201a"
}
]

getAllowedHost = {
"accountId": 11111,
"credentialId": 22222,
"id": 33333,
"name": "iqn.2020-03.com.ibm:sl02su11111-v62941551",
"resourceTableId": 6291111,
"resourceTableName": "VIRTUAL_GUEST",
"credential": {
"accountId": "11111",
"createDate": "2020-03-20T13:35:47-06:00",
"id": 44444,
"nasCredentialTypeId": 2,
"password": "SjFDCpHrjskfj",
"username": "SL02SU11111-V62941551"
}
}

getHardDrives = [
{
"id": 11111,
"serialNumber": "z1w4sdf",
"serviceProviderId": 1,
"hardwareComponentModel": {
"capacity": "1000",
"description": "SATAIII:2000:8300:Constellation",
"id": 111,
"manufacturer": "Seagate",
"name": "Constellation ES",
"hardwareGenericComponentModel": {
"capacity": "1000",
"units": "GB",
"hardwareComponentType": {
"id": 1,
"keyName": "HARD_DRIVE",
"type": "Hard Drive",
"typeParentId": 5
}
}
}
}
]
23 changes: 23 additions & 0 deletions SoftLayer/fixtures/SoftLayer_Network_Storage_Iscsi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
getObject = {
"id": 11111,
"allowedVirtualGuests": [
{
"id": 22222,
"allowedHost": {
"accountId": 12345,
"id": 18311111,
"name": "iqn.2020-03.com.ibm:sl02su11111-v62941551",
"resourceTableId": 6222222,
"resourceTableName": "VIRTUAL_GUEST",
"credential": {
"accountId": "12345",
"createDate": "2020-03-20T13:35:47-06:00",
"id": 1522222,
"nasCredentialTypeId": 2,
"password": "SjFDCpHrmKewos",
"username": "SL02SU322222-V62922222"
}
}
}
]
}
Loading