2016-02-29 4 views
0

Я пытаюсь выполнить следующие действия: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) 

Здесь, я не знаю, как получить идентификатор_сервера. Как узнать свой идентификатор сервера для определенного сервера. Пожалуйста помоги.

ответ

1

SoftLayer_Account::getHardware получает информацию о ваших аппаратных объектах, в которой вы можете найти serverIds с ваших серверов.

Попробуйте этот питон скрипт:

""" 
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. <[email protected]> 
""" 
# 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)) 

Этот скрипт будет возвращать информацию из ваших серверов, в которых «идентификатор» свойство относится к идентификатор_серверу от сервера, что вам нужно.

Однако, если вы хотите получить информацию для конкретного сервера, это может быть сделано с помощью 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. <[email protected]> 
""" 
# 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)) 

Вы должны указать «имя хоста» с вашего сервера. «id» в ответе ссылается на serverId.

Некоторые ссылки:

Смежные вопросы