summaryrefslogtreecommitdiff
path: root/cloudinit
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2011-01-20 17:18:22 -0500
committerScott Moser <smoser@ubuntu.com>2011-01-20 17:18:22 -0500
commita68580956927cd4998091e844783924ffb3009ee (patch)
tree76e2a3c8fddd9450a1125b61fbdea30507d33157 /cloudinit
parent05230a34e2617592487e94f392a1eab70d5220b6 (diff)
downloadvyos-cloud-init-a68580956927cd4998091e844783924ffb3009ee.tar.gz
vyos-cloud-init-a68580956927cd4998091e844783924ffb3009ee.zip
add 'resize_rootfs' cloud-config option.
Diffstat (limited to 'cloudinit')
-rw-r--r--cloudinit/CloudConfig/cc_resizefs.py54
1 files changed, 54 insertions, 0 deletions
diff --git a/cloudinit/CloudConfig/cc_resizefs.py b/cloudinit/CloudConfig/cc_resizefs.py
new file mode 100644
index 00000000..11a10005
--- /dev/null
+++ b/cloudinit/CloudConfig/cc_resizefs.py
@@ -0,0 +1,54 @@
+# vi: ts=4 expandtab
+#
+# Copyright (C) 2011 Canonical Ltd.
+#
+# Author: Scott Moser <scott.moser@canonical.com>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 3, as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+import cloudinit.util as util
+import subprocess
+import traceback
+
+def handle(name,cfg,cloud,log,args):
+ if len(args) != 0:
+ resize_root = False
+ if str(value).lower() in [ 'true', '1', 'on', 'yes']:
+ resize_root = True
+ else:
+ resize_root = util.get_cfg_option_bool(cfg,"resize_rootfs",False)
+
+ if not resize_root: return
+
+ log.debug("resizing root filesystem on first boot")
+
+ cmd = ['blkid', '-sTYPE', '-ovalue', '/dev/root']
+ try:
+ (fstype,err) = util.subp(cmd)
+ except Exception, e:
+ log.warn("Failed to get filesystem type via %s" % cmd)
+ raise
+
+ if fstype.startswith("ext"):
+ resize_cmd = [ 'resize2fs', '/dev/root' ]
+ elif fstype == "xfs":
+ resize_cmd = [ 'xfs_growfs', '/dev/root' ]
+ else:
+ log.debug("not resizing unknown filesystem %s" % fstype)
+ return
+
+ try:
+ (out,err) = util.subp(resize_cmd)
+ except Exception, e:
+ log.warn("Failed to resize filesystem (%s,%s)" % cmd)
+ raise
+