drop v1 client
we dropped v1 back in Juno. as icehouse is EOL and the client follows stable/branches, v1 is completely inaccessible and can be removed Change-Id: If4c6c07e65a6c47f47c59de6c99e8c40ef4e63cb Co-Authored-By: ZhiQiang Fan <aji.zqfan@gmail.com> Closes-Bug: #1389331
This commit is contained in:
@@ -23,7 +23,6 @@ from ceilometerclient import exc
|
||||
from ceilometerclient.openstack.common.apiclient import exceptions
|
||||
from ceilometerclient.tests.unit import fakes
|
||||
from ceilometerclient.tests.unit import utils
|
||||
from ceilometerclient.v1 import client as v1client
|
||||
from ceilometerclient.v2 import client as v2client
|
||||
|
||||
FAKE_ENV = {
|
||||
@@ -64,20 +63,7 @@ class ClientTest(utils.BaseTestCase):
|
||||
self.assertTrue(session.request.called)
|
||||
self.assertTrue(resp.json.called)
|
||||
|
||||
def test_client_v1_with_session(self):
|
||||
resp = mock.Mock(status_code=200, text=b'')
|
||||
resp.json.return_value = {'resources': []}
|
||||
session = mock.Mock()
|
||||
session.request.return_value = resp
|
||||
c = client.get_client(1, session=session)
|
||||
c.resources.list()
|
||||
self.assertTrue(session.request.called)
|
||||
self.assertTrue(resp.json.called)
|
||||
|
||||
def test_client_version(self):
|
||||
c1 = self.create_client(env=FAKE_ENV, api_version=1)
|
||||
self.assertIsInstance(c1, v1client.Client)
|
||||
|
||||
c2 = self.create_client(env=FAKE_ENV, api_version=2)
|
||||
self.assertIsInstance(c2, v2client.Client)
|
||||
|
||||
|
||||
@@ -1,162 +0,0 @@
|
||||
# Copyright 2012 OpenStack Foundation
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
from ceilometerclient.openstack.common.apiclient import client
|
||||
from ceilometerclient.openstack.common.apiclient import fake_client
|
||||
from ceilometerclient.tests.unit import utils
|
||||
import ceilometerclient.v1.meters
|
||||
|
||||
|
||||
fixtures = {
|
||||
'/v1/meters': {
|
||||
'GET': (
|
||||
{},
|
||||
{'meters': [
|
||||
{
|
||||
'resource_id': 'a',
|
||||
'project_id': 'dig_the_ditch',
|
||||
'user_id': 'freddy',
|
||||
'name': 'this',
|
||||
'type': 'counter',
|
||||
},
|
||||
{
|
||||
'resource_id': 'b',
|
||||
'project_id': 'dig_the_ditch',
|
||||
'user_id': 'joey',
|
||||
'name': 'this',
|
||||
'type': 'counter',
|
||||
},
|
||||
]},
|
||||
),
|
||||
},
|
||||
'/v1/users/joey/meters': {
|
||||
'GET': (
|
||||
{},
|
||||
{'meters': [
|
||||
{
|
||||
'resource_id': 'b',
|
||||
'project_id': 'dig_the_ditch',
|
||||
'user_id': 'joey',
|
||||
'name': 'this',
|
||||
'type': 'counter',
|
||||
},
|
||||
]},
|
||||
),
|
||||
},
|
||||
'/v1/projects/dig_the_ditch/meters': {
|
||||
'GET': (
|
||||
{},
|
||||
{'meters': [
|
||||
{
|
||||
'resource_id': 'b',
|
||||
'project_id': 'dig_the_ditch',
|
||||
'user_id': 'joey',
|
||||
'name': 'this',
|
||||
'type': 'counter',
|
||||
},
|
||||
]},
|
||||
),
|
||||
},
|
||||
'/v1/sources/openstack/meters': {
|
||||
'GET': (
|
||||
{},
|
||||
{'meters': [
|
||||
{
|
||||
'resource_id': 'b',
|
||||
'project_id': 'dig_the_ditch',
|
||||
'user_id': 'joey',
|
||||
'name': 'this',
|
||||
'type': 'counter',
|
||||
},
|
||||
{
|
||||
'resource_id': 'q',
|
||||
'project_id': 'dig_the_trench',
|
||||
'user_id': 'joey',
|
||||
'name': 'this',
|
||||
'type': 'counter',
|
||||
},
|
||||
]},
|
||||
),
|
||||
},
|
||||
'/v1/meters?metadata.zxc_id=foo': {
|
||||
'GET': (
|
||||
{},
|
||||
{'meters': [
|
||||
{
|
||||
'resource_id': 'b',
|
||||
'project_id': 'dig_the_ditch',
|
||||
'user_id': 'joey',
|
||||
'name': 'this',
|
||||
'type': 'counter',
|
||||
},
|
||||
]},
|
||||
),
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
class MeterManagerTest(utils.BaseTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(MeterManagerTest, self).setUp()
|
||||
self.http_client = fake_client.FakeHTTPClient(fixtures=fixtures)
|
||||
self.api = client.BaseClient(self.http_client)
|
||||
self.mgr = ceilometerclient.v1.meters.MeterManager(self.api)
|
||||
|
||||
def test_list_all(self):
|
||||
resources = list(self.mgr.list())
|
||||
expect = [
|
||||
'GET', '/v1/meters'
|
||||
]
|
||||
self.http_client.assert_called(*expect)
|
||||
self.assertEqual(len(resources), 2)
|
||||
self.assertEqual(resources[0].resource_id, 'a')
|
||||
self.assertEqual(resources[1].resource_id, 'b')
|
||||
|
||||
def test_list_by_source(self):
|
||||
resources = list(self.mgr.list(source='openstack'))
|
||||
expect = [
|
||||
'GET', '/v1/sources/openstack/meters'
|
||||
]
|
||||
self.http_client.assert_called(*expect)
|
||||
self.assertEqual(len(resources), 2)
|
||||
self.assertEqual(resources[0].resource_id, 'b')
|
||||
self.assertEqual(resources[1].resource_id, 'q')
|
||||
|
||||
def test_list_by_user(self):
|
||||
resources = list(self.mgr.list(user_id='joey'))
|
||||
expect = [
|
||||
'GET', '/v1/users/joey/meters'
|
||||
]
|
||||
self.http_client.assert_called(*expect)
|
||||
self.assertEqual(len(resources), 1)
|
||||
self.assertEqual(resources[0].resource_id, 'b')
|
||||
|
||||
def test_list_by_project(self):
|
||||
resources = list(self.mgr.list(project_id='dig_the_ditch'))
|
||||
expect = [
|
||||
'GET', '/v1/projects/dig_the_ditch/meters'
|
||||
]
|
||||
self.http_client.assert_called(*expect)
|
||||
self.assertEqual(len(resources), 1)
|
||||
self.assertEqual(resources[0].resource_id, 'b')
|
||||
|
||||
def test_list_by_metaquery(self):
|
||||
resources = list(self.mgr.list(metaquery='metadata.zxc_id=foo'))
|
||||
expect = [
|
||||
'GET', '/v1/meters?metadata.zxc_id=foo'
|
||||
]
|
||||
self.http_client.assert_called(*expect)
|
||||
self.assertEqual(len(resources), 1)
|
||||
self.assertEqual(resources[0].resource_id, 'b')
|
||||
@@ -1,65 +0,0 @@
|
||||
# Copyright 2012 OpenStack Foundation
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
from ceilometerclient.openstack.common.apiclient import client
|
||||
from ceilometerclient.openstack.common.apiclient import fake_client
|
||||
from ceilometerclient.tests.unit import utils
|
||||
import ceilometerclient.v1.meters
|
||||
|
||||
|
||||
fixtures = {
|
||||
'/v1/projects': {
|
||||
'GET': (
|
||||
{},
|
||||
{'projects': [
|
||||
'a',
|
||||
'b',
|
||||
]},
|
||||
),
|
||||
},
|
||||
'/v1/sources/source_b/projects': {
|
||||
'GET': (
|
||||
{},
|
||||
{'projects': ['b']},
|
||||
),
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
class ProjectManagerTest(utils.BaseTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(ProjectManagerTest, self).setUp()
|
||||
self.http_client = fake_client.FakeHTTPClient(fixtures=fixtures)
|
||||
self.api = client.BaseClient(self.http_client)
|
||||
self.mgr = ceilometerclient.v1.meters.ProjectManager(self.api)
|
||||
|
||||
def test_list_all(self):
|
||||
projects = list(self.mgr.list())
|
||||
expect = [
|
||||
'GET', '/v1/projects'
|
||||
]
|
||||
self.http_client.assert_called(*expect)
|
||||
self.assertEqual(len(projects), 2)
|
||||
self.assertEqual(projects[0].project_id, 'a')
|
||||
self.assertEqual(projects[1].project_id, 'b')
|
||||
|
||||
def test_list_by_source(self):
|
||||
projects = list(self.mgr.list(source='source_b'))
|
||||
expect = [
|
||||
'GET', '/v1/sources/source_b/projects'
|
||||
]
|
||||
self.http_client.assert_called(*expect)
|
||||
self.assertEqual(len(projects), 1)
|
||||
self.assertEqual(projects[0].project_id, 'b')
|
||||
@@ -1,161 +0,0 @@
|
||||
# Copyright 2012 OpenStack Foundation
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
from ceilometerclient.openstack.common.apiclient import client
|
||||
from ceilometerclient.openstack.common.apiclient import fake_client
|
||||
from ceilometerclient.tests.unit import utils
|
||||
import ceilometerclient.v1.meters
|
||||
|
||||
|
||||
fixtures = {
|
||||
'/v1/resources': {
|
||||
'GET': (
|
||||
{},
|
||||
{'resources': [
|
||||
{
|
||||
'resource_id': 'a',
|
||||
'project_id': 'project_bla',
|
||||
'user_id': 'freddy',
|
||||
'timestamp': 'now',
|
||||
'meter': ['this', 'that'],
|
||||
'metadata': {'zxc_id': 'bla'},
|
||||
},
|
||||
{
|
||||
'resource_id': 'b',
|
||||
'project_id': 'dig_the_ditch',
|
||||
'user_id': 'joey',
|
||||
'timestamp': 'now',
|
||||
'meter': ['this', 'that'],
|
||||
'metadata': {'zxc_id': 'foo'},
|
||||
},
|
||||
]},
|
||||
),
|
||||
},
|
||||
'/v1/users/joey/resources': {
|
||||
'GET': (
|
||||
{},
|
||||
{'resources': [
|
||||
{
|
||||
'resource_id': 'b',
|
||||
'project_id': 'dig_the_ditch',
|
||||
'user_id': 'joey',
|
||||
'timestamp': 'now',
|
||||
'meter': ['this', 'that'],
|
||||
'metadata': {'zxc_id': 'foo'},
|
||||
},
|
||||
]},
|
||||
),
|
||||
},
|
||||
'/v1/resources?metadata.zxc_id=foo': {
|
||||
'GET': (
|
||||
{},
|
||||
{'resources': [
|
||||
{
|
||||
'resource_id': 'b',
|
||||
'project_id': 'dig_the_ditch',
|
||||
'user_id': 'joey',
|
||||
'timestamp': 'now',
|
||||
'meter': ['this', 'that'],
|
||||
'metadata': {'zxc_id': 'foo'},
|
||||
},
|
||||
]},
|
||||
),
|
||||
},
|
||||
'/v1/projects/project_bla/resources': {
|
||||
'GET': (
|
||||
{},
|
||||
{'resources': [
|
||||
{
|
||||
'resource_id': 'a',
|
||||
'project_id': 'project_bla',
|
||||
'user_id': 'freddy',
|
||||
'timestamp': 'now',
|
||||
'meter': ['this', 'that'],
|
||||
'metadata': {'zxc_id': 'bla'},
|
||||
},
|
||||
]},
|
||||
),
|
||||
},
|
||||
'/v1/resources?start_timestamp=now&end_timestamp=now': {
|
||||
'GET': (
|
||||
{},
|
||||
{'resources': [
|
||||
{
|
||||
'resource_id': 'b',
|
||||
'project_id': 'dig_the_ditch',
|
||||
'user_id': 'joey',
|
||||
'timestamp': 'now',
|
||||
'meter': ['this', 'that'],
|
||||
'metadata': {'zxc_id': 'foo'},
|
||||
},
|
||||
]},
|
||||
),
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
class ResourceManagerTest(utils.BaseTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(ResourceManagerTest, self).setUp()
|
||||
self.http_client = fake_client.FakeHTTPClient(fixtures=fixtures)
|
||||
self.api = client.BaseClient(self.http_client)
|
||||
self.mgr = ceilometerclient.v1.meters.ResourceManager(self.api)
|
||||
|
||||
def test_list_all(self):
|
||||
resources = list(self.mgr.list())
|
||||
expect = [
|
||||
'GET', '/v1/resources'
|
||||
]
|
||||
self.http_client.assert_called(*expect)
|
||||
self.assertEqual(len(resources), 2)
|
||||
self.assertEqual(resources[0].resource_id, 'a')
|
||||
self.assertEqual(resources[1].resource_id, 'b')
|
||||
|
||||
def test_list_by_user(self):
|
||||
resources = list(self.mgr.list(user_id='joey'))
|
||||
expect = [
|
||||
'GET', '/v1/users/joey/resources'
|
||||
]
|
||||
self.http_client.assert_called(*expect)
|
||||
self.assertEqual(len(resources), 1)
|
||||
self.assertEqual(resources[0].resource_id, 'b')
|
||||
|
||||
def test_list_by_metaquery(self):
|
||||
resources = list(self.mgr.list(metaquery='metadata.zxc_id=foo'))
|
||||
expect = [
|
||||
'GET', '/v1/resources?metadata.zxc_id=foo'
|
||||
]
|
||||
self.http_client.assert_called(*expect)
|
||||
self.assertEqual(len(resources), 1)
|
||||
self.assertEqual(resources[0].resource_id, 'b')
|
||||
|
||||
def test_list_by_project(self):
|
||||
resources = list(self.mgr.list(project_id='project_bla'))
|
||||
expect = [
|
||||
'GET', '/v1/projects/project_bla/resources'
|
||||
]
|
||||
self.http_client.assert_called(*expect)
|
||||
self.assertEqual(len(resources), 1)
|
||||
self.assertEqual(resources[0].resource_id, 'a')
|
||||
|
||||
def test_list_by_timestamp(self):
|
||||
resources = list(self.mgr.list(start_timestamp='now',
|
||||
end_timestamp='now'))
|
||||
expect = [
|
||||
'GET', '/v1/resources?start_timestamp=now&end_timestamp=now'
|
||||
]
|
||||
self.http_client.assert_called(*expect)
|
||||
self.assertEqual(len(resources), 1)
|
||||
self.assertEqual(resources[0].resource_id, 'b')
|
||||
@@ -1,196 +0,0 @@
|
||||
# Copyright 2012 OpenStack Foundation
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
from ceilometerclient.openstack.common.apiclient import client
|
||||
from ceilometerclient.openstack.common.apiclient import fake_client
|
||||
from ceilometerclient.tests.unit import utils
|
||||
import ceilometerclient.v1.meters
|
||||
|
||||
|
||||
fixtures = {
|
||||
'/v1/users/freddy/meters/balls': {
|
||||
'GET': (
|
||||
{},
|
||||
{'events': [
|
||||
{
|
||||
'resource_id': 'inst-0045',
|
||||
'project_id': 'melbourne_open',
|
||||
'user_id': 'freddy',
|
||||
'name': 'tennis',
|
||||
'type': 'counter',
|
||||
'unit': 'balls',
|
||||
'volume': 3,
|
||||
'timestamp': None,
|
||||
'resource_metadata': None,
|
||||
},
|
||||
]},
|
||||
),
|
||||
},
|
||||
'/v1/sources/openstack/meters/this': {
|
||||
'GET': (
|
||||
{},
|
||||
{'events': [
|
||||
{
|
||||
'resource_id': 'b',
|
||||
'project_id': 'dig_the_ditch',
|
||||
'user_id': 'joey',
|
||||
'name': 'this',
|
||||
'type': 'counter',
|
||||
'unit': 'b',
|
||||
'volume': 45,
|
||||
'timestamp': None,
|
||||
'resource_metadata': None,
|
||||
},
|
||||
]},
|
||||
),
|
||||
},
|
||||
'/v1/projects/dig_the_ditch/meters/meters': {
|
||||
'GET': (
|
||||
{},
|
||||
{'events': [
|
||||
{
|
||||
'resource_id': 'b',
|
||||
'project_id': 'dig_the_ditch',
|
||||
'user_id': 'joey',
|
||||
'name': 'meters',
|
||||
'type': 'counter',
|
||||
'unit': 'meters',
|
||||
'volume': 345,
|
||||
'timestamp': None,
|
||||
'resource_metadata': None,
|
||||
},
|
||||
]},
|
||||
),
|
||||
},
|
||||
'/v1/meters?metadata.zxc_id=foo': {
|
||||
'GET': (
|
||||
{},
|
||||
{'events': [
|
||||
{
|
||||
'resource_id': 'b',
|
||||
'project_id': 'dig_the_ditch',
|
||||
'user_id': 'joey',
|
||||
'name': 'this',
|
||||
'type': 'counter',
|
||||
'unit': 'meters',
|
||||
'volume': 98,
|
||||
'timestamp': None,
|
||||
'resource_metadata': {'zxc_id': 'foo'},
|
||||
},
|
||||
]},
|
||||
),
|
||||
},
|
||||
'/v1/users/freddy/meters/balls?start_timestamp=now&end_timestamp=now': {
|
||||
'GET': (
|
||||
{},
|
||||
{'events': [
|
||||
{
|
||||
'resource_id': 'inst-0045',
|
||||
'project_id': 'melbourne_open',
|
||||
'user_id': 'freddy',
|
||||
'name': 'tennis',
|
||||
'type': 'counter',
|
||||
'unit': 'balls',
|
||||
'volume': 3,
|
||||
'timestamp': 'now',
|
||||
'resource_metadata': None,
|
||||
},
|
||||
|
||||
]},
|
||||
),
|
||||
},
|
||||
'/v1/meters': {
|
||||
'GET': (
|
||||
{},
|
||||
{'meters': []},
|
||||
),
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
class SampleManagerTest(utils.BaseTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(SampleManagerTest, self).setUp()
|
||||
self.http_client = fake_client.FakeHTTPClient(fixtures=fixtures)
|
||||
self.api = client.BaseClient(self.http_client)
|
||||
self.mgr = ceilometerclient.v1.meters.SampleManager(self.api)
|
||||
|
||||
def test_list_all(self):
|
||||
samples = list(self.mgr.list(counter_name=None))
|
||||
expect = [
|
||||
'GET', '/v1/meters'
|
||||
]
|
||||
self.http_client.assert_called(*expect)
|
||||
self.assertEqual(len(samples), 0)
|
||||
|
||||
def test_list_by_source(self):
|
||||
samples = list(self.mgr.list(source='openstack',
|
||||
counter_name='this'))
|
||||
expect = [
|
||||
'GET', '/v1/sources/openstack/meters/this'
|
||||
]
|
||||
self.http_client.assert_called(*expect)
|
||||
self.assertEqual(len(samples), 1)
|
||||
self.assertEqual(samples[0].resource_id, 'b')
|
||||
|
||||
def test_list_by_user(self):
|
||||
samples = list(self.mgr.list(user_id='freddy',
|
||||
counter_name='balls'))
|
||||
expect = [
|
||||
'GET', '/v1/users/freddy/meters/balls'
|
||||
]
|
||||
self.http_client.assert_called(*expect)
|
||||
self.assertEqual(len(samples), 1)
|
||||
self.assertEqual(samples[0].project_id, 'melbourne_open')
|
||||
self.assertEqual(samples[0].user_id, 'freddy')
|
||||
self.assertEqual(samples[0].volume, 3)
|
||||
|
||||
def test_list_by_project(self):
|
||||
samples = list(self.mgr.list(project_id='dig_the_ditch',
|
||||
counter_name='meters'))
|
||||
expect = [
|
||||
'GET', '/v1/projects/dig_the_ditch/meters/meters'
|
||||
]
|
||||
self.http_client.assert_called(*expect)
|
||||
self.assertEqual(len(samples), 1)
|
||||
self.assertEqual(samples[0].project_id, 'dig_the_ditch')
|
||||
self.assertEqual(samples[0].volume, 345)
|
||||
self.assertEqual(samples[0].unit, 'meters')
|
||||
|
||||
def test_list_by_metaquery(self):
|
||||
samples = list(self.mgr.list(metaquery='metadata.zxc_id=foo',
|
||||
counter_name='this'))
|
||||
expect = [
|
||||
'GET', '/v1/meters?metadata.zxc_id=foo'
|
||||
]
|
||||
self.http_client.assert_called(*expect)
|
||||
self.assertEqual(len(samples), 1)
|
||||
self.assertEqual(samples[0].resource_metadata['zxc_id'], 'foo')
|
||||
|
||||
def test_list_by_timestamp(self):
|
||||
samples = list(self.mgr.list(user_id='freddy',
|
||||
counter_name='balls',
|
||||
start_timestamp='now',
|
||||
end_timestamp='now'))
|
||||
expect = [
|
||||
'GET',
|
||||
'/v1/users/freddy/meters/balls?' +
|
||||
'start_timestamp=now&end_timestamp=now'
|
||||
]
|
||||
self.http_client.assert_called(*expect)
|
||||
self.assertEqual(len(samples), 1)
|
||||
self.assertEqual(samples[0].project_id, 'melbourne_open')
|
||||
self.assertEqual(samples[0].user_id, 'freddy')
|
||||
self.assertEqual(samples[0].volume, 3)
|
||||
@@ -1,65 +0,0 @@
|
||||
# Copyright 2012 OpenStack Foundation
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
from ceilometerclient.openstack.common.apiclient import client
|
||||
from ceilometerclient.openstack.common.apiclient import fake_client
|
||||
from ceilometerclient.tests.unit import utils
|
||||
import ceilometerclient.v1.meters
|
||||
|
||||
|
||||
fixtures = {
|
||||
'/v1/users': {
|
||||
'GET': (
|
||||
{},
|
||||
{'users': [
|
||||
'a',
|
||||
'b',
|
||||
]},
|
||||
),
|
||||
},
|
||||
'/v1/sources/source_b/users': {
|
||||
'GET': (
|
||||
{},
|
||||
{'users': ['b']},
|
||||
),
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
class UserManagerTest(utils.BaseTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(UserManagerTest, self).setUp()
|
||||
self.http_client = fake_client.FakeHTTPClient(fixtures=fixtures)
|
||||
self.api = client.BaseClient(self.http_client)
|
||||
self.mgr = ceilometerclient.v1.meters.UserManager(self.api)
|
||||
|
||||
def test_list_all(self):
|
||||
users = list(self.mgr.list())
|
||||
expect = [
|
||||
'GET', '/v1/users'
|
||||
]
|
||||
self.http_client.assert_called(*expect)
|
||||
self.assertEqual(len(users), 2)
|
||||
self.assertEqual(users[0].user_id, 'a')
|
||||
self.assertEqual(users[1].user_id, 'b')
|
||||
|
||||
def test_list_by_source(self):
|
||||
users = list(self.mgr.list(source='source_b'))
|
||||
expect = [
|
||||
'GET', '/v1/sources/source_b/users'
|
||||
]
|
||||
self.http_client.assert_called(*expect)
|
||||
self.assertEqual(len(users), 1)
|
||||
self.assertEqual(users[0].user_id, 'b')
|
||||
@@ -1,16 +0,0 @@
|
||||
# Copyright 2012 OpenStack Foundation
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from ceilometerclient.v1.client import Client # noqa
|
||||
@@ -1,56 +0,0 @@
|
||||
# Copyright 2012 OpenStack Foundation
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
from ceilometerclient import client as ceiloclient
|
||||
from ceilometerclient.v1 import meters
|
||||
|
||||
|
||||
class Client(object):
|
||||
"""Client for the Ceilometer v1 API.
|
||||
|
||||
:param session: a keystoneauth/keystoneclient session object
|
||||
:type session: keystoneclient.session.Session
|
||||
:param str service_type: The default service_type for URL discovery
|
||||
:param str service_name: The default service_name for URL discovery
|
||||
:param str interface: The default interface for URL discovery
|
||||
(Default: public)
|
||||
:param str region_name: The default region_name for URL discovery
|
||||
:param str endpoint_override: Always use this endpoint URL for requests
|
||||
for this ceiloclient
|
||||
:param auth: An auth plugin to use instead of the session one
|
||||
:type auth: keystoneclient.auth.base.BaseAuthPlugin
|
||||
:param str user_agent: The User-Agent string to set
|
||||
(Default is python-ceilometer-client)
|
||||
:param int connect_retries: the maximum number of retries that should be
|
||||
attempted for connection errors
|
||||
:param logger: A logging object
|
||||
:type logger: logging.Logger
|
||||
"""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
"""Initialize a new client for the Ceilometer v1 API."""
|
||||
|
||||
if not kwargs.get('auth_plugin'):
|
||||
kwargs['auth_plugin'] = ceiloclient.get_auth_plugin(*args,
|
||||
**kwargs)
|
||||
self.auth_plugin = kwargs.get('auth_plugin')
|
||||
|
||||
self.http_client = ceiloclient._construct_http_client(**kwargs)
|
||||
self.meters = meters.MeterManager(self.http_client)
|
||||
self.samples = meters.SampleManager(self.http_client)
|
||||
self.users = meters.UserManager(self.http_client)
|
||||
self.resources = meters.ResourceManager(self.http_client)
|
||||
self.projects = meters.ProjectManager(self.http_client)
|
||||
@@ -1,191 +0,0 @@
|
||||
# Copyright 2012 OpenMeter LLC.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import six
|
||||
|
||||
from ceilometerclient.common import base
|
||||
|
||||
|
||||
def _get_opt_path(simple_params=None, **kwargs):
|
||||
l = []
|
||||
simple_params = simple_params or []
|
||||
# get simple paramters
|
||||
for key in simple_params:
|
||||
val = kwargs.get(key)
|
||||
if val:
|
||||
l.append(key + '=' + val)
|
||||
# get metadata query paramters
|
||||
metaquery = kwargs.get('metaquery')
|
||||
if metaquery:
|
||||
l.extend(metaquery.split(':'))
|
||||
|
||||
return '&'.join(l)
|
||||
|
||||
|
||||
class User(base.Resource):
|
||||
def __init__(self, manager, info, loaded=False):
|
||||
_d = {six.u('user_id'): info}
|
||||
super(User, self).__init__(manager, _d, loaded)
|
||||
|
||||
def __repr__(self):
|
||||
return "<User %s>" % self._info
|
||||
|
||||
def data(self, **kwargs):
|
||||
return self.manager.data(self, **kwargs)
|
||||
|
||||
|
||||
class UserManager(base.Manager):
|
||||
resource_class = User
|
||||
|
||||
def list(self, **kwargs):
|
||||
s = kwargs.get('source')
|
||||
if s:
|
||||
path = '/sources/%s/users' % s
|
||||
else:
|
||||
path = '/users'
|
||||
return self._list('/v1%s' % path, 'users')
|
||||
|
||||
|
||||
class Project(base.Resource):
|
||||
def __init__(self, manager, info, loaded=False):
|
||||
_d = {six.u('project_id'): info}
|
||||
super(Project, self).__init__(manager, _d, loaded)
|
||||
|
||||
def __repr__(self):
|
||||
return "<Project %s>" % self._info
|
||||
|
||||
def data(self, **kwargs):
|
||||
return self.manager.data(self, **kwargs)
|
||||
|
||||
|
||||
class ProjectManager(base.Manager):
|
||||
resource_class = Project
|
||||
|
||||
def list(self, **kwargs):
|
||||
s = kwargs.get('source')
|
||||
if s:
|
||||
path = '/sources/%s/projects' % (kwargs['source'])
|
||||
else:
|
||||
path = '/projects'
|
||||
|
||||
return self._list('/v1%s' % path, 'projects')
|
||||
|
||||
|
||||
class Resource(base.Resource):
|
||||
def __repr__(self):
|
||||
return "<Resource %s>" % self._info
|
||||
|
||||
def data(self, **kwargs):
|
||||
return self.manager.data(self, **kwargs)
|
||||
|
||||
|
||||
class ResourceManager(base.Manager):
|
||||
resource_class = Resource
|
||||
|
||||
def list(self, **kwargs):
|
||||
u = kwargs.get('user_id')
|
||||
s = kwargs.get('source')
|
||||
p = kwargs.get('project_id')
|
||||
opts_path = _get_opt_path(['start_timestamp', 'end_timestamp'],
|
||||
**kwargs)
|
||||
if u:
|
||||
path = '/users/%s/resources' % u
|
||||
elif s:
|
||||
path = '/sources/%s/resources' % s
|
||||
elif p:
|
||||
path = '/projects/%s/resources' % p
|
||||
else:
|
||||
path = '/resources'
|
||||
if opts_path:
|
||||
path = '/v1%s?%s' % (path, opts_path)
|
||||
else:
|
||||
path = '/v1%s' % path
|
||||
return self._list(path, 'resources')
|
||||
|
||||
|
||||
class Sample(base.Resource):
|
||||
def __init__(self, manager, info, loaded=False):
|
||||
smaller = dict((k, v) for (k, v) in six.iteritems(info)
|
||||
if k not in ('metadata', 'message_signature'))
|
||||
super(Sample, self).__init__(manager, smaller, loaded)
|
||||
|
||||
def __repr__(self):
|
||||
return "<Sample %s>" % self._info
|
||||
|
||||
def data(self, **kwargs):
|
||||
return self.manager.data(self, **kwargs)
|
||||
|
||||
|
||||
class SampleManager(base.Manager):
|
||||
resource_class = Sample
|
||||
|
||||
def list(self, **kwargs):
|
||||
c = kwargs['counter_name']
|
||||
r = kwargs.get('resource_id')
|
||||
u = kwargs.get('user_id')
|
||||
p = kwargs.get('project_id')
|
||||
s = kwargs.get('source')
|
||||
opts_path = _get_opt_path(['start_timestamp', 'end_timestamp'],
|
||||
**kwargs)
|
||||
if r:
|
||||
path = '/resources/%s/meters/%s' % (r, c)
|
||||
elif u:
|
||||
path = '/users/%s/meters/%s' % (u, c)
|
||||
elif p:
|
||||
path = '/projects/%s/meters/%s' % (p, c)
|
||||
elif s:
|
||||
path = '/sources/%s/meters/%s' % (s, c)
|
||||
else:
|
||||
path = '/meters'
|
||||
|
||||
if opts_path:
|
||||
path = '/v1%s?%s' % (path, opts_path)
|
||||
else:
|
||||
path = '/v1%s' % path
|
||||
return self._list(path, 'events')
|
||||
|
||||
|
||||
class Meter(base.Resource):
|
||||
def __repr__(self):
|
||||
return "<Meter %s>" % self._info
|
||||
|
||||
def data(self, **kwargs):
|
||||
return self.manager.data(self, **kwargs)
|
||||
|
||||
|
||||
class MeterManager(base.Manager):
|
||||
resource_class = Meter
|
||||
|
||||
def list(self, **kwargs):
|
||||
r = kwargs.get('resource_id')
|
||||
u = kwargs.get('user_id')
|
||||
p = kwargs.get('project_id')
|
||||
s = kwargs.get('source')
|
||||
opts_path = _get_opt_path(**kwargs)
|
||||
if u:
|
||||
path = '/users/%s/meters' % u
|
||||
elif r:
|
||||
path = '/resources/%s/meters' % r
|
||||
elif p:
|
||||
path = '/projects/%s/meters' % p
|
||||
elif s:
|
||||
path = '/sources/%s/meters' % s
|
||||
else:
|
||||
path = '/meters'
|
||||
if opts_path:
|
||||
path = '/v1%s?%s' % (path, opts_path)
|
||||
else:
|
||||
path = '/v1%s' % path
|
||||
return self._list(path, 'meters')
|
||||
@@ -1,136 +0,0 @@
|
||||
# Copyright 2012 OpenStack Foundation
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from ceilometerclient.common import utils
|
||||
import ceilometerclient.exc as exc
|
||||
|
||||
|
||||
@utils.arg('-m', '--metaquery', metavar='<METAQUERY>',
|
||||
help='Query into the metadata metadata.key=value:..')
|
||||
@utils.arg('-s', '--source', metavar='<SOURCE>',
|
||||
help='ID of the resource to show samples for.')
|
||||
@utils.arg('-r', '--resource_id', metavar='<RESOURCE_ID>',
|
||||
help='ID of the resource to show samples for.')
|
||||
@utils.arg('-u', '--user_id', metavar='<USER_ID>',
|
||||
help='ID of the user to show samples for.')
|
||||
@utils.arg('-p', '--project_id', metavar='<PROJECT_ID>',
|
||||
help='ID of the project to show samples for.')
|
||||
@utils.arg('-c', '--counter_name', metavar='<NAME>',
|
||||
help='Name of meter to show samples for.')
|
||||
@utils.arg('--start', metavar='<START_TIMESTAMP>',
|
||||
help='ISO date in UTC which limits events by '
|
||||
'timestamp >= this value')
|
||||
@utils.arg('--end', metavar='<END_TIMESTAMP>',
|
||||
help='ISO date in UTC which limits events by '
|
||||
'timestamp <= this value')
|
||||
def do_sample_list(cc, args):
|
||||
'''List the samples for this meters.'''
|
||||
fields = {'counter_name': args.counter_name,
|
||||
'resource_id': args.resource_id,
|
||||
'user_id': args.user_id,
|
||||
'project_id': args.project_id,
|
||||
'source': args.source,
|
||||
'start_timestamp': args.start,
|
||||
'end_timestamp': args.end,
|
||||
'metaquery': args.metaquery}
|
||||
try:
|
||||
samples = cc.samples.list(**fields)
|
||||
except exc.HTTPNotFound:
|
||||
raise exc.CommandError('Samples not found: %s' % args.counter_name)
|
||||
else:
|
||||
field_labels = ['Resource ID', 'Name', 'Type', 'Volume', 'Timestamp']
|
||||
fields = ['resource_id', 'counter_name', 'counter_type',
|
||||
'counter_volume', 'timestamp']
|
||||
utils.print_list(samples, fields, field_labels,
|
||||
sortby=0)
|
||||
|
||||
|
||||
@utils.arg('-m', '--metaquery', metavar='<METAQUERY>',
|
||||
help='Query into the metadata metadata.key=value:..')
|
||||
@utils.arg('-s', '--source', metavar='<SOURCE>',
|
||||
help='ID of the resource to show samples for.')
|
||||
@utils.arg('-r', '--resource_id', metavar='<RESOURCE_ID>',
|
||||
help='ID of the resource to show samples for.')
|
||||
@utils.arg('-u', '--user_id', metavar='<USER_ID>',
|
||||
help='ID of the user to show samples for.')
|
||||
@utils.arg('-p', '--project_id', metavar='<PROJECT_ID>',
|
||||
help='ID of the project to show samples for.')
|
||||
def do_meter_list(cc, args={}):
|
||||
'''List the user's meter.'''
|
||||
fields = {'resource_id': args.resource_id,
|
||||
'user_id': args.user_id,
|
||||
'project_id': args.project_id,
|
||||
'source': args.source}
|
||||
meters = cc.meters.list(**fields)
|
||||
field_labels = ['Name', 'Type', 'Resource ID', 'User ID', 'Project ID']
|
||||
fields = ['name', 'type', 'resource_id',
|
||||
'user_id', 'project_id']
|
||||
utils.print_list(meters, fields, field_labels,
|
||||
sortby=0)
|
||||
|
||||
|
||||
@utils.arg('-s', '--source', metavar='<SOURCE>',
|
||||
help='ID of the resource to show projects for.')
|
||||
def do_user_list(cc, args={}):
|
||||
'''List the users.'''
|
||||
kwargs = {'source': args.source}
|
||||
users = cc.users.list(**kwargs)
|
||||
field_labels = ['User ID']
|
||||
fields = ['user_id']
|
||||
utils.print_list(users, fields, field_labels,
|
||||
sortby=0)
|
||||
|
||||
|
||||
@utils.arg('-s', '--source', metavar='<SOURCE>',
|
||||
help='ID of the resource to show for.')
|
||||
@utils.arg('-u', '--user_id', metavar='<USER_ID>',
|
||||
help='ID of the user to show resources for.')
|
||||
@utils.arg('-p', '--project_id', metavar='<PROJECT_ID>',
|
||||
help='ID of the project to show samples for.')
|
||||
@utils.arg('-m', '--metaquery', metavar='<METAQUERY>',
|
||||
help='Query into the metadata metadata.key=value:..')
|
||||
@utils.arg('--start', metavar='<START_TIMESTAMP>',
|
||||
help='ISO date in UTC which limits resouces by '
|
||||
'last update time >= this value')
|
||||
@utils.arg('--end', metavar='<END_TIMESTAMP>',
|
||||
help='ISO date in UTC which limits resouces by '
|
||||
'last update time <= this value')
|
||||
def do_resource_list(cc, args={}):
|
||||
"""List the resources."""
|
||||
kwargs = {'source': args.source,
|
||||
'user_id': args.user_id,
|
||||
'project_id': args.project_id,
|
||||
'start_timestamp': args.start,
|
||||
'end_timestamp': args.end,
|
||||
'metaquery': args.metaquery}
|
||||
resources = cc.resources.list(**kwargs)
|
||||
|
||||
field_labels = ['Resource ID', 'Source', 'User ID', 'Project ID']
|
||||
fields = ['resource_id', 'source', 'user_id', 'project_id']
|
||||
utils.print_list(resources, fields, field_labels,
|
||||
sortby=1)
|
||||
|
||||
|
||||
@utils.arg('-s', '--source', metavar='<SOURCE>',
|
||||
help='ID of the resource to show projects for.')
|
||||
def do_project_list(cc, args={}):
|
||||
"""List the projects."""
|
||||
kwargs = {'source': args.source}
|
||||
projects = cc.projects.list(**kwargs)
|
||||
|
||||
field_labels = ['Project ID']
|
||||
fields = ['project_id']
|
||||
utils.print_list(projects, fields, field_labels,
|
||||
sortby=0)
|
||||
@@ -14,7 +14,7 @@ First create a client instance with your credentials::
|
||||
>>> import ceilometerclient.client
|
||||
>>> cclient = ceilometerclient.client.get_client(VERSION, os_username=USERNAME, os_password=PASSWORD, os_tenant_name=PROJECT_NAME, os_auth_url=AUTH_URL)
|
||||
|
||||
Here ``VERSION`` can be: ``1`` and ``2``.
|
||||
Here ``VERSION`` should be: ``2``.
|
||||
|
||||
Then call methods on its managers::
|
||||
|
||||
@@ -44,5 +44,4 @@ For more information, see the reference:
|
||||
:maxdepth: 2
|
||||
|
||||
ref/index
|
||||
ref/v1/index
|
||||
ref/v2/index
|
||||
|
||||
@@ -16,8 +16,6 @@ execfile(os.path.join("..", "ext", "gen_ref.py"))
|
||||
project = 'python-ceilometerclient'
|
||||
|
||||
gen_ref("", "Client Reference", ["client", "exc"])
|
||||
gen_ref("v1", "Version 1 API Reference",
|
||||
["meters"])
|
||||
gen_ref("v2", "Version 2 API Reference",
|
||||
["meters", "samples", "statistics", "resources", "query", "alarms",
|
||||
"events", "event_types", "traits", "trait_descriptions"])
|
||||
|
||||
@@ -22,7 +22,6 @@ Contents:
|
||||
shell
|
||||
api
|
||||
ref/index
|
||||
ref/v1/index
|
||||
ref/v2/index
|
||||
|
||||
Contributing
|
||||
|
||||
Reference in New Issue
Block a user