2017-05-17 4 views
0

Cet appel REST affiche une liste de machines virtuelles avec CPU, Mem, Storage ... comment puis-je additionner le stockage total au lieu d'afficher la taille de disque individuelle?Softlayer VSI total 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]]] 

Merci Behzad

Répondre

0

Prendre en compte les demandes REST ne sont utilisés que pour récupérer des données de chaque datatype object, cela signifie que vous ne serez pas en mesure d'effectuer un calcul par REST.

Afin d'obtenir le stockage total, je vous recommande d'utiliser une langue comme Python, Java, C#, Ruby, Golang, etc. qui sont pris en charge par SoftLayer. Voir Softlayer API Overview

0

Ce peu de python devrait fonctionner pour vous.

""" 
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() 

Will quelque chose de sortie comme ceci:

$ 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