python 为VSI获取带宽

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 为VSI获取带宽相关的知识,希望对你有一定的参考价值。

import SoftLayer
import pprint

class example():

    def __init__(self):
        self.client = SoftLayer.Client()

    def main(self):
        pp = pprint.PrettyPrinter(indent=2)
        theMask = "mask[inboundPrivateBandwidthUsage,inboundPublicBandwidthUsage,outboundPrivateBandwidthUsage,outboundPublicBandwidthUsage]"
        result = self.client['SoftLayer_Account'].getVirtualGuests()
        print "server_name,public_in,public_out,private_in,private_out"
        
        for server in result:
            #getHardware() only returns SoftLayer_Hardware, which doesn't have the private bw usage metrics, for some reason.
            # So we just use SoftLayer_Hardware_Server here, which has more detailed information
            serverInfo = self.client['SoftLayer_Virtual_Guest'].getObject(id=server['id'],mask=theMask)

            # use .get() to avoid exceptions
            pubin = serverInfo.get('inboundPublicBandwidthUsage', '--')
            pubout = serverInfo.get('outboundPublicBandwidthUsage', '--')
            privin =serverInfo.get('inboundPrivateBandwidthUsage', '--')
            privout = serverInfo.get('outboundPrivateBandwidthUsage', '--')

            print(serverInfo['fullyQualifiedDomainName'] + ","),
            print(pubin + ","),
            print(pubout + ","),
            print(privin + ","),
            print(privout)


if __name__ == "__main__":
    main = example()
    main.main()

以上是关于python 为VSI获取带宽的主要内容,如果未能解决你的问题,请参考以下文章

python 用于订购VSI并指定安装后脚本URL的Python示例

markdown 用于将VSI部署到专用主机的Terraform示例

markdown 用于在Centos 7上创建VSI和安装Docker Engine的Terraform示例文件

不能在vsi2017的linux子系统中包含头文件

android Camera 如何 获取最佳合适的尺寸

android Camera 如何 获取最佳合适的尺寸