Add api samples to simple tenant usage extension

Change-Id: Ib6e00e5c049846146619f52732cd06fefac62494
This commit is contained in:
Mauro S. M. Rodrigues 2012-10-04 10:18:38 -04:00
parent f54cf7bf53
commit d2af738f02
17 changed files with 319 additions and 0 deletions

View File

@ -0,0 +1,16 @@
{
"server" : {
"name" : "new-server-test",
"imageRef" : "http://openstack.example.com/openstack/images/70a599e0-31e7-49b7-b260-868f441e862b",
"flavorRef" : "http://openstack.example.com/openstack/flavors/1",
"metadata" : {
"My Server Name" : "Apache1"
},
"personality" : [
{
"path" : "/etc/banner.txt",
"contents" : "ICAgICAgDQoiQSBjbG91ZCBkb2VzIG5vdCBrbm93IHdoeSBpdCBtb3ZlcyBpbiBqdXN0IHN1Y2ggYSBkaXJlY3Rpb24gYW5kIGF0IHN1Y2ggYSBzcGVlZC4uLkl0IGZlZWxzIGFuIGltcHVsc2lvbi4uLnRoaXMgaXMgdGhlIHBsYWNlIHRvIGdvIG5vdy4gQnV0IHRoZSBza3kga25vd3MgdGhlIHJlYXNvbnMgYW5kIHRoZSBwYXR0ZXJucyBiZWhpbmQgYWxsIGNsb3VkcywgYW5kIHlvdSB3aWxsIGtub3csIHRvbywgd2hlbiB5b3UgbGlmdCB5b3Vyc2VsZiBoaWdoIGVub3VnaCB0byBzZWUgYmV5b25kIGhvcml6b25zLiINCg0KLVJpY2hhcmQgQmFjaA=="
}
]
}
}

View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<server xmlns="http://docs.openstack.org/compute/api/v1.1" imageRef="http://openstack.example.com/openstack/images/70a599e0-31e7-49b7-b260-868f441e862b" flavorRef="http://openstack.example.com/openstack/flavors/1" name="new-server-test">
<metadata>
<meta key="My Server Name">Apache1</meta>
</metadata>
<personality>
<file path="/etc/banner.txt">
ICAgICAgDQoiQSBjbG91ZCBkb2VzIG5vdCBrbm93IHdoeSBp
dCBtb3ZlcyBpbiBqdXN0IHN1Y2ggYSBkaXJlY3Rpb24gYW5k
IGF0IHN1Y2ggYSBzcGVlZC4uLkl0IGZlZWxzIGFuIGltcHVs
c2lvbi4uLnRoaXMgaXMgdGhlIHBsYWNlIHRvIGdvIG5vdy4g
QnV0IHRoZSBza3kga25vd3MgdGhlIHJlYXNvbnMgYW5kIHRo
ZSBwYXR0ZXJucyBiZWhpbmQgYWxsIGNsb3VkcywgYW5kIHlv
dSB3aWxsIGtub3csIHRvbywgd2hlbiB5b3UgbGlmdCB5b3Vy
c2VsZiBoaWdoIGVub3VnaCB0byBzZWUgYmV5b25kIGhvcml6
b25zLiINCg0KLVJpY2hhcmQgQmFjaA==
</file>
</personality>
</server>

View File

@ -0,0 +1,16 @@
{
"server": {
"adminPass": "tpKL9n5BHKFv",
"id": "3edb83e6-2c90-41c1-bf80-0b61472b4c19",
"links": [
{
"href": "http://openstack.example.com/v2/openstack/servers/3edb83e6-2c90-41c1-bf80-0b61472b4c19",
"rel": "self"
},
{
"href": "http://openstack.example.com/openstack/servers/3edb83e6-2c90-41c1-bf80-0b61472b4c19",
"rel": "bookmark"
}
]
}
}

View File

@ -0,0 +1,6 @@
<?xml version='1.0' encoding='UTF-8'?>
<server xmlns:atom="http://www.w3.org/2005/Atom" xmlns="http://docs.openstack.org/compute/api/v1.1" id="df5f4368-be09-47cc-a84f-c1382459284d" adminPass="foPQHkv8H66R">
<metadata/>
<atom:link href="http://openstack.example.com/v2/openstack/servers/df5f4368-be09-47cc-a84f-c1382459284d" rel="self"/>
<atom:link href="http://openstack.example.com/openstack/servers/df5f4368-be09-47cc-a84f-c1382459284d" rel="bookmark"/>
</server>

View File

@ -0,0 +1,27 @@
{
"tenant_usage": {
"server_usages": [
{
"ended_at": null,
"flavor": "m1.tiny",
"hours": 1.0,
"instance_id": "1f1deceb-17b5-4c04-84c7-e0d4499c8fe0",
"local_gb": 0,
"memory_mb": 512,
"name": "new-server-test",
"started_at": "2012-10-08T20:10:44.541277",
"state": "active",
"tenant_id": "openstack",
"uptime": 3600,
"vcpus": 1
}
],
"start": "2012-10-08T20:10:44.587336",
"stop": "2012-10-08T21:10:44.587336",
"tenant_id": "openstack",
"total_hours": 1.0,
"total_local_gb_usage": 0.0,
"total_memory_mb_usage": 512.0,
"total_vcpus_usage": 1.0
}
}

View File

@ -0,0 +1,26 @@
<?xml version='1.0' encoding='UTF-8'?>
<tenant_usage>
<tenant_id>openstack</tenant_id>
<total_local_gb_usage>0.0</total_local_gb_usage>
<total_vcpus_usage>1.0</total_vcpus_usage>
<total_memory_mb_usage>512.0</total_memory_mb_usage>
<total_hours>1.0</total_hours>
<start>2012-10-08 20:10:51.902640</start>
<stop>2012-10-08 21:10:51.902640</stop>
<server_usages>
<server_usage>
<instance_id>e4521f3b-d9ad-4454-be8a-e2732f0630ef</instance_id>
<name>new-server-test</name>
<hours>1.0</hours>
<memory_mb>512</memory_mb>
<local_gb>0</local_gb>
<vcpus>1</vcpus>
<tenant_id>openstack</tenant_id>
<flavor>m1.tiny</flavor>
<started_at>2012-10-08 20:10:51.854331</started_at>
<ended_at>None</ended_at>
<state>active</state>
<uptime>3600</uptime>
</server_usage>
</server_usages>
</tenant_usage>

View File

@ -0,0 +1,13 @@
{
"tenant_usages": [
{
"start": "2012-10-08T21:10:44.587336",
"stop": "2012-10-08T22:10:44.587336",
"tenant_id": "openstack",
"total_hours": 1.0,
"total_local_gb_usage": 0.0,
"total_memory_mb_usage": 512.0,
"total_vcpus_usage": 1.0
}
]
}

View File

@ -0,0 +1,13 @@
<?xml version='1.0' encoding='UTF-8'?>
<tenant_usages>
<tenant_usage>
<tenant_id>openstack</tenant_id>
<total_local_gb_usage>0.0</total_local_gb_usage>
<total_vcpus_usage>1.0</total_vcpus_usage>
<total_memory_mb_usage>512.0</total_memory_mb_usage>
<total_hours>1.0</total_hours>
<start>2012-10-08 21:10:51.902640</start>
<stop>2012-10-08 22:10:51.902640</stop>
<server_usages/>
</tenant_usage>
</tenant_usages>

View File

@ -0,0 +1,16 @@
{
"server" : {
"name" : "new-server-test",
"imageRef" : "%(host)s/openstack/images/%(image_id)s",
"flavorRef" : "%(host)s/openstack/flavors/1",
"metadata" : {
"My Server Name" : "Apache1"
},
"personality" : [
{
"path" : "/etc/banner.txt",
"contents" : "ICAgICAgDQoiQSBjbG91ZCBkb2VzIG5vdCBrbm93IHdoeSBpdCBtb3ZlcyBpbiBqdXN0IHN1Y2ggYSBkaXJlY3Rpb24gYW5kIGF0IHN1Y2ggYSBzcGVlZC4uLkl0IGZlZWxzIGFuIGltcHVsc2lvbi4uLnRoaXMgaXMgdGhlIHBsYWNlIHRvIGdvIG5vdy4gQnV0IHRoZSBza3kga25vd3MgdGhlIHJlYXNvbnMgYW5kIHRoZSBwYXR0ZXJucyBiZWhpbmQgYWxsIGNsb3VkcywgYW5kIHlvdSB3aWxsIGtub3csIHRvbywgd2hlbiB5b3UgbGlmdCB5b3Vyc2VsZiBoaWdoIGVub3VnaCB0byBzZWUgYmV5b25kIGhvcml6b25zLiINCg0KLVJpY2hhcmQgQmFjaA=="
}
]
}
}

View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<server xmlns="http://docs.openstack.org/compute/api/v1.1" imageRef="%(host)s/openstack/images/%(image_id)s" flavorRef="%(host)s/openstack/flavors/1" name="new-server-test">
<metadata>
<meta key="My Server Name">Apache1</meta>
</metadata>
<personality>
<file path="/etc/banner.txt">
ICAgICAgDQoiQSBjbG91ZCBkb2VzIG5vdCBrbm93IHdoeSBp
dCBtb3ZlcyBpbiBqdXN0IHN1Y2ggYSBkaXJlY3Rpb24gYW5k
IGF0IHN1Y2ggYSBzcGVlZC4uLkl0IGZlZWxzIGFuIGltcHVs
c2lvbi4uLnRoaXMgaXMgdGhlIHBsYWNlIHRvIGdvIG5vdy4g
QnV0IHRoZSBza3kga25vd3MgdGhlIHJlYXNvbnMgYW5kIHRo
ZSBwYXR0ZXJucyBiZWhpbmQgYWxsIGNsb3VkcywgYW5kIHlv
dSB3aWxsIGtub3csIHRvbywgd2hlbiB5b3UgbGlmdCB5b3Vy
c2VsZiBoaWdoIGVub3VnaCB0byBzZWUgYmV5b25kIGhvcml6
b25zLiINCg0KLVJpY2hhcmQgQmFjaA==
</file>
</personality>
</server>

View File

@ -0,0 +1,16 @@
{
"server": {
"adminPass": "%(password)s",
"id": "%(id)s",
"links": [
{
"href": "%(host)s/v2/openstack/servers/%(uuid)s",
"rel": "self"
},
{
"href": "%(host)s/openstack/servers/%(uuid)s",
"rel": "bookmark"
}
]
}
}

View File

@ -0,0 +1,6 @@
<?xml version='1.0' encoding='UTF-8'?>
<server xmlns:atom="http://www.w3.org/2005/Atom" xmlns="http://docs.openstack.org/compute/api/v1.1" id="%(id)s" adminPass="%(password)s">
<metadata/>
<atom:link href="%(host)s/v2/openstack/servers/%(uuid)s" rel="self"/>
<atom:link href="%(host)s/openstack/servers/%(uuid)s" rel="bookmark"/>
</server>

View File

@ -0,0 +1,27 @@
{
"tenant_usage": {
"server_usages": [
{
"ended_at": null,
"flavor": "m1.tiny",
"hours": 1.0,
"instance_id": "%(uuid)s",
"local_gb": 0,
"memory_mb": 512,
"name": "new-server-test",
"started_at": "%(timestamp)s",
"state": "active",
"tenant_id": "openstack",
"uptime": 3600,
"vcpus": 1
}
],
"start": "%(timestamp)s",
"stop": "%(timestamp)s",
"tenant_id": "openstack",
"total_hours": 1.0,
"total_local_gb_usage": 0.0,
"total_memory_mb_usage": 512.0,
"total_vcpus_usage": 1.0
}
}

View File

