Port metric v1 to resource2

This change ports metric v1 to resource2. Note that most of this stuff
isn't exposed in the proxy, but that change should be made elsewhere. I
also removed the resource.Generic.create method as that doesn't seem
necessary based on what's documented.

Change-Id: I662ad4811ff84bd7b7726d02d676e9f5f05e3808
This commit is contained in:
Brian Curtin
2017-04-27 12:49:53 -04:00
parent bfc88e76f3
commit fb4a329501
10 changed files with 41 additions and 46 deletions

View File

@@ -11,7 +11,7 @@
# under the License. # under the License.
from openstack.metric.v1 import capabilities from openstack.metric.v1 import capabilities
from openstack import proxy from openstack import proxy2 as proxy
class Proxy(proxy.BaseProxy): class Proxy(proxy.BaseProxy):

View File

@@ -11,7 +11,7 @@
# under the License. # under the License.
from openstack.metric import metric_service from openstack.metric import metric_service
from openstack import resource from openstack import resource2 as resource
class ArchivePolicy(resource.Resource): class ArchivePolicy(resource.Resource):
@@ -20,18 +20,16 @@ class ArchivePolicy(resource.Resource):
# Supported Operations # Supported Operations
allow_create = True allow_create = True
allow_retrieve = True allow_get = True
allow_delete = True allow_delete = True
allow_list = True allow_list = True
id_attribute = "name"
# Properties # Properties
#: The name of this policy #: The name of this policy
name = resource.prop('name') name = resource.Body('name', alternate_id=True)
#: The definition of this policy #: The definition of this policy
definition = resource.prop('definition', type=list) definition = resource.Body('definition', type=list)
#: The window of time older than the period that archives can be requested #: The window of time older than the period that archives can be requested
back_window = resource.prop('back_window') back_window = resource.Body('back_window')
#: A list of the aggregation methods supported #: A list of the aggregation methods supported
aggregation_methods = resource.prop("aggregation_methods", type=list) aggregation_methods = resource.Body("aggregation_methods", type=list)

View File

@@ -11,7 +11,7 @@
# under the License. # under the License.
from openstack.metric import metric_service from openstack.metric import metric_service
from openstack import resource from openstack import resource2 as resource
class Capabilities(resource.Resource): class Capabilities(resource.Resource):
@@ -19,7 +19,7 @@ class Capabilities(resource.Resource):
service = metric_service.MetricService() service = metric_service.MetricService()
# Supported Operations # Supported Operations
allow_retrieve = True allow_get = True
#: The supported methods of aggregation. #: The supported methods of aggregation.
aggregation_methods = resource.prop('aggregation_methods', type=list) aggregation_methods = resource.Body('aggregation_methods', type=list)

View File

@@ -11,7 +11,7 @@
# under the License. # under the License.
from openstack.metric import metric_service from openstack.metric import metric_service
from openstack import resource from openstack import resource2 as resource
class Metric(resource.Resource): class Metric(resource.Resource):
@@ -20,20 +20,20 @@ class Metric(resource.Resource):
# Supported Operations # Supported Operations
allow_create = True allow_create = True
allow_retrieve = True allow_get = True
allow_delete = True allow_delete = True
allow_list = True allow_list = True
# Properties # Properties
#: The name of the archive policy #: The name of the archive policy
archive_policy_name = resource.prop('archive_policy_name') archive_policy_name = resource.Body('archive_policy_name')
#: The archive policy #: The archive policy
archive_policy = resource.prop('archive_policy') archive_policy = resource.Body('archive_policy')
#: The ID of the user who created this metric #: The ID of the user who created this metric
created_by_user_id = resource.prop('created_by_user_id') created_by_user_id = resource.Body('created_by_user_id')
#: The ID of the project this metric was created under #: The ID of the project this metric was created under
created_by_project_id = resource.prop('created_by_project_id') created_by_project_id = resource.Body('created_by_project_id')
#: The identifier of this metric #: The identifier of this metric
resource_id = resource.prop('resource_id') resource_id = resource.Body('resource_id')
#: The name of this metric #: The name of this metric
name = resource.prop('name') name = resource.Body('name')

View File

