Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions SoftLayer/managers/cdn.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class CDNManager(utils.IdentifierMixin, object):

def __init__(self, client):
self.client = client
self._start_date = None
self._end_date = None
self.cdn_configuration = self.client['Network_CdnMarketplace_Configuration_Mapping']
self.cdn_path = self.client['SoftLayer_Network_CdnMarketplace_Configuration_Mapping_Path']
self.cdn_metrics = self.client['Network_CdnMarketplace_Metrics']
Expand Down Expand Up @@ -151,10 +153,20 @@ def get_usage_metrics(self, unique_id, history=30, frequency="aggregate"):
_start = utils.days_to_datetime(history)
_end = utils.days_to_datetime(0)

_start_date = utils.timestamp(_start)
_end_date = utils.timestamp(_end)
self._start_date = utils.timestamp(_start)
self._end_date = utils.timestamp(_end)

usage = self.cdn_metrics.getMappingUsageMetrics(unique_id, _start_date, _end_date, frequency)
usage = self.cdn_metrics.getMappingUsageMetrics(unique_id, self._start_date, self._end_date, frequency)

# The method getMappingUsageMetrics() returns an array but there is only 1 object
return usage[0]

@property
def start_data(self):
"""Retrieve the cdn usage metric start date."""
return self._start_date

@property
def end_date(self):
"""Retrieve the cdn usage metric end date."""
return self._end_date
11 changes: 2 additions & 9 deletions tests/managers/cdn_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

from SoftLayer.managers import cdn
from SoftLayer import testing
from SoftLayer import utils


class CDNTests(testing.TestCase):
Expand All @@ -31,15 +30,9 @@ def test_detail_cdn(self):
def test_detail_usage_metric(self):
self.cdn_client.get_usage_metrics(12345, history=30, frequency="aggregate")

_start = utils.days_to_datetime(30)
_end = utils.days_to_datetime(0)

_start_date = utils.timestamp(_start)
_end_date = utils.timestamp(_end)

args = (12345,
_start_date,
_end_date,
self.cdn_client.start_data,
self.cdn_client.end_date,
"aggregate")
self.assert_called_with('SoftLayer_Network_CdnMarketplace_Metrics',
'getMappingUsageMetrics',
Expand Down