Softlayer api:为什么返回的SoftLayer_Metric_Tracking_Object :: getSummaryData接口数据为空?

时间:2018-02-08 03:46:39

标签: api ibm-cloud-infrastructure bandwidth

我正在开发softlayer api。我通过SoftLayer_Metric_Tracking_Object :: getSummaryData接口获得了带宽信息。昨天这个界面很正常。但今天我得到的数据带宽都是[]。所以我们现在有充电问题。界面有问题吗?

此致〜

    def get_amount_of_used_bandwidth(self, type, begin_date, end_date, instance_id, internal=300, default_log_type = 'sl_api'):
    '''
    Get amount of used bytes
    :param type:
        bandwidth_public_in
        bandwidth_public_out
        bandwidth_private_out
        bandwidth_private_in
    :param begin_date: 2016-09-01T00:00:00+8:00
    :param end_date: 2016-09-22T00:00:00+8:00
    :param interval integer  300, 600, 1800, 3600, 43200 or 86400 seconds
    :param instance_id:24401607
    :return:
    [
        {
            'counter': 96563.0,
            'type': 'publicOut_net_octet',
            'dateTime': '2016-03-31T00:05:00-06:00'
        },
        ...
    ]
    '''

    if not self.check_date(begin_date):
        raise AttributeError('Invalid date')

    if not self.check_date(end_date):
        raise AttributeError('Invalid date')

    metric_info = self.sl_virtual_guest.getMetricTrackingObject(id=instance_id)
    metric_tracking_object_id = metric_info['id']

    if type == 'bandwidth_public_out':
        types = [
                {
                    "keyName": "PUBLICOUT",
                    "name": "publicOut",
                    "summaryType": "sum"
                }
        ]

    elif type == 'bandwidth_public_in':
        types = [
                {
                    "keyName": "PUBLICIN",
                    "name": "publicIn",
                    "summaryType": "sum"
                }
        ]
    elif type == 'bandwidth_private_out':
        types = [
                {
                    "keyName": "PRIVATEOUT",
                    "name": "privateOut",
                    "summaryType": "sum"
                }
        ]
    elif type == 'bandwidth_private_in':
        types = [
                {
                    "keyName": "PRIVATEIN",
                    "name": "privateIn",
                    "summaryType": "sum"
                }
        ]
    else:
        raise AttributeError('Invalid type')

    data_repo = self.sl_metric_tracking_object.getSummaryData(begin_date, end_date, types, internal,
                                                              id=metric_tracking_object_id)


    return data_repo

0 个答案:

没有答案