summaryrefslogtreecommitdiff
path: root/cloudinit/config/cc_growpart.py
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2013-03-05 18:32:24 +0000
committerScott Moser <smoser@ubuntu.com>2013-03-05 18:32:24 +0000
commit00416dd5cd8f0fb507f64a7f0035fbe706c3f279 (patch)
treeb3889b0e5d29355be632a118af41026e1fdefdbc /cloudinit/config/cc_growpart.py
parent34a76e2be8a3eb4f8490183f12a67a01276575ff (diff)
downloadvyos-cloud-init-00416dd5cd8f0fb507f64a7f0035fbe706c3f279.tar.gz
vyos-cloud-init-00416dd5cd8f0fb507f64a7f0035fbe706c3f279.zip
remove 'log' passing. call growpart with --dry-run first.
growrun --dry-run will exit 1 if it wouldn't do anything. so call it, check for '1' and if no change, then just return.
Diffstat (limited to 'cloudinit/config/cc_growpart.py')
-rw-r--r--cloudinit/config/cc_growpart.py27
1 files changed, 20 insertions, 7 deletions
diff --git a/cloudinit/config/cc_growpart.py b/cloudinit/config/cc_growpart.py
index 6d647be1..b88e6f6a 100644
--- a/cloudinit/config/cc_growpart.py
+++ b/cloudinit/config/cc_growpart.py
@@ -22,6 +22,7 @@ import re
import stat
from cloudinit.settings import PER_ALWAYS
+from cloudinit import log as logging
from cloudinit import util
frequency = PER_ALWAYS
@@ -31,6 +32,7 @@ DEFAULT_CONFIG = {
'devices': ['/'],
}
+LOG = logging.getLogger(__name__)
def resizer_factory(mode):
resize_class = None
@@ -103,8 +105,19 @@ class ResizeGrowPart(object):
def resize(self, blockdev, part):
try:
+ util.subp(["growpart", '--dry-run', blockdev, part])
+ except util.ProcessExecutionError as e:
+ if e.exit_code != 1:
+ logexc(LOG, ("Failed growpart --dry-run for (%s, %s)" %
+ (blockdev, part)))
+ raise ResizeFailedException(e)
+ LOG.debug("no change necessary on (%s,%s)" % (blockdev, part))
+ return
+
+ try:
util.subp(["growpart", blockdev, part])
except util.ProcessExecutionError as e:
+ logexc(LOG, "Failed: growpart %s %s" % (blockdev, part))
raise ResizeFailedException(e)
@@ -150,38 +163,38 @@ def devent2dev(devent):
return result[0]
-def resize_devices(resizer, devices, log):
+def resize_devices(resizer, devices):
resized = []
for devent in devices:
try:
blockdev = devent2dev(devent)
except ValueError as e:
- log.debug("unable to turn %s into device: %s" % (devent, e))
+ LOG.debug("unable to turn %s into device: %s" % (devent, e))
continue
try:
statret = os.stat(blockdev)
except OSError as e:
- log.debug("device '%s' for '%s' failed stat" %
+ LOG.debug("device '%s' for '%s' failed stat" %
(blockdev, devent))
continue
if not stat.S_ISBLK(statret.st_mode):
- log.debug("device '%s' for '%s' is not a block device" %
+ LOG.debug("device '%s' for '%s' is not a block device" %
(blockdev, devent))
continue
try:
(disk, ptnum) = device_part_info(blockdev)
except (TypeError, ValueError) as e:
- log.debug("failed to get part_info for (%s, %s): %s" %
+ LOG.debug("failed to get part_info for (%s, %s): %s" %
(devent, blockdev, e))
continue
try:
resizer.resize(disk, ptnum)
except ResizeFailedException as e:
- log.warn("failed to resize: devent=%s, disk=%s, ptnum=%s: %s",
+ LOG.warn("failed to resize: devent=%s, disk=%s, ptnum=%s: %s",
devent, disk, ptnum, e)
resized.append(devent)
@@ -218,7 +231,7 @@ def handle(name, cfg, _cloud, log, _args):
raise e
return
- resized = resize_devices(resizer, devices, log)
+ resized = resize_devices(resizer, devices)
log.debug("resized: %s" % resized)
RESIZERS = (('parted', ResizeParted), ('growpart', ResizeGrowPart))