@@ -11,7 +11,7 @@
# under the License. # under the License.
from openstack.metric import metric_service from openstack.metric import metric_service
from openstack import resource from openstack import resource2 as resource
class Generic(resource.Resource): class Generic(resource.Resource):
@@ -20,31 +20,27 @@ class Generic(resource.Resource):
# Supported Operations # Supported Operations
allow_create = True allow_create = True
allow_retrieve = True allow_get = True
allow_delete = True allow_delete = True
allow_list = True allow_list = True
allow_update = True allow_update = True
# Properties # Properties
#: The identifier of this resource #: The identifier of this resource
id = resource.prop('id', alias="resource_id") id = resource.Body('id')
#: The ID of the user who created this resource #: The ID of the user who created this resource
created_by_user_id = resource.prop('created_by_user_id') created_by_user_id = resource.Body('created_by_user_id')
#: The ID of the project this resource was created under #: The ID of the project this resource was created under
created_by_project_id = resource.prop('created_by_project_id') created_by_project_id = resource.Body('created_by_project_id')
#: The ID of the user #: The ID of the user
user_id = resource.prop('user_id') user_id = resource.Body('user_id')
#: The ID of the project #: The ID of the project
project_id = resource.prop('project_id') project_id = resource.Body('project_id')
#: Timestamp when this resource was started #: Timestamp when this resource was started
started_at = resource.prop('started_at') started_at = resource.Body('started_at')
#: Timestamp when this resource was ended #: Timestamp when this resource was ended
ended_at = resource.prop('ended_at') ended_at = resource.Body('ended_at')
#: A dictionary of metrics collected on this resource #: A dictionary of metrics collected on this resource
metrics = resource.prop('metrics', type=dict) metrics = resource.Body('metrics', type=dict)
#: The type of resource
def create(self, session): type = resource.Body('type')
resp = self.create_by_id(session, self._attrs)
self._attrs[self.id_attribute] = resp[self.id_attribute]
self._reset_dirty()
return self

View File

@@ -47,14 +47,15 @@ class TestArchivePolicy(testtools.TestCase):
self.assertEqual('/archive_policy', m.base_path) self.assertEqual('/archive_policy', m.base_path)
self.assertEqual('metric', m.service.service_type) self.assertEqual('metric', m.service.service_type)
self.assertTrue(m.allow_create) self.assertTrue(m.allow_create)
self.assertTrue(m.allow_retrieve) self.assertTrue(m.allow_get)
self.assertFalse(m.allow_update) self.assertFalse(m.allow_update)
self.assertTrue(m.allow_delete) self.assertTrue(m.allow_delete)
self.assertTrue(m.allow_list) self.assertTrue(m.allow_list)
def test_make_it(self): def test_make_it(self):
m = archive_policy.ArchivePolicy(EXAMPLE) m = archive_policy.ArchivePolicy(**EXAMPLE)
self.assertEqual(EXAMPLE['name'], m.name) self.assertEqual(EXAMPLE['name'], m.name)
self.assertEqual(EXAMPLE['name'], m.id)
self.assertEqual(EXAMPLE['definition'], m.definition) self.assertEqual(EXAMPLE['definition'], m.definition)
self.assertEqual(EXAMPLE['back_window'], m.back_window) self.assertEqual(EXAMPLE['back_window'], m.back_window)
self.assertEqual(EXAMPLE['aggregation_methods'], m.aggregation_methods) self.assertEqual(EXAMPLE['aggregation_methods'], m.aggregation_methods)

View File

@@ -25,12 +25,12 @@ class TestCapabilites(testtools.TestCase):
self.assertEqual('/capabilities', sot.base_path) self.assertEqual('/capabilities', sot.base_path)
self.assertEqual('metric', sot.service.service_type) self.assertEqual('metric', sot.service.service_type)
self.assertFalse(sot.allow_create) self.assertFalse(sot.allow_create)
self.assertTrue(sot.allow_retrieve) self.assertTrue(sot.allow_get)
self.assertFalse(sot.allow_update) self.assertFalse(sot.allow_update)
self.assertFalse(sot.allow_delete) self.assertFalse(sot.allow_delete)
self.assertFalse(sot.allow_list) self.assertFalse(sot.allow_list)
def test_make_it(self): def test_make_it(self):
sot = capabilities.Capabilities(BODY) sot = capabilities.Capabilities(**BODY)
self.assertEqual(BODY['aggregation_methods'], self.assertEqual(BODY['aggregation_methods'],
sot.aggregation_methods) sot.aggregation_methods)

