软层 Server_ID

Softlayer Server_ID

我正在尝试执行以下操作:

import SoftLayer.API
username = 'set me!'
apiKey = 'set me too!'
serverId = 1234       
client = SoftLayer.API.Client('SoftLayer_Hardware_Server', serverId, username, apiKey)

在这里,我真的不知道如何检索 serverId。我怎么知道特定服务器的服务器 ID。请帮忙

SoftLayer_Account::getHardware 检索有关硬件对象的信息,您可以在其中找到服务器的 serverId。

试试这个 python 脚本:

"""
This script retrieves an account's associated hardware objects

Important manual pages:
http://sldn.softlayer.com/reference/services/SoftLayer_Account/getHardware

License: http://sldn.softlayer.com/article/License
Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>
"""
# So we can talk to the SoftLayer API:
import SoftLayer.API

# For nice debug output:
from pprint import pprint as pp

# Your SoftLayer username and api key
API_USERNAME = 'set me'
API_KEY = 'set me'

# Creates a new connection to the API service.
client = SoftLayer.API.Client(username=API_USERNAME,api_key=API_KEY)

try:
    hardwareObjects = client['SoftLayer_Account'].getHardware()
    pp(hardwareObjects)

except SoftLayer.SoftLayerAPIError as e:
        pp('Unable to get hardware objects faultCode=%s, faultString=%s'
            % (e.faultCode, e.faultString))

此脚本将return来自您的服务器的信息,其中"id" 属性指的是您所在服务器的serverId需要。

但是,如果您希望检索特定服务器的信息,可以使用 Object Filters 来完成,这里有一个例子:

"""
This script retrieves a hardware information for an specific hardware object.
It is only necessary to specify the hostname from the server.

Important manual pages:
http://sldn.softlayer.com/reference/services/SoftLayer_Account/getHardware
http://sldn.softlayer.com/article/object-filters

License: http://sldn.softlayer.com/article/License
Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>
"""
# So we can talk to the SoftLayer API:
import SoftLayer.API

# For nice debug output:
from pprint import pprint as pp

# Your SoftLayer username and api key
API_USERNAME = 'set me'
API_KEY = 'set me'
# Define the hostname from the hardware object
hostname = 'hostnametest'

# Declare an object filter to get an specific hardware object
filterHardware = {
    'hardware': {
        'hostname': {
            'operation': hostname
        }
    }
}

# Creates a new connection to the API service.
client = SoftLayer.API.Client(username=API_USERNAME,api_key=API_KEY)

try:
    hardwareObjects = client['SoftLayer_Account'].getHardware(filter=filterHardware)
    pp(hardwareObjects)

except SoftLayer.SoftLayerAPIError as e:
        pp('Unable to get the hardware object faultCode=%s, faultString=%s'
            % (e.faultCode, e.faultString))

您需要从您的服务器指定 "hostname"。响应中的"id"指的是serverId.

部分参考资料: