summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosh Kearney <josh@jk0.org>2011-03-24 10:30:09 -0500
committerJosh Kearney <josh@jk0.org>2011-03-24 10:30:09 -0500
commitcf70a1a76dfa0456ea6230eaa014fa98e7ddd464 (patch)
tree74cd73f91f7a227855a53b32272b87e769c0a2e8
parent97ac70c45b78dcffeeb53f7408c42e3e240ca6d7 (diff)
downloadnova-cf70a1a76dfa0456ea6230eaa014fa98e7ddd464.tar.gz
nova-cf70a1a76dfa0456ea6230eaa014fa98e7ddd464.tar.xz
nova-cf70a1a76dfa0456ea6230eaa014fa98e7ddd464.zip
Small refactor
-rw-r--r--nova/utils.py7
-rw-r--r--nova/virt/xenapi/vmops.py18
2 files changed, 11 insertions, 14 deletions
diff --git a/nova/utils.py b/nova/utils.py
index 03a6e8095..6042a5332 100644
--- a/nova/utils.py
+++ b/nova/utils.py
@@ -336,11 +336,8 @@ utcnow.override_time = None
def is_older_than(before, seconds):
- """Return True if before is older than 'seconds'"""
- if utcnow() - before > datetime.timedelta(seconds=seconds):
- return True
- else:
- return False
+ """Return True if before is older than seconds"""
+ return utcnow() - before > datetime.timedelta(seconds=seconds)
def utcnow_ts():
diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py
index 84cf836ac..6c1f6424a 100644
--- a/nova/virt/xenapi/vmops.py
+++ b/nova/virt/xenapi/vmops.py
@@ -528,7 +528,7 @@ class VMOps(object):
vbd_refs = self._session.get_xenapi().VM.get_VBDs(rescue_vm_ref)
for vbd_ref in vbd_refs:
vbd_rec = self._session.get_xenapi().VBD.get_record(vbd_ref)
- if vbd_rec["userdevice"] == "1": # primary VBD is always 1
+ if vbd_rec.get("userdevice", None) == "1": # VBD is always 1
VMHelper.unplug_vbd(self._session, vbd_ref)
VMHelper.destroy_vbd(self._session, vbd_ref)
@@ -712,18 +712,18 @@ class VMOps(object):
in rescue mode for >= the provided timeout
"""
last_ran = self.poll_rescue_last_ran
- if last_ran:
- if not utils.is_older_than(last_ran, timeout):
- # Do not run. Let's bail.
- return
- else:
- # Update the time tracker and proceed.
- self.poll_rescue_last_ran = utils.utcnow()
- else:
+ if not last_ran:
# We need a base time to start tracking.
self.poll_rescue_last_ran = utils.utcnow()
return
+ if not utils.is_older_than(last_ran, timeout):
+ # Do not run. Let's bail.
+ return
+
+ # Update the time tracker and proceed.
+ self.poll_rescue_last_ran = utils.utcnow()
+
rescue_vms = []
for instance in self.list_instances():
if instance.endswith("-rescue"):