View File

@@ -52,13 +52,13 @@ class TestMetric(testtools.TestCase):
self.assertEqual('/metric', m.base_path) self.assertEqual('/metric', m.base_path)
self.assertEqual('metric', m.service.service_type) self.assertEqual('metric', m.service.service_type)
self.assertTrue(m.allow_create) self.assertTrue(m.allow_create)
self.assertTrue(m.allow_retrieve) self.assertTrue(m.allow_get)
self.assertFalse(m.allow_update) self.assertFalse(m.allow_update)
self.assertTrue(m.allow_delete) self.assertTrue(m.allow_delete)
self.assertTrue(m.allow_list) self.assertTrue(m.allow_list)
def test_make_it(self): def test_make_it(self):
m = metric.Metric(EXAMPLE) m = metric.Metric(**EXAMPLE)
self.assertEqual(EXAMPLE['id'], m.id) self.assertEqual(EXAMPLE['id'], m.id)
self.assertEqual(EXAMPLE['archive_policy_name'], m.archive_policy_name) self.assertEqual(EXAMPLE['archive_policy_name'], m.archive_policy_name)
self.assertEqual(EXAMPLE['created_by_user_id'], m.created_by_user_id) self.assertEqual(EXAMPLE['created_by_user_id'], m.created_by_user_id)
@@ -67,7 +67,7 @@ class TestMetric(testtools.TestCase):
self.assertEqual(EXAMPLE['resource_id'], m.resource_id) self.assertEqual(EXAMPLE['resource_id'], m.resource_id)
self.assertEqual(EXAMPLE['name'], m.name) self.assertEqual(EXAMPLE['name'], m.name)
m = metric.Metric(EXAMPLE_AP) m = metric.Metric(**EXAMPLE_AP)
self.assertEqual(EXAMPLE_AP['id'], m.id) self.assertEqual(EXAMPLE_AP['id'], m.id)
self.assertEqual(EXAMPLE_AP['archive_policy'], m.archive_policy) self.assertEqual(EXAMPLE_AP['archive_policy'], m.archive_policy)
self.assertEqual(EXAMPLE_AP['created_by_user_id'], self.assertEqual(EXAMPLE_AP['created_by_user_id'],

View File

@@ -12,7 +12,7 @@
from openstack.metric.v1 import _proxy from openstack.metric.v1 import _proxy
from openstack.metric.v1 import capabilities from openstack.metric.v1 import capabilities
from openstack.tests.unit import test_proxy_base from openstack.tests.unit import test_proxy_base2 as test_proxy_base
class TestMetricProxy(test_proxy_base.TestProxyBase): class TestMetricProxy(test_proxy_base.TestProxyBase):

View File

@@ -36,13 +36,13 @@ class TestResource(testtools.TestCase):
self.assertEqual('/resource/generic', m.base_path) self.assertEqual('/resource/generic', m.base_path)
self.assertEqual('metric', m.service.service_type) self.assertEqual('metric', m.service.service_type)
self.assertTrue(m.allow_create) self.assertTrue(m.allow_create)
self.assertTrue(m.allow_retrieve) self.assertTrue(m.allow_get)
self.assertTrue(m.allow_update) self.assertTrue(m.allow_update)
self.assertTrue(m.allow_delete) self.assertTrue(m.allow_delete)
self.assertTrue(m.allow_list) self.assertTrue(m.allow_list)
def test_make_generic(self): def test_make_generic(self):
r = resource.Generic(EXAMPLE_GENERIC) r = resource.Generic(**EXAMPLE_GENERIC)
self.assertEqual(EXAMPLE_GENERIC['created_by_user_id'], self.assertEqual(EXAMPLE_GENERIC['created_by_user_id'],
r.created_by_user_id) r.created_by_user_id)
self.assertEqual(EXAMPLE_GENERIC['created_by_project_id'], self.assertEqual(EXAMPLE_GENERIC['created_by_project_id'],