首页 > 解决方案 > 如何确定裸机设备有 GPU 以及什么类型的 GPU?

问题描述

我正在尝试确定我的 IBM Cloud 帐户中拥有 GPU 的 Bare Metal 设备的数量、GPU 的数量和 GPU 的类型。这如何使用 REST API 来完成?谢谢。

标签: ibm-cloud-infrastructure

解决方案


尝试使用以下 python 脚本示例:

import SoftLayer
from prettytable import PrettyTable

USERNAME = 'set me'

API_KEY = 'set me'

# Declare the API client
client = SoftLayer.create_client_from_env(USERNAME, API_KEY)
account_service = client['SoftLayer_Account']
x = PrettyTable()
x.field_names = ["HardwareComponentType", "Manufacturer", "Name"]

object_mask = 'mask[components]'
try:
    response = account_service.getHardware(mask=object_mask)
    count = 0
    for hardware in response:
        for component in hardware['components']:
            component_type = component['hardwareComponentModel']['hardwareGenericComponentModel'][
                'hardwareComponentType']['type']
            if component_type == 'GPU':
                gpu_type = component_type
                gpu_manufacturer = component['hardwareComponentModel']['manufacturer']
                gpu_name = component['hardwareComponentModel']['name']
                x.add_row([gpu_type, gpu_manufacturer, gpu_name])
                count = count + 1

    print(x)
    print("Number of Bare Metal devices in the account that have a GPU")
    print(str(count))

except SoftLayer.SoftLayerAPIError as e:
    """ 
        If there was an error returned from the SoftLayer API then bomb out with the 
        error message. 
        """
    print("Unable to get the hardware information \nfaultCode= %s, \nfaultString= %s"
          % (e.faultCode, e.faultString))

推荐阅读