From 56737be36ffcc97c1498c0d4320d825268125922 Mon Sep 17 00:00:00 2001 From: Clark Boylan Date: Mon, 22 Sep 2014 16:53:07 -0700 Subject: [PATCH] Move the ImageUpdater base class for clarity. The location of the ImageUpdater base class was slightly confusing as it was not grouped with its children. Move it so that locality better represents the relationships between our classes. Change-Id: I2a5ce182098aa0b15cb47d7f425018f4f8e87450 --- nodepool/nodepool.py | 96 ++++++++++++++++++++++---------------------- 1 file changed, 48 insertions(+), 48 deletions(-) diff --git a/nodepool/nodepool.py b/nodepool/nodepool.py index ac4cb1130..a083f0ca4 100644 --- a/nodepool/nodepool.py +++ b/nodepool/nodepool.py @@ -703,54 +703,6 @@ class ImageDeleter(threading.Thread): self.snap_image_id) -class ImageUpdater(threading.Thread): - log = logging.getLogger("nodepool.ImageUpdater") - - def __init__(self, nodepool, provider, image, snap_image_id): - threading.Thread.__init__(self, name='ImageUpdater for %s' % - snap_image_id) - self.provider = provider - self.image = image - self.snap_image_id = snap_image_id - self.nodepool = nodepool - self.scriptdir = self.nodepool.config.scriptdir - self.elementsdir = self.nodepool.config.elementsdir - self.imagesdir = self.nodepool.config.imagesdir - - def run(self): - try: - self._run() - except Exception: - self.log.exception("Exception in run method:") - - def _run(self): - with self.nodepool.getDB().getSession() as session: - self.log.debug("Updating image %s in %s " % (self.image.name, - self.provider.name)) - try: - self.snap_image = session.getSnapshotImage( - self.snap_image_id) - self.manager = self.nodepool.getProviderManager(self.provider) - except Exception: - self.log.exception("Exception preparing to update image %s " - "in %s:" % (self.image.name, - self.provider.name)) - return - - try: - self.updateImage(session) - except Exception: - self.log.exception("Exception updating image %s in %s:" % - (self.image.name, self.provider.name)) - try: - if self.snap_image: - self.nodepool.deleteImage(self.snap_image.id) - except Exception: - self.log.exception("Exception deleting image id: %s:" % - self.snap_image.id) - return - - class DiskImageBuilder(threading.Thread): log = logging.getLogger("nodepool.DiskImageBuilderThread") @@ -842,6 +794,54 @@ class DiskImageBuilder(threading.Thread): self.log.info("Image %s is built" % self.dib_image.image_name) +class ImageUpdater(threading.Thread): + log = logging.getLogger("nodepool.ImageUpdater") + + def __init__(self, nodepool, provider, image, snap_image_id): + threading.Thread.__init__(self, name='ImageUpdater for %s' % + snap_image_id) + self.provider = provider + self.image = image + self.snap_image_id = snap_image_id + self.nodepool = nodepool + self.scriptdir = self.nodepool.config.scriptdir + self.elementsdir = self.nodepool.config.elementsdir + self.imagesdir = self.nodepool.config.imagesdir + + def run(self): + try: + self._run() + except Exception: + self.log.exception("Exception in run method:") + + def _run(self): + with self.nodepool.getDB().getSession() as session: + self.log.debug("Updating image %s in %s " % (self.image.name, + self.provider.name)) + try: + self.snap_image = session.getSnapshotImage( + self.snap_image_id) + self.manager = self.nodepool.getProviderManager(self.provider) + except Exception: + self.log.exception("Exception preparing to update image %s " + "in %s:" % (self.image.name, + self.provider.name)) + return + + try: + self.updateImage(session) + except Exception: + self.log.exception("Exception updating image %s in %s:" % + (self.image.name, self.provider.name)) + try: + if self.snap_image: + self.nodepool.deleteImage(self.snap_image.id) + except Exception: + self.log.exception("Exception deleting image id: %s:" % + self.snap_image.id) + return + + class DiskImageUpdater(ImageUpdater): log = logging.getLogger("nodepool.DiskImageUpdater")