Merge "Overwrite Usage class's get() function"
This commit is contained in:
commit
2d353f2879
novaclient
@ -13,6 +13,8 @@
|
|||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
|
import six
|
||||||
|
|
||||||
from novaclient.tests.unit import utils
|
from novaclient.tests.unit import utils
|
||||||
from novaclient.tests.unit.v2 import fakes
|
from novaclient.tests.unit.v2 import fakes
|
||||||
from novaclient.v2 import usage
|
from novaclient.v2 import usage
|
||||||
@ -58,3 +60,18 @@ class UsageTest(utils.TestCase):
|
|||||||
("start=%s&" % now.isoformat()) +
|
("start=%s&" % now.isoformat()) +
|
||||||
("end=%s" % now.isoformat()))
|
("end=%s" % now.isoformat()))
|
||||||
self.assertIsInstance(u, usage.Usage)
|
self.assertIsInstance(u, usage.Usage)
|
||||||
|
|
||||||
|
def test_usage_class_get(self):
|
||||||
|
start = six.u('2012-01-22T19:48:41.750722')
|
||||||
|
stop = six.u('2012-01-22T19:48:41.750722')
|
||||||
|
|
||||||
|
info = {'tenant_id': 'tenantfoo', 'start': start,
|
||||||
|
'stop': stop}
|
||||||
|
u = usage.Usage(self.cs.usage, info)
|
||||||
|
u.get()
|
||||||
|
self.assert_request_id(u, fakes.FAKE_REQUEST_ID_LIST)
|
||||||
|
|
||||||
|
self.cs.assert_called(
|
||||||
|
'GET',
|
||||||
|
"/os-simple-tenant-usage/tenantfoo?start=%s&end=%s" %
|
||||||
|
(start, stop))
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
Usage interface.
|
Usage interface.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import oslo_utils
|
||||||
|
|
||||||
from novaclient import base
|
from novaclient import base
|
||||||
|
|
||||||
|
|
||||||
@ -25,6 +27,19 @@ class Usage(base.Resource):
|
|||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<ComputeUsage>"
|
return "<ComputeUsage>"
|
||||||
|
|
||||||
|
def get(self):
|
||||||
|
fmt = '%Y-%m-%dT%H:%M:%S.%f'
|
||||||
|
if self.start and self.stop and self.tenant_id:
|
||||||
|
# set_loaded() first ... so if we have to bail, we know we tried.
|
||||||
|
self.set_loaded(True)
|
||||||
|
start = oslo_utils.timeutils.parse_strtime(self.start, fmt=fmt)
|
||||||
|
stop = oslo_utils.timeutils.parse_strtime(self.stop, fmt=fmt)
|
||||||
|
|
||||||
|
new = self.manager.get(self.tenant_id, start, stop)
|
||||||
|
if new:
|
||||||
|
self._add_details(new._info)
|
||||||
|
self.append_request_ids(new.request_ids)
|
||||||
|
|
||||||
|
|
||||||
class UsageManager(base.ManagerWithFind):
|
class UsageManager(base.ManagerWithFind):
|
||||||
"""
|
"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user