Revision 3ccb2618
b/image_creator/disk.py | ||
---|---|---|
1 | 1 |
#!/usr/bin/env python |
2 | 2 |
|
3 |
import losetup |
|
3 |
from image_creator.util import get_command |
|
4 |
from clint.textui import progress |
|
5 |
|
|
4 | 6 |
import stat |
5 | 7 |
import os |
6 | 8 |
import tempfile |
... | ... | |
9 | 11 |
import sys |
10 | 12 |
import guestfs |
11 | 13 |
|
12 |
import pbs |
|
13 |
from pbs import dd |
|
14 |
from clint.textui import progress |
|
15 |
|
|
16 | 14 |
|
17 | 15 |
class DiskError(Exception): |
18 | 16 |
pass |
19 | 17 |
|
20 |
|
|
21 |
def find_sbin_command(command, exception): |
|
22 |
search_paths = ['/usr/local/sbin', '/usr/sbin', '/sbin'] |
|
23 |
for fullpath in map(lambda x: "%s/%s" % (x, command), search_paths): |
|
24 |
if os.path.exists(fullpath) and os.access(fullpath, os.X_OK): |
|
25 |
return pbs.Command(fullpath) |
|
26 |
continue |
|
27 |
raise exception |
|
28 |
|
|
29 |
|
|
30 |
try: |
|
31 |
from pbs import dmsetup |
|
32 |
except pbs.CommandNotFound as e: |
|
33 |
dmsetup = find_sbin_command('dmsetup', e) |
|
34 |
|
|
35 |
try: |
|
36 |
from pbs import blockdev |
|
37 |
except pbs.CommandNotFound as e: |
|
38 |
blockdev = find_sbin_command('blockdev', e) |
|
18 |
dd = get_command('dd') |
|
19 |
dmsetup = get_command('dmsetup') |
|
20 |
losetup = get_command('losetup') |
|
21 |
blockdev = get_command('blockdev') |
|
39 | 22 |
|
40 | 23 |
|
41 | 24 |
class Disk(object): |
... | ... | |
57 | 40 |
self._cleanup_jobs.append((job, args)) |
58 | 41 |
|
59 | 42 |
def _losetup(self, fname): |
60 |
loop = losetup.find_unused_loop_device()
|
|
61 |
loop.mount(fname)
|
|
62 |
self._add_cleanup(loop.unmount)
|
|
63 |
return loop.device
|
|
43 |
loop = losetup('-f', '--show', fname)
|
|
44 |
loop = loop.strip() # remove the new-line char
|
|
45 |
self._add_cleanup(losetup, '-d', loop)
|
|
46 |
return loop |
|
64 | 47 |
|
65 | 48 |
def _dir_to_disk(self): |
66 | 49 |
raise NotImplementedError |
b/image_creator/main.py | ||
---|---|---|
34 | 34 |
from image_creator import get_os_class |
35 | 35 |
from image_creator import __version__ as version |
36 | 36 |
from image_creator.disk import Disk |
37 |
from image_creator.util import get_command |
|
38 |
|
|
37 | 39 |
import sys |
38 | 40 |
import os |
39 | 41 |
import optparse |
40 |
from pbs import dd |
|
42 |
|
|
43 |
dd = get_command('dd') |
|
41 | 44 |
|
42 | 45 |
|
43 | 46 |
class FatalError(Exception): |
... | ... | |
123 | 126 |
|
124 | 127 |
size = options.shrink and dev.shrink() or dev.size() |
125 | 128 |
metadata['size'] = str(size // 2 ** 20) |
126 |
|
|
127 | 129 |
dd('if=%s' % dev.device, |
128 | 130 |
'of=%s/%s.%s' % (options.outdir, options.name, 'diskdump'), |
129 | 131 |
'bs=4M', 'count=%d' % ((size + 1) // 2 ** 22)) |
b/image_creator/util.py | ||
---|---|---|
1 |
#!/usr/bin/env python |
|
2 |
|
|
3 |
import pbs |
|
4 |
|
|
5 |
def get_command(command): |
|
6 |
def find_sbin_command(command, exception): |
|
7 |
search_paths = ['/usr/local/sbin', '/usr/sbin', '/sbin'] |
|
8 |
for fullpath in map(lambda x: "%s/%s" % (x, command), search_paths): |
|
9 |
if os.path.exists(fullpath) and os.access(fullpath, os.X_OK): |
|
10 |
return pbs.Command(fullpath) |
|
11 |
raise exception |
|
12 |
|
|
13 |
try: |
|
14 |
return pbs.__getattr__(command) |
|
15 |
except pbs.CommadNotFount as e: |
|
16 |
return find_sbin_command(command, e) |
b/setup.py | ||
---|---|---|
47 | 47 |
license='BSD', |
48 | 48 |
packages=['image_creator'], |
49 | 49 |
include_package_data=True, |
50 |
install_requires=['losetup', 'pbs', 'clint'],
|
|
50 |
install_requires=['pbs', 'clint'], |
|
51 | 51 |
entry_points={ |
52 | 52 |
'console_scripts': ['snf-image-creator = image_creator.main:main'] |
53 | 53 |
} |
Also available in: Unified diff