summaryrefslogtreecommitdiff
path: root/google-compute-engine.write
diff options
context:
space:
mode:
authorMark Doffman <mark.doffman@codethink.co.uk>2015-04-14 20:23:30 +0000
committerMark Doffman <mark.doffman@codethink.co.uk>2015-04-17 16:55:47 +0000
commitce7ea2923f1dc8c8fbd5600f14e356ffed99072b (patch)
treea57acda310648685cbf4c7c4aa9d21bea974c754 /google-compute-engine.write
parent2c013960069f9080589f2e61bd616a437e7a5264 (diff)
downloaddefinitions-baserock/markdoffman/google-compute-engine.tar.gz
Add strata, systems and cluster morpologies for google compute engine.baserock/markdoffman/google-compute-engine
Add the ability to create baserock images compatible with google compute engine. Add an example cluster morphology that does this.
Diffstat (limited to 'google-compute-engine.write')
-rwxr-xr-xgoogle-compute-engine.write64
1 files changed, 64 insertions, 0 deletions
diff --git a/google-compute-engine.write b/google-compute-engine.write
new file mode 100755
index 00000000..a3226416
--- /dev/null
+++ b/google-compute-engine.write
@@ -0,0 +1,64 @@
+#!/usr/bin/python
+# Copyright (C) 2012-2015 Codethink Limited
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# 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/>.
+
+
+'''A Morph deployment write extension for compressed raw disk images
+ that are compatible with google compute engine.'''
+
+
+import cliapp
+import os
+import sys
+import time
+import tempfile
+import shutil
+
+import morphlib.writeexts
+
+from subprocess import call
+
+class GoogleComputeEngineWriteExtension(morphlib.writeexts.WriteExtension):
+
+ def process_args(self, args):
+ if len(args) != 2:
+ raise cliapp.AppException('Wrong number of command line args')
+
+ DISK_NAME = 'disk.raw'
+
+ temp_root, location = args
+
+ try:
+ temp_dir = tempfile.mkdtemp()
+ disk_location = os.path.join(temp_dir, DISK_NAME)
+
+ with self.created_disk_image(disk_location):
+ self.format_btrfs(disk_location)
+ self.create_system(temp_root, disk_location)
+
+ self.status(msg='Compressing disk image')
+ call(["tar", '-czf', location, '-C', temp_dir, DISK_NAME])
+
+ self.status(msg='Compressed disk image has been created at %s' % location)
+ except Exception:
+ self.status(msg='Failure to deploy system to %s' % location)
+ raise
+ finally:
+ try:
+ shutil.rmtree(temp_dir)
+ except OSError as exc:
+ if exc.errno != errno.ENOENT:
+ raise
+
+GoogleComputeEngineWriteExtension().run()