diff options
Diffstat (limited to 'google-compute-engine.write')
-rwxr-xr-x | google-compute-engine.write | 64 |
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() |