对 "getSnapshotPercentage" 的软层服务调用失败
Softlayer service call to "getSnapshotPercentage" is failing
我将以下逻辑写入 get the Snapshot Percentage,但出现以下错误。请注意,我已经对 Network_Storage
和 Network_Storage_Iscsi
都进行了尝试,并且在这两种情况下都看到了相同的响应。有解决方法还是这是一个错误?
def get_snapshot_space(sl_config, iscsi_identifier):
""" get the total number of Snapshot Space remaining"""
snapshot_percentage = SL.instance(sl_config).net.getSnapshotPercentage(id=iscsi_identifier);
print "Snapshot Space Used: \% %s " % snapshot_space;
错误:
snapshot_percentage = SL.instance(sl_config).net.getSnapshotPercentage(id=iscsi_identifier);
File "/usr/lib/python2.7/site-packages/SoftLayer-5.1.0-
py2.7.egg/SoftLayer/API.py", line 375, in call_handler
return self(name, *args, **kwargs)
File "/usr/lib/python2.7/site-packages/SoftLayer-5.1.0-
py2.7.egg/SoftLayer/API.py", line 343, in call
return self.client.call(self.name, name, *args, **kwargs)
File "/usr/lib/python2.7/site-packages/SoftLayer-5.1.0-
py2.7.egg/SoftLayer/API.py", line 246, in call
return self.transport(request)
File "/usr/lib/python2.7/site-packages/SoftLayer-5.1.0-
py2.7.egg/SoftLayer/transports.py", line 187, in __call__
raise _ex(ex.faultCode, ex.faultString)
SoftLayer.exceptions.SoftLayerAPIError: SoftLayerAPIError(Client): Function ("getSnapshotPercentage") is not a valid method for this service
另外,我注意到在 softLayer Portal 上,百分比的表示有时不正确?自从我清除所有快照以来已经一个多小时了。
该方法目前已弃用,因此您可以使用对象掩码来检索 bytesUsed 和 snapshotCapacityGb 属性。
下一个脚本生成 space 可用的快照,显示在 UI 门户中。
"""
Retrieves snapshot space.
See below references for more details.
Important manual pages:
http://sldn.softlayer.com/reference/datatypes/SoftLayer_Network_Storage
@License: http://sldn.softlayer.com/article/License
@Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>
"""
import SoftLayer
USERNAME = 'set me'
API_KEY = 'set me'
client = SoftLayer.create_client_from_env(username=USERNAME, api_key=API_KEY)
networkStorageService = client['SoftLayer_Network_Storage']
iscsiStorageId = 1234567
objectMask = 'mask[snapshotCapacityGb,snapshots[bytesUsed,snapshotSizeBytes,snapshotSpaceAvailable]]'
try:
storage = networkStorageService.getObject(mask=objectMask, id=iscsiStorageId)
capacity = long(float(storage['snapshotCapacityGb'])) * 1e+9
used_space = 0
for child in storage['snapshots']:
used_space = used_space + long(float(child['snapshotSizeBytes']))
snapshot_space = (capacity - used_space) / 1e+9
print snapshot_space
except SoftLayer.SoftLayerAPIError as e:
print('Failed ... faultCode=%s, faultString=%s'
% (e.faultCode, e.faultString))
关于 UI 中的快照 space 表示,它或多或少每小时更新一次。
希望对您有所帮助。
我将以下逻辑写入 get the Snapshot Percentage,但出现以下错误。请注意,我已经对 Network_Storage
和 Network_Storage_Iscsi
都进行了尝试,并且在这两种情况下都看到了相同的响应。有解决方法还是这是一个错误?
def get_snapshot_space(sl_config, iscsi_identifier):
""" get the total number of Snapshot Space remaining"""
snapshot_percentage = SL.instance(sl_config).net.getSnapshotPercentage(id=iscsi_identifier);
print "Snapshot Space Used: \% %s " % snapshot_space;
错误:
snapshot_percentage = SL.instance(sl_config).net.getSnapshotPercentage(id=iscsi_identifier);
File "/usr/lib/python2.7/site-packages/SoftLayer-5.1.0-
py2.7.egg/SoftLayer/API.py", line 375, in call_handler
return self(name, *args, **kwargs)
File "/usr/lib/python2.7/site-packages/SoftLayer-5.1.0-
py2.7.egg/SoftLayer/API.py", line 343, in call
return self.client.call(self.name, name, *args, **kwargs)
File "/usr/lib/python2.7/site-packages/SoftLayer-5.1.0-
py2.7.egg/SoftLayer/API.py", line 246, in call
return self.transport(request)
File "/usr/lib/python2.7/site-packages/SoftLayer-5.1.0-
py2.7.egg/SoftLayer/transports.py", line 187, in __call__
raise _ex(ex.faultCode, ex.faultString)
SoftLayer.exceptions.SoftLayerAPIError: SoftLayerAPIError(Client): Function ("getSnapshotPercentage") is not a valid method for this service
另外,我注意到在 softLayer Portal 上,百分比的表示有时不正确?自从我清除所有快照以来已经一个多小时了。
该方法目前已弃用,因此您可以使用对象掩码来检索 bytesUsed 和 snapshotCapacityGb 属性。
下一个脚本生成 space 可用的快照,显示在 UI 门户中。
"""
Retrieves snapshot space.
See below references for more details.
Important manual pages:
http://sldn.softlayer.com/reference/datatypes/SoftLayer_Network_Storage
@License: http://sldn.softlayer.com/article/License
@Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>
"""
import SoftLayer
USERNAME = 'set me'
API_KEY = 'set me'
client = SoftLayer.create_client_from_env(username=USERNAME, api_key=API_KEY)
networkStorageService = client['SoftLayer_Network_Storage']
iscsiStorageId = 1234567
objectMask = 'mask[snapshotCapacityGb,snapshots[bytesUsed,snapshotSizeBytes,snapshotSpaceAvailable]]'
try:
storage = networkStorageService.getObject(mask=objectMask, id=iscsiStorageId)
capacity = long(float(storage['snapshotCapacityGb'])) * 1e+9
used_space = 0
for child in storage['snapshots']:
used_space = used_space + long(float(child['snapshotSizeBytes']))
snapshot_space = (capacity - used_space) / 1e+9
print snapshot_space
except SoftLayer.SoftLayerAPIError as e:
print('Failed ... faultCode=%s, faultString=%s'
% (e.faultCode, e.faultString))
关于 UI 中的快照 space 表示,它或多或少每小时更新一次。
希望对您有所帮助。