0
如何使用python通過API在Hardware_Server上設置筆記?我一直在尋找Hardware_Server中的可用方法,但沒有看到setNote
的方法。如何使用SoftLayer API設置硬件筆記
如何使用python通過API在Hardware_Server上設置筆記?我一直在尋找Hardware_Server中的可用方法,但沒有看到setNote
的方法。如何使用SoftLayer API設置硬件筆記
要添加註釋或編輯其他SoftLayer_Hardware_Server屬性,您需要使用SoftLayer_Hardware_Server :: editObject方法。
下面你可以看到一個例子來註釋添加到BMS ID爲123456
"""
Edit a bare metal server's basic information
This example shows how to edit the property 'notes' for a single bare metal server by
using the editObject() method in the SoftLayer_Hardware_Server API service.
See below for more details.
Important manual pages:
http://sldn.softlayer.com/reference/services/SoftLayer_Hardware_Server/editObject
License: http://sldn.softlayer.com/article/License
Author: SoftLayer Technologies, Inc. <[email protected]>
"""
import SoftLayer
# Your SoftLayer API username and key.
USERNAME = 'set me'
API_KEY = 'set me'
# The id of the bare metal you wish to edit
hardwareId = 123456
'''
The template object used to edit a SoftLayer_Hardware_Server.
Take account you can edit other properties by using a similar skeleton
'''
templateObject = {
'notes': 'This is my bare metal server!'
}
# Declare a new API service object
client = SoftLayer.create_client_from_env(username=USERNAME, api_key=API_KEY)
try:
# Add notes to the Bare Metal server
result = client['SoftLayer_Hardware_Server'].editObject(templateObject,
id=hardwareId)
print('Bare Metal Server edited')
except SoftLayer.SoftLayerAPIError as e:
print("Unable to edit the server: %s, %s" % (e.faultCode, e.faultString))
參考文獻:
http://sldn.softlayer.com/reference/services/SoftLayer_Hardware_Server/editObject
http://sldn.softlayer.com/reference/datatypes/SoftLayer_Hardware_Server
我希望這可以幫助您。
Regards,