blob: a3226416cbf3d055496dc75f956d16039d752a8b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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()
|