Skip to content
Snippets Groups Projects
Commit 3ccb2618 authored by Nikos Skalkotos's avatar Nikos Skalkotos
Browse files

Remove python-losetup dependency

The package is buggy and we can use pbs to do the same thing.
parent e7c01d1e
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python #!/usr/bin/env python
import losetup from image_creator.util import get_command
from clint.textui import progress
import stat import stat
import os import os
import tempfile import tempfile
...@@ -9,33 +11,14 @@ import re ...@@ -9,33 +11,14 @@ import re
import sys import sys
import guestfs import guestfs
import pbs
from pbs import dd
from clint.textui import progress
class DiskError(Exception): class DiskError(Exception):
pass pass
dd = get_command('dd')
def find_sbin_command(command, exception): dmsetup = get_command('dmsetup')
search_paths = ['/usr/local/sbin', '/usr/sbin', '/sbin'] losetup = get_command('losetup')
for fullpath in map(lambda x: "%s/%s" % (x, command), search_paths): blockdev = get_command('blockdev')
if os.path.exists(fullpath) and os.access(fullpath, os.X_OK):
return pbs.Command(fullpath)
continue
raise exception
try:
from pbs import dmsetup
except pbs.CommandNotFound as e:
dmsetup = find_sbin_command('dmsetup', e)
try:
from pbs import blockdev
except pbs.CommandNotFound as e:
blockdev = find_sbin_command('blockdev', e)
class Disk(object): class Disk(object):
...@@ -57,10 +40,10 @@ class Disk(object): ...@@ -57,10 +40,10 @@ class Disk(object):
self._cleanup_jobs.append((job, args)) self._cleanup_jobs.append((job, args))
def _losetup(self, fname): def _losetup(self, fname):
loop = losetup.find_unused_loop_device() loop = losetup('-f', '--show', fname)
loop.mount(fname) loop = loop.strip() # remove the new-line char
self._add_cleanup(loop.unmount) self._add_cleanup(losetup, '-d', loop)
return loop.device return loop
def _dir_to_disk(self): def _dir_to_disk(self):
raise NotImplementedError raise NotImplementedError
......
...@@ -34,10 +34,13 @@ ...@@ -34,10 +34,13 @@
from image_creator import get_os_class from image_creator import get_os_class
from image_creator import __version__ as version from image_creator import __version__ as version
from image_creator.disk import Disk from image_creator.disk import Disk
from image_creator.util import get_command
import sys import sys
import os import os
import optparse import optparse
from pbs import dd
dd = get_command('dd')
class FatalError(Exception): class FatalError(Exception):
...@@ -123,7 +126,6 @@ def main(): ...@@ -123,7 +126,6 @@ def main():
size = options.shrink and dev.shrink() or dev.size() size = options.shrink and dev.shrink() or dev.size()
metadata['size'] = str(size // 2 ** 20) metadata['size'] = str(size // 2 ** 20)
dd('if=%s' % dev.device, dd('if=%s' % dev.device,
'of=%s/%s.%s' % (options.outdir, options.name, 'diskdump'), 'of=%s/%s.%s' % (options.outdir, options.name, 'diskdump'),
'bs=4M', 'count=%d' % ((size + 1) // 2 ** 22)) 'bs=4M', 'count=%d' % ((size + 1) // 2 ** 22))
......
#!/usr/bin/env python
import pbs
def get_command(command):
def find_sbin_command(command, exception):
search_paths = ['/usr/local/sbin', '/usr/sbin', '/sbin']
for fullpath in map(lambda x: "%s/%s" % (x, command), search_paths):
if os.path.exists(fullpath) and os.access(fullpath, os.X_OK):
return pbs.Command(fullpath)
raise exception
try:
return pbs.__getattr__(command)
except pbs.CommadNotFount as e:
return find_sbin_command(command, e)
...@@ -47,7 +47,7 @@ setup( ...@@ -47,7 +47,7 @@ setup(
license='BSD', license='BSD',
packages=['image_creator'], packages=['image_creator'],
include_package_data=True, include_package_data=True,
install_requires=['losetup', 'pbs', 'clint'], install_requires=['pbs', 'clint'],
entry_points={ entry_points={
'console_scripts': ['snf-image-creator = image_creator.main:main'] 'console_scripts': ['snf-image-creator = image_creator.main:main']
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment