2017-05-17 3 views
0

このRESTコールは、CPU、Mem、Storageを持つVMのリストを表示します...個々のディスクサイズを表示する代わりに、合計ストレージを合計するにはどうすればよいですか?ソフトレイヤーVSI合計Sotrage

https://APIID:[email protected]/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

テイクアカウントREST要求は、それはあなたが文句を言わないRESTを通じて任意の計算を実行することができる意味し、各datatype objectのデータを取得するために使用されています。

総ストレージを得るために、私はSOFTLAYERによってサポートされているなどPythonJavaC#RubyGolang、のようないくつかの言語を使用することをお勧めいたします。 Softlayer API Overview

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