此REST调用显示具有CPU,内存,存储的虚拟机列表...如何总计存储总量而不是显示单个磁盘大小?
https://APIID:Key@api.softlayer.com/rest/v3/SoftLayer_Account/getVirtualGuests?objectMask=mask[id,hostname,primaryIpAddress,primaryBackendIpAddress,maxCpu,maxMemory,domain,fullyQualifiedDomainName,createDate,operatingSystem[id,softwareDescription[longDescription]],networkVlans[vlanNumber,primarySubnetId,name],datacenter[name],powerState[keyName],blockDevices[id,mountType,diskImage[capacity]]]
由于 Behzad
答案 0 :(得分:0)
考虑到帐户REST请求仅用于检索每个datatype object的数据,这意味着您无法通过REST执行任何计算。
为了获得总存储空间,建议您使用Python,Java,C#,Ruby,Golang等语言。由SoftLayer支持。见Softlayer API Overview
答案 1 :(得分:0)
这段python应该适合你。
"""
Goes through each virtual guest, prints out the FQDN, each disk and its size
and then the total size for disks on that virtual guest.
"""
import SoftLayer
from pprint import pprint as pp
class example():
def __init__(self):
self.client = SoftLayer.Client()
def main(self):
mask = "mask[id,fullyQualifiedDomainName,blockDevices[diskImage[type]]]"
guests = self.client['SoftLayer_Account'].getVirtualGuests(mask=mask)
for guest in guests:
self.getSumStorage(guest)
def getSumStorage(self, guest):
"""
Gets the total disk space for each virtual guest.
DOES NOT COUNT SWAP SPACE in this total
"""
print("%s" % guest['fullyQualifiedDomainName'])
sumTotal = 0
for device in guest['blockDevices']:
try:
if device['diskImage']['type']['keyName'] == 'SWAP':
print("\tSWAP: %s - %s GB (not counted)" %(device['device'],device['diskImage']['capacity']) )
continue
else:
print("\tDisk: %s - %s GB" %(device['device'],device['diskImage']['capacity']) )
sumTotal = sumTotal + device['diskImage']['capacity']
except KeyError:
continue
print("TOTAL: %s GB" % sumTotal)
return sumTotal
if __name__ == "__main__":
main = example()
main.main()
将输出如下内容:
$ python diskSum.py
LAMP1.asdf.com
Disk: 0 - 25 GB
SWAP: 1 - 2 GB (not counted)
TOTAL: 25 GB
LAMP2.asdf.com
Disk: 0 - 25 GB
SWAP: 1 - 2 GB (not counted)
TOTAL: 25 GB