Consistent resource.prop for timestamps and booleans (compute)

This patch set updates all compute objects to use consistent
resource.prop for timestamps and booleans. In particular, the
following changes were made:
  - Clarify documentation for timestamp and boolean attributes
  - Use 'is_' prefix and boolean type for boolean attributes
  - Use '_at' suffix and timestamp type for timestamp attributes

Change-Id: I6dbb946dad0d9daee5fd766fab6577e9701edb35
Partial-Bug: #1544584
This commit is contained in:
Richard Theis 2016-03-11 09:00:35 -06:00
parent db553996c0
commit 94d637cfcd
8 changed files with 40 additions and 19 deletions

View File

@ -11,6 +11,7 @@
# under the License.
from openstack.compute import compute_service
from openstack import format
from openstack import resource
@ -37,5 +38,6 @@ class Extension(resource.Resource):
name = resource.prop('name')
#: A URL pointing to the namespace for this extension.
namespace = resource.prop('namespace')
# Timestamp when this extension was last updated.
updated = resource.prop('updated')
#: Timestamp when this extension was last updated.
#: *Type: datetime object parsed from ISO 8601 formatted string*
updated_at = resource.prop('updated', type=format.ISO8601)

View File

@ -46,8 +46,8 @@ class Flavor(resource.Resource):
swap = resource.prop('swap')
#: Size of the ephemeral data disk attached to this server. *Type: int*
ephemeral = resource.prop('OS-FLV-EXT-DATA:ephemeral', type=int)
#: ``True`` if this flavor is disabled, ``False`` if not.
disabled = resource.prop('OS-FLV-DISABLED:disabled')
#: ``True`` if this flavor is disabled, ``False`` if not. *Type: bool*
is_disabled = resource.prop('OS-FLV-DISABLED:disabled', type=bool)
#: The bandwidth scaling factor this flavor receives on the network.
rxtx_factor = resource.prop('rxtx_factor', type=float)

View File

@ -12,6 +12,7 @@
from openstack.compute import compute_service
from openstack.compute.v2 import metadata
from openstack import format
from openstack import resource
@ -33,7 +34,8 @@ class Image(resource.Resource, metadata.MetadataMixin):
#: The name of this image.
name = resource.prop('name')
#: Timestamp when the image was created.
created_at = resource.prop('created')
#: *Type: datetime object parsed from ISO 8601 formatted string*
created_at = resource.prop('created', type=format.ISO8601)
#: Metadata pertaining to this image. *Type: dict*
metadata = resource.prop('metadata', type=dict)
#: The mimimum disk size. *Type: int*
@ -46,7 +48,8 @@ class Image(resource.Resource, metadata.MetadataMixin):
#: The status of this image.
status = resource.prop('status')
#: Timestamp when the image was updated.
updated_at = resource.prop('updated')
#: *Type: datetime object parsed from ISO 8601 formatted string*
updated_at = resource.prop('updated', type=format.ISO8601)
#: Size of the image in bytes. *Type: int*
size = resource.prop('OS-EXT-IMG-SIZE:size', type=int)

View File

@ -12,6 +12,7 @@
from openstack.compute import compute_service
from openstack.compute.v2 import metadata
from openstack import format
from openstack import resource
from openstack import utils
@ -40,7 +41,8 @@ class Server(resource.Resource, metadata.MetadataMixin):
#: of the IP address. *Type: dict*
addresses = resource.prop('addresses', type=dict)
#: Timestamp of when the server was created.
created_at = resource.prop('created')
#: *Type: datetime object parsed from ISO 8601 formatted string*
created_at = resource.prop('created', type=format.ISO8601)
#: The flavor reference, as a ID or full URL, for the flavor to use for
#: this server.
flavor_id = resource.prop('flavorRef')
@ -67,7 +69,8 @@ class Server(resource.Resource, metadata.MetadataMixin):
#: ``SUSPENDED``, ``UNKNOWN``, or ``VERIFY_RESIZE``.
status = resource.prop('status')
#: Timestamp of when this server was last updated.
updated_at = resource.prop('updated')
#: *Type: datetime object parsed from ISO 8601 formatted string*
updated_at = resource.prop('updated', type=format.ISO8601)
#: The user ID associated with this server.
user_id = resource.prop('user_id')

View File

@ -9,6 +9,7 @@
# 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 datetime
import testtools
@ -21,7 +22,7 @@ EXAMPLE = {
'links': '3',
'name': '4',
'namespace': '5',
'updated': '6',
'updated': '2015-03-09T12:14:57.233772',
}
@ -47,4 +48,6 @@ class TestExtension(testtools.TestCase):
self.assertEqual(EXAMPLE['links'], sot.links)
self.assertEqual(EXAMPLE['name'], sot.name)
self.assertEqual(EXAMPLE['namespace'], sot.namespace)
self.assertEqual(EXAMPLE['updated'], sot.updated)
dt = datetime.datetime(2015, 3, 9, 12, 14, 57, 233772).replace(
tzinfo=None)
self.assertEqual(dt, sot.updated_at.replace(tzinfo=None))

View File

@ -58,7 +58,7 @@ class TestFlavor(testtools.TestCase):
self.assertEqual(BASIC_EXAMPLE['OS-FLV-EXT-DATA:ephemeral'],
sot.ephemeral)
self.assertEqual(BASIC_EXAMPLE['OS-FLV-DISABLED:disabled'],
sot.disabled)
sot.is_disabled)
self.assertEqual(BASIC_EXAMPLE['rxtx_factor'], sot.rxtx_factor)
def test_detail(self):

View File

@ -9,6 +9,7 @@
# 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 datetime
import testtools
@ -22,13 +23,13 @@ BASIC_EXAMPLE = {
}
DETAILS = {
'created': '1',
'created': '2015-03-09T12:14:57.233772',
'metadata': {'key': '2'},
'minDisk': 3,
'minRam': 4,
'progress': 5,
'status': '6',
'updated': '7',
'updated': '2015-03-09T12:15:57.233772',
'OS-EXT-IMG-SIZE:size': 8
}
@ -70,7 +71,9 @@ class TestImage(testtools.TestCase):
def test_make_detail(self):
sot = image.ImageDetail(DETAIL_EXAMPLE)
self.assertEqual(DETAIL_EXAMPLE['created'], sot.created_at)
dt = datetime.datetime(2015, 3, 9, 12, 14, 57, 233772).replace(
tzinfo=None)
self.assertEqual(dt, sot.created_at.replace(tzinfo=None))
self.assertEqual(DETAIL_EXAMPLE['id'], sot.id)
self.assertEqual(DETAIL_EXAMPLE['links'], sot.links)
self.assertEqual(DETAIL_EXAMPLE['metadata'], sot.metadata)
@ -79,5 +82,7 @@ class TestImage(testtools.TestCase):
self.assertEqual(DETAIL_EXAMPLE['name'], sot.name)
self.assertEqual(DETAIL_EXAMPLE['progress'], sot.progress)
self.assertEqual(DETAIL_EXAMPLE['status'], sot.status)
self.assertEqual(DETAIL_EXAMPLE['updated'], sot.updated_at)
dt = datetime.datetime(2015, 3, 9, 12, 15, 57, 233772).replace(
tzinfo=None)
self.assertEqual(dt, sot.updated_at.replace(tzinfo=None))
self.assertEqual(DETAIL_EXAMPLE['OS-EXT-IMG-SIZE:size'], sot.size)

View File

@ -11,6 +11,7 @@
# under the License.
import copy
import datetime
import mock
import testtools
@ -22,7 +23,7 @@ EXAMPLE = {
'accessIPv4': '1',
'accessIPv6': '2',
'addresses': {'region': '3'},
'created': '4',
'created': '2015-03-09T12:14:57.233772',
'flavorRef': '5',
'hostId': '6',
'id': IDENTIFIER,
@ -33,7 +34,7 @@ EXAMPLE = {
'progress': 12,
'tenant_id': '13',
'status': '14',
'updated': '15',
'updated': '2015-03-09T12:15:57.233772',
'user_id': '16',
}
@ -65,7 +66,9 @@ class TestServer(testtools.TestCase):
self.assertEqual(EXAMPLE['accessIPv4'], sot.access_ipv4)
self.assertEqual(EXAMPLE['accessIPv6'], sot.access_ipv6)
self.assertEqual(EXAMPLE['addresses'], sot.addresses)
self.assertEqual(EXAMPLE['created'], sot.created_at)
dt = datetime.datetime(2015, 3, 9, 12, 14, 57, 233772).replace(
tzinfo=None)
self.assertEqual(dt, sot.created_at.replace(tzinfo=None))
self.assertEqual(EXAMPLE['flavorRef'], sot.flavor_id)
self.assertEqual(EXAMPLE['hostId'], sot.host_id)
self.assertEqual(EXAMPLE['id'], sot.id)
@ -76,7 +79,9 @@ class TestServer(testtools.TestCase):
self.assertEqual(EXAMPLE['progress'], sot.progress)
self.assertEqual(EXAMPLE['tenant_id'], sot.project_id)
self.assertEqual(EXAMPLE['status'], sot.status)
self.assertEqual(EXAMPLE['updated'], sot.updated_at)
dt = datetime.datetime(2015, 3, 9, 12, 15, 57, 233772).replace(
tzinfo=None)
self.assertEqual(dt, sot.updated_at.replace(tzinfo=None))
self.assertEqual(EXAMPLE['user_id'], sot.user_id)
def test_detail(self):