]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Move Timestamp code to separate file
authorZane Bitter <zbitter@redhat.com>
Thu, 25 Oct 2012 20:18:27 +0000 (22:18 +0200)
committerZane Bitter <zbitter@redhat.com>
Thu, 25 Oct 2012 20:28:38 +0000 (22:28 +0200)
Change-Id: I57627f5b9048bbbcda0a07ac274fd1e579348496
Signed-off-by: Zane Bitter <zbitter@redhat.com>
heat/engine/parser.py
heat/engine/resources.py
heat/engine/timestamp.py [new file with mode: 0644]
heat/engine/watchrule.py

index 9f804cd0d61f597e929fed6de26149a1f3b4fb7c..7e82c131ff1a4656f05b5a88490c4cb915e6b3b6 100644 (file)
@@ -23,6 +23,7 @@ from heat.engine import checkeddict
 from heat.engine import dependencies
 from heat.engine import identifier
 from heat.engine import resources
+from heat.engine import timestamp
 from heat.db import api as db_api
 
 from heat.openstack.common import log as logging
@@ -240,8 +241,8 @@ class Stack(object):
     UPDATE_COMPLETE = 'UPDATE_COMPLETE'
     UPDATE_FAILED = 'UPDATE_FAILED'
 
-    created_time = resources.Timestamp(db_api.stack_get, 'created_at')
-    updated_time = resources.Timestamp(db_api.stack_get, 'updated_at')
+    created_time = timestamp.Timestamp(db_api.stack_get, 'created_at')
+    updated_time = timestamp.Timestamp(db_api.stack_get, 'updated_at')
 
     def __init__(self, context, stack_name, template, parameters=None,
                  stack_id=None, state=None, state_description='',
index 90439c828a15595e7fd82b109f45a93cc71d4139..2b15e2a7727dfa03c529ce80375d30cd3e72ad54 100644 (file)
@@ -31,7 +31,7 @@ from heat.common import exception
 from heat.common import config
 from heat.db import api as db_api
 from heat.engine import checkeddict
-from heat.engine import auth
+from heat.engine import timestamp
 
 from heat.openstack.common import log as logging
 from heat.openstack.common import cfg
@@ -74,39 +74,6 @@ class Metadata(object):
             return None
 
 
-class Timestamp(object):
-    '''
-    A descriptor for fetching an up-to-date timestamp from the database.
-    '''
-
-    def __init__(self, db_fetch, attribute):
-        '''
-        Initialise with a function to fetch the database representation of an
-        object (given a context and ID) and the name of the attribute to
-        retrieve.
-        '''
-        self.db_fetch = db_fetch
-        self.attribute = attribute
-
-    def __get__(self, obj, obj_class):
-        '''
-        Get the latest data from the database for the given object and class.
-        '''
-        if obj is None or obj.id is None:
-            return None
-
-        o = self.db_fetch(obj.context, obj.id)
-        o.refresh(attrs=[self.attribute])
-        return getattr(o, self.attribute)
-
-    def __set__(self, obj, timestamp):
-        '''Update the timestamp for the given object.'''
-        if obj.id is None:
-            raise AttributeError("%s has not yet been created" % str(obj))
-        o = self.db_fetch(obj.context, obj.id)
-        o.update_and_save({self.attribute: timestamp})
-
-
 class Resource(object):
     # Status strings
     CREATE_IN_PROGRESS = 'IN_PROGRESS'
@@ -128,8 +95,8 @@ class Resource(object):
     # If True, this resource must be created before it can be referenced.
     strict_dependency = True
 
-    created_time = Timestamp(db_api.resource_get, 'created_at')
-    updated_time = Timestamp(db_api.resource_get, 'updated_at')
+    created_time = timestamp.Timestamp(db_api.resource_get, 'created_at')
+    updated_time = timestamp.Timestamp(db_api.resource_get, 'updated_at')
 
     metadata = Metadata()
 
diff --git a/heat/engine/timestamp.py b/heat/engine/timestamp.py
new file mode 100644 (file)
index 0000000..c271c5c
--- /dev/null
@@ -0,0 +1,47 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+#
+#    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.
+
+
+class Timestamp(object):
+    '''
+    A descriptor for fetching an up-to-date timestamp from the database.
+    '''
+
+    def __init__(self, db_fetch, attribute):
+        '''
+        Initialise with a function to fetch the database representation of an
+        object (given a context and ID) and the name of the attribute to
+        retrieve.
+        '''
+        self.db_fetch = db_fetch
+        self.attribute = attribute
+
+    def __get__(self, obj, obj_class):
+        '''
+        Get the latest data from the database for the given object and class.
+        '''
+        if obj is None or obj.id is None:
+            return None
+
+        o = self.db_fetch(obj.context, obj.id)
+        o.refresh(attrs=[self.attribute])
+        return getattr(o, self.attribute)
+
+    def __set__(self, obj, timestamp):
+        '''Update the timestamp for the given object.'''
+        if obj.id is None:
+            raise AttributeError("%s has not yet been created" % str(obj))
+        o = self.db_fetch(obj.context, obj.id)
+        o.update_and_save({self.attribute: timestamp})
index 5d150655cf6b8b9b9ae5c3de526fe32158e519d2..abc0a109ef79a1d7c715bbef42c5601146cf7a3d 100644 (file)
@@ -17,7 +17,7 @@
 import datetime
 from heat.openstack.common import log as logging
 from heat.openstack.common import timeutils
-from heat.engine import resources
+from heat.engine import timestamp
 from heat.db import api as db_api
 from heat.engine import parser
 from heat.common import context as ctxtlib
@@ -35,8 +35,8 @@ class WatchRule(object):
                   NORMAL: 'OKActions',
                   NODATA: 'InsufficientDataActions'}
 
-    created_at = resources.Timestamp(db_api.watch_rule_get, 'created_at')
-    updated_at = resources.Timestamp(db_api.watch_rule_get, 'updated_at')
+    created_at = timestamp.Timestamp(db_api.watch_rule_get, 'created_at')
+    updated_at = timestamp.Timestamp(db_api.watch_rule_get, 'updated_at')
 
     def __init__(self, context, watch_name, rule, stack_name, state=NORMAL,
                  wid=None, watch_data=[], last_evaluated=timeutils.utcnow()):