Search code examples
ibm-cloud-infrastructure

re-creating bandwidth pool detail screen via API


I'm trying to get a programmatic dump of the bandwidth usage, per machine, from a bandwidth pool.

I've created code that can add and remove my servers using the API, but I haven't managed to find the correct mechanism to get the details of the usage on a per-machine basis.

It looks like:

https://softlayer.github.io/reference/services/SoftLayer_Network_Bandwidth_Version1_Allotment/getDetails/

Is the correct api call, and calling this gives me a list of details of allotment but I cannot work out the right mask to get all the details I need.

So far I've tried the following mask:

"allocation.amount;allocation.billingItem.hostname;bandwidthAllotment.amount;bandwidthAllotment.billingItem.hostname;bandwidthUsage.amount;bandwidthUsage.billingItem.hostname"

But that doesn't get me the details that I need and seems to pull in large numbers of extra fields that are not in the filter and make the call take a very long time to complete.

Does anyone know how to construct the correct filter?


Solution

  • To know the bandwidth usage in all the hardware servers moved into the bandwidth pool rack you have to use the method getHardware of the service SoftLayer_Account because it is the method and service that the control portal use.

    Use this rest api to get the bandwith usage informacion for the hardware servers:

    Method: GET

    https://[username]:[apiKey]@api.softlayer.com/rest/v3.1/SoftLayer_Account/getHardware?objectMask=mask[id,primaryIpAddress,datacenter[longName,groups[id]],bandwidthAllocation,outboundPublicBandwidthUsage,billingItem[nextBillDate],virtualRackId,bareMetalInstanceFlag]&objectFilter={"hardware":{"virtualRackId":{"operation":11111}}}
    

    Change the virtualRackId: 11111 for your virtualRackId that is the bandwidth pool id that you are using.

    The current usage that you find in the control portal you will find here in the response with the attribute “outboundPublicBandwidthUsage”.

    In hardware server there is not the attribute “projectedPublicBandwidthUsage” but in virtual server you will find that option.

    Reference:

    https://softlayer.github.io/reference/datatypes/SoftLayer_Hardware/

    It is the same for virtual servers that are associated to the bandwidth pool but in this case you will get the attribute “projectedPublicBandwidthUsage” which is the “PROJECTED USAGE” in the control portal.

    Use this rest api for virtual servers:

    Method: GET

    https://[username]:[apiKey]@api.softlayer.com/rest/v3.1/SoftLayer_Account/getVirtualGuests?objectMask=mask[id,primaryIpAddress,datacenter[longName,groups[id]],bandwidthAllocation,outboundPublicBandwidthUsage,billingItem[nextBillDate],virtualRackId,projectedPublicBandwidthUsage]&objectFilter={"virtualGuests":{"virtualRackId":{"operation":11111}}}
    

    The same that above change the virtualRackId for your bandwidth pool id.

    Reference:

    https://softlayer.github.io/reference/datatypes/SoftLayer_Virtual_Guest/