@ -0,0 +1,26 @@
<?xml version='1.0' encoding='UTF-8'?>
<tenant_usage>
<tenant_id>openstack</tenant_id>
<total_local_gb_usage>0.0</total_local_gb_usage>
<total_vcpus_usage>1.0</total_vcpus_usage>
<total_memory_mb_usage>512.0</total_memory_mb_usage>
<total_hours>1.0</total_hours>
<start>%(timestamp)s</start>
<stop>%(timestamp)s</stop>
<server_usages>
<server_usage>
<instance_id>%(uuid)s</instance_id>
<name>new-server-test</name>
<hours>1.0</hours>
<memory_mb>512</memory_mb>
<local_gb>0</local_gb>
<vcpus>1</vcpus>
<tenant_id>openstack</tenant_id>
<flavor>m1.tiny</flavor>
<started_at>%(timestamp)s</started_at>
<ended_at>None</ended_at>
<state>active</state>
<uptime>3600</uptime>
</server_usage>
</server_usages>
</tenant_usage>

View File

@ -0,0 +1,13 @@
{
"tenant_usages": [
{
"start": "%(timestamp)s",
"stop": "%(timestamp)s",
"tenant_id": "openstack",
"total_hours": 1.0,
"total_local_gb_usage": 0.0,
"total_memory_mb_usage": 512.0,
"total_vcpus_usage": 1.0
}
]
}

View File

@ -0,0 +1,13 @@
<?xml version='1.0' encoding='UTF-8'?>
<tenant_usages>
<tenant_usage>
<tenant_id>openstack</tenant_id>
<total_local_gb_usage>0.0</total_local_gb_usage>
<total_vcpus_usage>1.0</total_vcpus_usage>
<total_memory_mb_usage>512.0</total_memory_mb_usage>
<total_hours>1.0</total_hours>
<start>%(timestamp)s</start>
<stop>%(timestamp)s</stop>
<server_usages/>
</tenant_usage>
</tenant_usages>

View File

@ -14,19 +14,23 @@
# under the License.
import base64
import datetime
import os
import re
import urllib
import uuid
from lxml import etree
from nova.cloudpipe.pipelib import CloudPipe
from nova.compute import api
from nova import context
from nova import flags
from nova.network.manager import NetworkManager
from nova.openstack.common import importutils
from nova.openstack.common import jsonutils
from nova.openstack.common.log import logging
from nova.openstack.common import timeutils
from nova import test
from nova.tests import fake_network
from nova.tests.image import fake
@ -1222,3 +1226,46 @@ class MultipleCreateJsonTest(ServersSampleBase):
class MultipleCreateXmlTest(MultipleCreateJsonTest):
ctype = 'xml'
class SimpleTenantUsageSampleJsonTest(ServersSampleBase):
extension_name = ("nova.api.openstack.compute.contrib.simple_tenant_usage."
"Simple_tenant_usage")
def setUp(self):
"""setUp method for simple tenant usage"""
super(SimpleTenantUsageSampleJsonTest, self).setUp()
self._post_server()
timeutils.set_time_override(timeutils.utcnow() +
datetime.timedelta(hours=1))
self.query = {
'start': str(timeutils.utcnow() - datetime.timedelta(hours=1)),
'end': str(timeutils.utcnow())
}
def tearDown(self):
"""tearDown method for simple tenant usage"""
super(SimpleTenantUsageSampleJsonTest, self).tearDown()
timeutils.clear_time_override()
def test_get_tenants_usage(self):
"""Get api sample to get all tenants usage request"""
response = self._do_get('os-simple-tenant-usage?%s' % (
urllib.urlencode(self.query)))
self.assertEqual(response.status, 200)
subs = self._get_regexes()
self._verify_response('simple-tenant-usage-get', subs, response)
def test_get_tenant_usage_details(self):
"""Get api sample to get specific tenant usage request"""
tenant_id = 'openstack'
response = self._do_get('os-simple-tenant-usage/%s?%s' % (tenant_id,
urllib.urlencode(self.query)))
self.assertEqual(response.status, 200)
subs = self._get_regexes()
self._verify_response('simple-tenant-usage-get-specific', subs,
response)
class SimpleTenantUsageSampleXmlTest(SimpleTenantUsageSampleJsonTest):
ctype = "xml"